
AMDG Hicham Mouline wrote:
After some though, here is more precisely what I'd like to have... I apologize that it is quite different from the initial problem:
template<int n> class Tree { static double sum(); // };
If the user instantiates tree<2>, he should get:
template<> class Tree<2> { static double sum(double d1, double d2); };
template<> class Tree<3> { static double sum(double d1, double d2, double d3); }; etc etc...
so that in user code, for e.g.:
double d= Tree<4>::sum(d1, d2, d3, d4);
should compile.
Is it possible for me to just define the template Tree for the n-case without the 2- and 3- specializations?
Ah. You still need the preprocessor, but you can rearrange the definitions slightly. (untested) template<int N> struct TreeSumImpl; #define TREE_SUM_DEF(z, n, data)\ template<>\ struct TreeSumImpl<n> {\ static double sum(BOOST_PP_ENUM_PARAMS_Z(z, n, double arg)) { ... }\ }; BOOST_PP_REPEAT(20, TREE_SUM_DEF, ~) template<int N> struct Tree : TreeSumImpl<N> { // other code }; In Christ, Steven Watanabe