Variadic template
A variadic template is a C++ template that uses a parameter pack to accept a variable number of template arguments.
Learn C++ by Example
A variadic template is a template containing at least one parameter pack and therefore capable of accepting a variable number of template arguments.
- How it is used
- Deploys variable-arity functions, frequency counting, and grouped lambda visitors for variants.
- How deep it goes
- Explains declarations, expansions, folds, constraints, and selected overload behavior, but defers broader template internals.
- Examples
- Uses summation, frequency maps for slot-machine reels, and an Overload visitor combining lambdas.
- What you can do after
- Build variable-arity functions, expand packs into expressions or lists, and compose callable visitors for variants.
100 C++ Mistakes and How to Avoid Them
A variadic template is a C++ template that accepts a variable number of template arguments or function arguments.
- How it is used
- Handles variable numbers of template or function arguments for more generic and reusable code.
- How deep it goes
- Explains base and recursive cases, compiler expansion, and a C++17 fold-expression alternative.
- Examples
- Contrasts summing values from a vector with direct calls accepting two, three, or four arguments.
- What you can do after
- Build variable-length sum functions using a base case, recursive parameter pack, or C++17 fold expression.
Read how 100 C++ Mistakes and How to Avoid Them explains variadic template →
Related concepts
- templatekind of · A C++ template is a parameterized declaration or definition from which the compiler generates specialized code or types for specified arguments.
- parameter packhas part · A parameter pack is a C++ template or function parameter construct representing zero or more arguments, potentially of varying types.
- recursionuses · Recursion is a computational technique in which a definition or procedure refers to or invokes the same definition or procedure, directly or indirectly.
- fold expressionalternative to · A fold expression is a C++ expression that applies a binary operator across the elements of a parameter pack.
- frequencyuses · Frequency is the count or rate at which an item, event, outcome, or periodic cycle occurs within a specified collection or interval.
- variadic argumentsimplements · A variadic function or parameter accepts a variable number of arguments, often collecting the supplied values into a sequence of a specified type.
These guides are generated from the text of Manning books by Manning's knowledge graph and link to the sections they draw on. The full books are available on liveBook and at manning.com.

