Calling a function with a variable number of arguments

Is it possible to construct a function call (inside a function template) with a variable number of arguments, depending on the number of template arguments? Sort of:

void f(int i) {} void f(int i1, int i2){} void f(int i1, int i2, int i3){} ... template<typename... T> void caller() { f(/* sizeof...(T) number of arguments; of form T_i::value */); } 
+4
source share
1 answer

Yes; the package of parameters of the template T can be expanded in the same way as the package of parameters of the function:

 template<typename... T> caller() { f(T::value...); } 
+6
source

All Articles