Class template argument deduction in C++17
summary
Class template argument deduction (CTAD) in C++17 is explained as a two-step deduction process: synthesize function-like deduction candidates from constructors, deduce template arguments, then instantiate the class. Practical details include writing deduction guides for iterator-to-container cases, SFINAE-friendly guides, and techniques to disable CTAD (the type_identity idiom, templated constructors, or typedef indirection). Important pitfalls: brace vs parenthesis chooses initializer_list or range constructors, copy-vs-list ambiguity with one vs multiple args, smart pointers deliberately disable CTAD for safety, and aggregates/aliases remain problematic for future C++20 fixes.
AI-written summary · about
chapters (33)
- 0:00Introduction
- 1:41Class template argument deduction
- 5:16How does it work
- 11:12Make functions
- 12:47Vector
- 17:59Recommendation
- 19:09Priority
- 20:41Set
- 21:50Map
- 26:25No constructor arguments
- 28:09Why you should be careful
- 29:23Smart pointers
- 30:51Race
- 31:52Seated
- 32:38Disable C10
- 33:44Type identity idiom
- 35:45Other techniques
- 37:41STL deduction guides
- 38:45Vector deduction guides
- 42:13Vector deduction guide
- 43:27Array deduction guide
- 47:15Primary template only
- 49:33Should you do this
- 51:07Smart pointer constructors
- 51:37Signatures
- 52:16Unique pointers
- 53:04String views
- 54:00Dont use deduction guides
- 55:29CTF proposals
- 56:19Aggregates
- 57:10Aggregate Guide
- 58:26Type Aliases
- 59:17Template Arguments
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 01m“Template Normal Programming (part 2 of 2)"
01h 30mRethinking the Way We Do Templates in C++
01h 02mC++17: The Language Features
57mIntroduction to C++ Template Metaprogramming
