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 expressions
- Variadic alias templates
- Variadic variable templates
By the end of the chapter, you will have a good understanding of how to write variadic templates and how they work.
We will start, however...