Search⌘ K
AI Features

Understanding Parameter Packs Expansion

Explore the different contexts in which parameter packs expand in C++ variadic templates. Understand how expansions work in template parameter and argument lists, function calls, initializers, base classes, and lambda captures to enhance template flexibility and functionality.

We'll cover the following...

Parameter packs can appear in a multitude of contexts. The form of their expansion may depend on this context. These possible contexts are listed ahead along with examples.

Lists

  • Template parameter list: The template parameter list is used when we specify parameters for a template:

C++
template <typename... T>
struct outer
{
template <T... args>
struct inner {};
};
outer<int, double, char[5]> a;
  • Template argument list: The template argument list is used when we specify arguments for a template:

C++
template <typename... T>
struct tag {};
template <typename T, typename U, typename ... Args>
void tagger()
{
tag<T, U, Args...> t1;
tag<T, Args..., U> t2;
tag<Args..., T, U> t3;
tag<U, T, Args...> t4;
}
  • Function parameter list: The function parameter list is ...