开发者

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<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

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜