Chapter 3: Variadic Templates

A variadic template is a template with a variable number of arguments. This is a feature that was introduced in C++11. It combines generic code with functions with variable numbers of arguments, a feature that was inherited from the C language. Although the syntax and some details could be seen as cumbersome, variadic templates help us write function templates with a variable number of arguments or class templates with a variable number of data members in a way that was not possible before with compile time evaluation and type safety.

In this chapter, we will learn about the following topics:

  • Understanding the need for variadic templates
  • Variadic function templates
  • Parameter packs
  • Variadic class templates
  • Fold ...

Get Template Metaprogramming with C++ 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.