4

テンプレート引数の数に応じて、可変数の引数で関数呼び出し (関数テンプレート内) を構築することは可能ですか? 何かのようなもの:

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

1 に答える 1

6

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

template<typename... T>
caller() {
   f(T::value...);
}
于 2011-08-11T15:45:02.523 に答える