定数式で値を使用できるクラスの配列を初期化する方法を知りたいです。これが私の問題の説明です:
// The goal : initializing an array for a class
// whose values can be used as normal static const
// (as template parameters for example)
class MyClass
{
public:
static const unsigned int value = 42; // <- No problem here
static const unsigned int array[3] = {100, 101, 102}; // <- How to initialize this static const array (with constexpr or metaprogrammation maybe ?)
template<unsigned int T> inline void f() {std::cout<<"Hello, my value is "<<T<<std::endl;} // <- Simple function for demonstration purposes
inline void fvalue() {f<value>();} // <- No problem here
inline void farray() {f<array[1]>();} // <- Big problem here
};
//const unsigned int Class1::array[3] = {100, 101, 102}; // <- If I do this, I will initialize the array but farray() will not compile
C ++ 2011でこれを行う方法はありますか?(constexprまたはメタプログラミングで多分?)
どうもありがとうございます !
編集:タイトルが指定しているように、私array
はクラスのメンバーである必要があります(グローバル配列ではありません)。