私は、スレッド数に対する符号なしのintパラメータを持つテンプレート・クラスを持っています。私はスレッドのための静的な配列を作成するためにそれを使用したいと思います。私は、デフォルト値としてstd::thread::hardware_concurrency()
使用することはできませんどちらもテンプレート・パラメータとしてthread :: hardware_concurrency()
、
template <typename T, size_t num_threads = std::thread::hardware_concurrency()>
class Some_class{
T values[num_threads];
...
}
もパラメータとして私のクラスにそれを与えます。
template <typename T, size_t num_threads>
class Some_class{
T values[num_threads];
...
}
Some_class<int,std::thread::hardware_concurrency()> instance;
問題がstd::thread::hardware_concurrency()
の戻り値はconstのないことです。
コンパイラは言う:
error: call to non-constexpr function ‘static unsigned int std::thread::hardware_concurrency()’
note: in template argument for type ‘long unsigned int’
は私のテンプレートで使用可能なスレッド数を取得するには、別の静的な方法はありますか?
*定数式*はC++テンプレートでのみ使用できます。残念ながら 'std :: thread :: hardware_concurrency()'は*定数式ではなく、実行時にしか評価できません – WhiZTiM
どのOSを使用していますか? – WhiZTiM