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-length function argument lists with reusable templates.
- How deep it goes
- Explains base and recursive cases, pack reduction, and fold expressions as an optional next step.
- Examples
- Demonstrates summing values with a vector workaround and with variadic calls containing two, three, or four integers.
- What you can do after
- Build variable-argument sum functions using a base case and recursive parameter-pack case.
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 instantiates functions, classes, or other code for specified types or values.
- parameter packhas part · A parameter pack is a C++ template or function parameter construct representing zero or more arguments, potentially of varying types.
- templatekind of · A template is a reusable structure with fixed elements and variable parts for creating or organizing instances of similar content or artifacts.
- recursionuses · Recursion is a computational technique in which a definition or procedure refers to or invokes itself, 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 number or rate at which an item, event, outcome, or cycle occurs within a specified collection or interval.
Questions about variadic template
What is variadic template?
A variadic template is a C++ template that uses a parameter pack to accept a variable number of template arguments.
Which Manning books explain variadic template?
Learn C++ by Example and 100 C++ Mistakes and How to Avoid Them.
What is the difference between variadic template and fold expression?
A variadic template is a C++ template that uses a parameter pack to accept a variable number of template arguments. A fold expression is a C++ expression that applies a binary operator across the elements of a parameter pack.
What is variadic template a kind of?
Variadic template is a kind of template. A C++ template is a parameterized declaration or definition from which the compiler instantiates functions, classes, or other code for specified types or values.
What are the parts of variadic template?
Variadic template includes parameter pack.
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.

