Variadic Variable Templates

Master the concept of variadic variable templates to expand our knowledge of C++ template metaprogramming.

We'll cover the following

As mentioned before, variable templates may also be variadic. However, variables cannot be defined recursively, nor can they be specialized like class templates. Fold expressions, which simplify generating expressions from a variable number of arguments, are very handy for creating variadic variable templates.

Defining a variadic variable template

In the following example, we define a variadic variable template called Sum that’s initialized at compile-time with the sum of all integers supplied as non-type template arguments:

Get hands-on with 1400+ tech skills courses.