CTAD: Complete Guide to Class Template Argument Deduction
summary
C++17’s class template argument deduction (CTAD) lets the compiler infer template parameters from constructors by creating implicit deduction guides derived from the primary template, and C++20/23 extend that to aggregates support and inherited constructors. It fails for references, arrays, partial explicit template arguments (you cannot supply some and have others deduced), and some non-deduced contexts. User-written guides override implicit ones; never declare guides for std types. Note the copy-preference (copy-style guides often win over converting constructors). Test, document, and add explicit guides when library behaviour must be precise.
AI-written summary · about
chapters (18)
- 0:00Introduction to CTAD
- 2:58Motivations for the Talk
- 4:22Function Template Deduction
- 8:57Class Template Deduction
- 11:42CTAD Use Cases
- 14:41CTAD in Ranges
- 17:31CTAD Evolution
- 20:57CTAD Capabilities
- 24:16Structural Types
- 26:54How CTAD Works
- 30:02Implicit Deduction Guides
- 37:19User-Defined Guides
- 39:24Guide Rules and Pitfalls
- 44:13CTAD vs Forwarding
- 49:23Limitations of CTAD
- 54:55CTAD Preferences
- 59:49Handling Edge Cases
- 1:03:55Conclusion and Q&A
related talks
01h 00mClass template argument deduction in C++17
01h 01mClass Template Argument Deduction for Everyone
01h 04mClass Template Argument Deduction in C++17
58mThe Pattern Matching We Already Have
01h 37mRethinking the Way We Do Templates in C++ even more
01h 01m“Template Normal Programming (part 2 of 2)"
01h 21mWhat Has C++20 Ever Done For Templates?
58m“Template Normal Programming (part 1 of 2)”
