开发者

Function call with variable number of arguments

开发者 https://www.devze.com 2023-03-27 16:44 出处:网络
Is it possible to construct function call (inside function template) with variable number of arguments, depending on number of template arguments? Something like:

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<typ开发者_C百科ename... T>
void caller() {
   f(/* sizeof...(T) number of arguments; of form T_i::value */);
}


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

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

精彩评论

暂无评论...
验证码 换一张
取 消