Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

What are the names of the new syntactic entities added for variadic templates?

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?

like image 399
Motti Avatar asked Nov 01 '11 20:11

Motti


Video Answer


1 Answers

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).
like image 172
ildjarn Avatar answered Nov 15 '22 10:11

ildjarn