0Pricing
C++ Academy · Lesson

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

  1. Function and Class Templates Revisited
  2. Template Specialization Partial and Full
  3. Variadic Templates and Parameter Packs
  4. constexpr Functions and if constexpr
← Back to C++ Academy