16.4.2. Pack Expansion
Aside from taking its size, the only other thing we can do with a parameter pack is to expand it. When we expand a pack, we also provide a pattern to be used on each expanded element. Expanding a pack separates the pack into its constituent elements, applying the pattern to each element as it does so. We trigger an expansion by putting an ellipsis (. . . ) to the right of the pattern.
For example, our print
function contains two expansions:
template <typename T, typename... Args>ostream &print(ostream &os, const T &t, const Args&... rest)// expand Args{ os << t << ", "; return print(os, rest...); // ...
Get C++ Primer, Fifth Edition 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.