Variadic Templates and Parameter Packs
Use parameter packs and fold expressions to write variadic templates.
Variable Number of Template Arguments
Variadic templates accept any number of template arguments. Used to write functions like std::make_unique, std::tuple, and printf-style logging.
Parameter Pack Syntax
Use typename... Ts to declare a type parameter pack, and Ts... to expand it.
template <typename... Args>
void print_all(Args... args) {
// ...
}All lessons in this course
- Function and Class Templates Revisited
- Template Specialization Partial and Full
- Variadic Templates and Parameter Packs
- constexpr Functions and if constexpr