Embracing CTAD
Talkat CppCon 2023 · on Wednesday, 2023-10-04· at 15:15· Maple 3/4/5, 6700 North Gaylord Rockies Boulevard·
summary
Class template argument deduction gives concrete rules: compilers synthesize deduction guides from constructors and from a few special cases so template parameters are inferred for object initialization, aggregates and C++20 non-type parameters, and user-written deduction guides handle iterator/value extraction. Important gotchas include copy deduction guide forcing same-specialization results, no forwarding references (T&& in constructors does not behave like universal refs), and CAD turning off as soon as any template parameter is specified so implicit deduction guides can be disabled intentionally.
AI-written summary · about
chapters (25)
- 0:00Introduction
- 2:15What is CTAD
- 4:24CTAD versus function deduction
- 6:32When CTAD works and when it doesn't
- 9:21CTAD benefits examples
- 11:50CTAD in C++17 and C++20
- 15:05How deduction guides are made
- 17:10Writing custom guides
- 20:27Copy deduction guide
- 23:14CTAD versus normal deduction
- 25:42Why partial CTAD fails
- 27:33CTAD pitfalls
- 31:33CTAD surprises and design
- 33:18Advice for users and vendors
- 35:04Q&A: Partial CTAD and disambiguation
- 36:49Q&A: Deduction guides for alias templates
- 37:55Q&A: Fixing user guides
- 39:02Q&A: Forwarding references in CTAD
- 40:07Q&A: Guide syntax design
- 41:10Q&A: Forwarding reference experiment
- 42:11Q&A: Non-type template parameters
- 42:55Q&A: Guide scope limits
- 43:37Q&A: Using tags for CTAD
- 44:19Q&A: Disambiguating containers
- 45:02Closing remarks
related talks
06mConstructor Template Argument Deduction Best Practices
01h 03mDeducing this Patterns
01h 02mBack to Basics: Templates in C++
01h 07mBack to Basics: Templates (part 2 of 2)
57mAlices adventures in Template Land
54mModern Template Techniques
59mBack to Basics: Generic Programming in C++
53mFrom C++ Templates to C++ Concepts - Metaprogramming: an Amazing Journey
