In the following snippet:
void normalize(path& p)
{
// do something with p
}
template<typename... T>
void normalize(T&... t)
{
normalize(t)...; // (L)
}
In my actual understanding, the line (L)
expands to:
template<typename... T>
void normalize(T&... t) // T = {t1, t2, t3}, for example
{
normalize(t1), normalize(t2), normalize(t3);
}
and each one of these expressions will execute the one-parameter version of normalize
. However, g++
(4.8.1) throws me the following error:
prueba.cpp: In function 'void normalize(T& ...)':
prueba.cpp:155:17: error: expected ';' before '...' token
normalize(t)...;
^
prueba.cpp:155:20: error: parameter packs not expanded with '...':
normalize(t)...;
^
prueba.cpp:155:20: note: 't'
What's wrong with my code?
The expansion of parameter packs is not allowed in this context. If you create a helper class
pass
, you can do the following:The helper class
pass
might look as follows: