Template and Function Parameter Packs

As a starting point to see how parameter packs work, let’s consider a simple template function, one that displays a list consisting of just one item:

template<typename T>void show_list0(T value){    std::cout << value << ", ";}

This definition has two parameter lists. The template parameter list is just T. The function parameter list is just value. A function call such as the following sets T in the template parameter list to double and value in the function parameter list to 2.15:

show_list0(2.15);

C++11 provides an ellipsis meta-operator that enables you to declare an identifier for a template parameter pack, essentially a list of types. Similarly, it lets you declare an identifier for a function parameter ...

Get C++ Primer Plus now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.