How to construct a variadic parameter pack

The parameter pack is identified by putting three dots in front of the type name, and three dots after the variadic argument expands the pack, with a comma in between:

Here's the syntactic explanation:

  • Ts is a list of types
  • The <typename ...Ts&> function indicates that the function deals with a list
  • The values... function expands the pack such that a comma is added between every type

To put it into code, consider this expand_pack function:

template <typename ...Ts> 
auto expand_pack(const Ts& ...values) { 
   auto tuple = std::tie(values...); 
} 

Let's call the preceding function like this:

expand_pack(42, std::string{"hi"}); 

In that case, the compiler will generate a function similar to this:

auto ...

Get C++ High Performance 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.