C++11 introduced variadic templates
template <typename... Args>
void foo(Args... params) {
cout << sizeof...(Args) << endl;
}
What are the names of Args
and params
? I know that one of them (at least?) is called a variadic template pack but which is it? And what is the other called?
Partially quoting the FDIS, §14.5.3:
1 A template parameter pack is a template parameter that accepts zero or more template arguments.
2 A function parameter pack is a function parameter that accepts zero or more function arguments.
3 A parameter pack is either a template parameter pack or a function parameter pack.
4 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.
So in your example,
typename... Args
is a template parameter pack (and consequently also a parameter pack)Args... params
is a function parameter pack (and consequently also a parameter pack)sizeof...(Args)
is a pack expansion wherein Args
is the pattern (an identifier in this context).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