Class Template Argument Deduction in C++17
summary
Explains how C++17 class template argument deduction actually works in two phases, shows real STL examples (pair, vector, array, set, map, tuple, std::function) and exposes concrete pitfalls: list-initialization wins, deduction uses the primary template, aggregates require explicit deduction guides, and CTAD can silently produce unsafe code for smart pointers. Demonstrates fixes: type_identity idiom, member typedefs or extra constructor template parameters, order-dependent guides, and when to prefer make_shared/make_unique for safety.
AI-written summary · about
chapters (24)
- 0:00Intro
- 1:51template argument deduction in C++98
- 12:27vector
- 12:53pitfall!
- 13:49magic!
- 17:00trap #1: the order matters
- 19:14trap #2: list-initialisation has priority
- 19:51sequence containers
- 21:20map
- 23:31locks & mutexes
- 24:15example with no arguments
- 24:32other STL classes...
- 26:36smart pointers
- 29:34how to disable CTAD
- 30:10type identity idiom
- 32:06member typedef
- 32:48templated ctor
- 34:00std: function
- 35:49deduction guides SFINAE
- 44:02aggregates need explicit guides
- 46:36CTAD uses the primary template
- 51:00CTAD not just in declarations!
- 52:07no CTAD in nested types
- 53:12CTAD + smart pointer conversions
related talks
01h 00mClass template argument deduction in C++17
01h 01mClass Template Argument Deduction for Everyone
01h 08mCTAD: Complete Guide to Class Template Argument Deduction
01h 01m“Template Normal Programming (part 2 of 2)"
58m“Template Normal Programming (part 1 of 2)”
58mThe Pattern Matching We Already Have
01h 02mC++17: The Language Features
57mIntroduction to C++ Template Metaprogramming
