The following code is legal in C++11.
template<int... N>
std::tuple<decltype(N)...> f()
{
return std::make_tuple(7 + N...);
}
What does it mean?
First of all, look at the template parameters: template <int ... N>
. Even though a variable number of template arguments can be given to f
, all of them must be of type int
.
Now when you use f<t1, t2, ..., tn>
, the parameter unpacking (7 + N...)
will follow the pattern 7 + N
and expand to
7 + t1, 7 + t2, 7 + t3, ..., 7 + tn
Therefore you end up with a tuple which contains each of your template arguments increased by seven. The details can be found in section 14.5.3 Variadic templates [temp.variadic].
3. A pack expansion consists of a pattern and an ellipsis, the instantiation of which produces zero or more instantiations of the pattern in a list [...].
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With