Introduction to C++ Template Metaprogramming
summary
Covers concrete techniques for real code: uses C++11/14 features like type_traits, void_t trick for member detection, and SFINAE via enable_if to disable overloads; shows three selection strategies—explicit specialization, tag dispatch, and enable_if—to pick faster algorithm variants (example: memcpy-style fast copy and O(1) vs O(n) distance). Replaces recursive metafunctions with constexpr functions and builds a compile-time cstr plus a static_assert-based constexpr string validation for printf-like format checks. Notes GCC/Clang work; older MSVC has limits.
AI-written summary · about
chapters (19)
- 0:00Intro
- 1:42Motivation: Checking Type Constraints
- 3:59Motivation: Algorithm Selection
- 5:18Motivation: Compile-Time Computation Some fairly complex computations can be performed ahead-of-time
- 5:57Reminder: Class Template Specialization
- 7:03A large collection of metafunctions that check properties of types
- 9:01Type Traits and static assert
- 10:19Non-Constraining Use of Traits
- 17:41Member Detection with void_t
- 23:24Generalized Version (Expression SFINAE)
- 27:37Specializing a Template Based on Traits - There are multiple approaches, each with its merits Hand-written template specialisation
- 28:22Hand-Written Template Specialization
- 31:56Tag Dispatch Overload functions on a type that depends on a type tra les
- 34:11distance_helper
- 35:24std::enable_if
- 43:39Recursive Templates
- 46:29Some Simple Uses
- 47:29constexpr Over Types
- 51:52Compile-Time Safe printf
related talks
01h 06m“C++ Metaprogramming: Journey from simple to insanity and back"
01h 00mModern Template Metaprogramming: A Compendium, Part I
01h 01mRethinking the Way We Do Templates in C++
01h 01m“Template Normal Programming (part 2 of 2)"
01h 01m“How bad is Meta-Programming still today?"
58m“Template Normal Programming (part 1 of 2)”
01h 03mBack to Basics: Templates (part 2 of 2)
59mMetaprogramming: From Templates to Concepts
