Predrag
Predrag

Reputation: 1557

Function call with variable number of arguments

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

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 */);
}

Upvotes: 4

Views: 157

Answers (1)

JohannesD
JohannesD

Reputation: 14471

Yes; the template parameter pack T may expanded the same way as a function parameter pack:

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

Upvotes: 6

Related Questions