C++ Function Templates: How Do They Really Work?
summary
Claim: function templates are blueprints not functions, compilers synthesize signatures and instantiate definitions only as needed from calls. Crucial surprising rule: explicit specializations do not participate in overload resolution — they reuse names and are considered only after overload resolution picks a candidate. Practical advice: avoid explicit function-template specializations; prefer ordinary overloads or a helper class-template with operator() indirection. Notes on direction: library work moves toward customization-point objects and core proposals explore abbreviated template syntax (auto + requires) for C++20.
AI-written summary · about
chapters (9)
- 0:00Introduction and thanks
- 1:29What is a function template?
- 10:30Function templates vs specializations
- 20:10Template argument deduction
- 27:12Partial ordering of templates
- 39:47Explicit specializations pitfalls
- 43:37Future of function templates
- 53:52Resources and next steps
- 54:34Q&A session
related talks
01h 03mBack to Basics: Function and Class Templates
57mIntroduction to C++ Template Metaprogramming
01h 21mWhat Has C++20 Ever Done For Templates?
01h 01mRethinking the Way We Do Templates in C++
50mExpression Templates: Past, Present, Future
01h 29mHigher-order functions and function_ref
01h 30mRethinking the Way We Do Templates in C++
01h 00mConcepts in C++20: Revolution or Evolution
