Laurent <
laurent...@gmail.com> wrote:
> Thanx, the following syntax do compile :
>
> template <typename First, typename... Rest>
> Toto(const First & first, const Rest&... rest):subToto_(rest...){}
In general, the ... syntax for variadic templates goes like this:
In the template declaration you use "typename... [name]" to indicate
a variable amount of parameters. (Could also be "[type]... [name]",
eg "int... Values", but that's besides the point.)
Then wherever you are going to use the typename [name], you use
the entire type expression and append "..." to it.
For example "const Rest&..." means that each of the types will be
expanded as "const [the specified type]&".
The place where you use the actual parameter, you can write any
expression you want, and append "..." to it, which means that the
expression will be repeated for each of the specified types, separated
by commas. In other words, something like this is completely valid:
template<typename... T>
void foo(const T&... parameters)
{
int results[] = { someFunction(parameters)... };
}
Notice that "someFunction(parameters...)" would be different from
"someFunction(parameters)...". The former means that all the parameters
are given to the single function call (which must of course support
being given a variable number of parameters), while the latter means
that a "someFunction()" call will be created for each parameter (in
other words, said function just takes one parameter), and all these
calls basically separated with commas.
--- news://
freenews.netfront.net/ - complaints:
ne...@netfront.net ---