Class Template Argument Deduction for Everyone
summary
C++17’s Class Template Argument Deduction (CTAD) automatically infers template parameters for many STL types (std::pair, std::array, std::vector, lock guards), cutting angle-bracket noise; the library implements this with explicit deduction guides where constructors don’t name all template parameters and uses the decay by value trick to match perfect-forwarding constructors. Limitations include alias templates, explicit template-argument mixes, nullptr and non-deduced-context edge cases, and aggregate rules for std::array; MSVC/Clang implemented CTAD in practice and uncovered compiler bugs during rollout.
AI-written summary · about
chapters (12)
- 0:00Intro
- 1:32Why Examples Use STL Types
- 2:52Function Template Arg Deduction
- 5:14Class Templates: No Deduction
- 13:56Type Transformation
- 19:14Alias Templates
- 28:11Range Constructors
- 28:48Hello, Deduction Guide World
- 35:11Enforcing Requirements
- 36:45Supporting CTAD in Your Library - For each constructor of each class template: - Is CTAD applicable? Example "no": vector size_t Does CTAD automatically work?
- 45:14Deduction Guides, 1 of 3
- 49:35Non-Templated Constructors
related talks
01h 08mCTAD: Complete Guide to Class Template Argument Deduction
01h 04mClass Template Argument Deduction in C++17
01h 37mRethinking the Way We Do Templates in C++ even more
58mThe Pattern Matching We Already Have
01h 30mRethinking the Way We Do Templates in C++
58m“Template Normal Programming (part 1 of 2)”
01h 01m“Template Normal Programming (part 2 of 2)"
53mC++ Variadic Templates and Parameter Packs
