テンプレート引数と同じ型の要素のリストを使用する必要があるため、ベクトルを使用していますが、これを機能させる方法がわかりません
#include <iostream>
#include <cstdint>
#include <vector>
template <uint8_t VAL>
void foo()
{
std::cout << "__" << std::endl;
};
template <>
void foo<3>()
{
std::cout << "OK" << std::endl;
};
int main()
{
std::vector<uint8_t> v = { 2, 4, 5, 2, 3, 55 };
for (auto &k : v) {
foo<k>();
}
return (0);
}
k
コンパイラは基本的に ではないことについて不平を言いa constant expression
ます。問題は、これを機能させるためにこれを変更する方法がわからないことです。反復するデータ構造が必要なので、ベクトルを保持する必要があります。単純化するためのテンプレートが必要です。見れば見るほど無限ループにハマってしまう。