
AMDG Hicham Mouline wrote:
hi,
i have a template function, the arguments of which i wish to have depend on a non-type int template argument:
template<int n> double f<n>( double arg0, double arg1, ..., double argn ) // ... is not the variadic notation for var number of args { // for(int i=0; i
int main() { return x = f<3>( 1.0, 2.0, 3.0 ); }
BOOST_PP_REPEAT can't seem to do the job as the template argument n needs to be known at the preprocessing stage, which happens before the template instantiation stage ( this is part of compilation)
I don't understand why you want n to be passed explicitly. Can't it be deduced from the number of arguments (warning untested): #define SUM_IMPL(z, n, data) + arg ## n #define F_DEF(z, n, data) double f(BOOST_PP_ENUM_PARAMS_Z(z, n, double arg)) { return(0.0 BOOST_PP_REPEAT_ ## z(n, SUM_IMPL, ~)); } BOOST_PP_REPEAT(MAX_ARITY, F_DEF, ~) In Christ, Steven Watanabe