How and When To Write a C++ Template
summary
Covers concrete rules and tradeoffs: when templates save code versus when a variant or type erasure is better, concrete examples (optional, std::find, variadic sum, PI variable template), and real fixes like preferring overloads to function-template specializations. Shows testing by defaulting a template parameter so tests inject a stub type, explains explicit instantiation to cut compile time with extern template, demonstrates modern techniques like if constexpr and concepts as safer SFINAE replacements, and uses CPInsights to reveal actual instantiations.
AI-written summary · about
chapters (16)
- 0:00Introduction and motivation
- 1:34What are templates?
- 5:10Types of templates
- 7:13Fundamentals of templates
- 8:58Template instantiation
- 11:33Variations of templates
- 18:03Advanced parameters and folds
- 22:42Type deduction overview
- 23:51Complex template parameters
- 29:52Typename and compiler errors
- 35:50Function template specialization
- 38:48Understanding SFINAE
- 42:13Choosing the right abstraction
- 47:21Lambda templates and if constexpr
- 49:53Testing and architecture
- 56:41Tooling and conclusion
related talks
01h 01mRethinking the Way We Do Templates in C++
15mVerification of Templated Code in C++
10mSession Preview - Interview With – Katherine Rocha
30mExpression Templates for Efficient, Generic Finance Code
47mDesign Patterns - The Most Common Misconceptions (2 of N)
55mHow to "OO" in C++
41m“Avoiding Disasters with Strongly Typed C++”
54mWriting C++ to Be Read
