È possibile in C++ 0x utilizzando modelli variadic. Ecco come creare una tabella di coefficienti binomiali:
//typedefs used
typedef short int index_t;
typedef unsigned long long int int_t;
//standard recursive template for coefficient values, used as generator
template <index_t n, index_t k> struct coeff {static int_t const value = coeff<n-1, k-1>::value + coeff<n-1, k>::value;};
template <index_t n> struct coeff<n, 0> {static int_t const value = 1;};
template <index_t n> struct coeff<n, n> {static int_t const value = 1;};
//helper template, just converts its variadic arguments to array initializer list
template<int_t... values> struct int_ary {static int_t const value[sizeof...(values)];};
template<int_t... values> int_t const int_ary<values...>::value[] = {values...};
//decrement k, pile up variadic argument list using generator
template<index_t n, index_t k, int_t... values> struct rec: rec<n, k-1, coeff<n, k-1>::value, values...> {};
//when done (k == 0), derive from int_ary
template<index_t n, int_t... values> struct rec<n, 0, values...>: int_ary<values...> {};
//initialise recursion
template<index_t n> struct binomial: rec<n, n+1> {};
per accedere agli elementi usa una sintassi del tipo binomiale <N> :: valore [k], dove N è compilazione costante di tempo e k è indice che varia da 0 a N inclusivo.
Si potrebbe star meglio con la metaprogrammazione del preprocessore. Non penso che il C++ abbia abbastanza soluzioni alternative. – Potatoswatter
Oppure, il mio preferito per la costruzione di dati strutturati in fase di compilazione, usa un macro assemblatore! – Potatoswatter
Da IBM 'The art of Metaprogramming' l'autore dà a script perl per generare la sua tabella. Forse non è quello che stai cercando, ma qualcuno potrebbe apprezzarlo. –