K
Ich hatte da eigentlich an eine Funktion gedacht, wo drin das Array per static deklariert wird. Aber sonst sieht das auch fast genauso aus, wie bei Euch:
#include <type_traits>
template<class T> struct identity {typedef T type;};
template<class...T> struct pack {};
template<int Beg, int End, int...Tail>
struct index_pack_type
: index_pack_type<Beg,End-1,End-1,Tail...> {};
template<int BE, int...Tail>
struct index_pack_type<BE,BE,Tail...>
: identity<pack<std::integral_constant<int,Tail>...> > {};
template<int B, int E>
typename index_pack_type<B,E>::type make_index_pack() {
return typename index_pack_type<B,E>::type();
}
template<class ValueType, template<class> class MetaFunc, class...MetaArgs>
inline ValueType const* lookuptable(pack<MetaArgs...>) {
static const ValueType data[] = {MetaFunc<MetaArgs>::value...};
return data;
}
#include <iostream>
template<int I> struct fib_c : std::integral_constant<int,
fib_c<I-1>::value + fib_c<I-2>::value
>{};
template<> struct fib_c<0> : std::integral_constant<int,0>{};
template<> struct fib_c<1> : std::integral_constant<int,1>{};
template<class MetaArg> struct fib : fib_c<MetaArg::value>{};
int main() {
const int N = 10;
const int* fibtab = lookuptable<int,fib>(make_index_pack<0,N>());
for (int i=0; i<N; ++i) {
std::cout << fibtab[i] << std::endl;
}
}