Andrei Alexandrescu gave an excellent talk entitled: Variadic Templates are Funadic.
He presents the following 3 expansions which are subltey different:
template <class... Ts> void fun( Ts... vs ) {
gun( A<Ts...>::hun(vs)...);
gun( A<Ts...>::hun(vs...));
gun( A<Ts>::hun(vs)...);
}
He explains:
Call 1:
Expands all Ts
for instatiation of class A
,
Then calls hun(vs)
Then expands all parameters again when passing them into gun
Call 2:
Expands all Ts
and all vs
separately
Call 3:
Expnads in lock step, ie:
Expand argument 1 of Ts
and Argument 1 of vs
Expand argument 2 of Ts
and Argument 2 of vs
Expand argument n of Ts
and Argument n of vs
Other discussion on variadic templates only seem to cover the simple variadic class templates and variadic functions such as typesafe printf etc. I am unsure as to how these different types of expansion effect the code and where each type would be useful.
Does anyone have some examples that demonstrate the application of each type of expansion?