C++ Variadic Templates and Parameter Packs
summary
Refresher on using C++ variadic templates and parameter packs with concrete examples: a tuple-backed container implemented by expanding packs into template and ctor argument lists, a constexpr make_array sized with sizeof..., a sum implemented first via initializer_list then simplified to a one-line fold expression in C++17, a delete_all and find_first_if built with folds and comma tricks, an overload combiner for lambdas using tuple-like base expansion, plus use of std::apply, std::forward, std::variant/std::visit, concepts (C++20) and planned C++26 features like direct pack indexing and variadic structured binding.
AI-written summary · about
chapters (25)
- 0:00Variadic templates intro
- 1:12C++ templates refresher
- 4:41What variadic templates enable
- 7:12Parameter pack expansion example
- 10:48Forwarding with parameter packs
- 12:35Compile-time pack size
- 13:59Packs in initializer lists
- 16:09Operations on each pack element
- 18:19Packs in lambda captures
- 20:54Alignment expansion for variants
- 23:03std::visit with lambdas
- 26:00Recursive vs initializer packs
- 27:03C++17 fold expressions
- 31:23Fold expressions with operators
- 32:50delete_all with fold
- 34:59Complex fold logic
- 37:56Type lists for packs
- 39:02Scheduler example
- 41:12C++11 to C++17 evolution
- 44:24Standard library pack tools
- 46:13C++20 abbreviated templates
- 47:41Same-type enforcement with concepts
- 49:05C++26 pack future
- 50:32Variadic structured binding
- 52:46Substitution failure
related talks
01h 03mBack to Basics: Templates (part 2 of 2)
04mGeneralized fold expressions
05mBeautiful Folds
05mLightning Talk: The Finer Points of Parameter Packs
54mGeneric Programming Without (Writing Your Own) Templates
05mAn example of applying variadic templates to C code
01h 27mC++20 Templates - the Next Level: Concepts and More
01h 05mBack to Basics: Templates (part 1 of 2)
