“C++ Metaprogramming: Journey from simple to insanity and back"
summary
Covers template metaprogramming techniques that generate code at compile time using templates, partial specialization, default template arguments and SFINAE, with practical idioms like remove_pointer and an if_compiles macro that tests arbitrary expressions via overload resolution and sizeof tricks. Shows numeric examples run 2^27 iterations where power 16 takes ~0.5s and power 20 ~0.9s, and a divide‑and‑conquer generation that drops 0.5s to 0.05s. Notes recursion depth limits, when to prefer constexpr, and how these tricks enable portable, self‑adapting code.
AI-written summary · about
chapters (19)
- 0:00Intro
- 2:02What is Metaprogramming?
- 2:24Why use metaprogramming?
- 7:15Note on C++11 syntax
- 7:55Not Tools of metaprogramming
- 15:02Compile-time (static) assertions
- 24:50Example - computing r with partial specializations
- 28:33More practical metaprogramming examples
- 29:43Guidelines for using metaprogramming in everyday application programming Compile-time numeric calculations
- 30:58Example - bit string
- 34:06Indexing bits in a template
- 37:16Indexing deque
- 40:50Type manipulations
- 41:52Life before C++11 was miserable...
- 46:00Type-dependent code for efficiency
- 49:33Argument non-evaluation
- 49:56SFINAE check for a member function
- 53:07Back to the drawing board
- 54:12Nobody expects global operators!
related talks
57mIntroduction to C++ Template Metaprogramming
01h 00mModern Template Metaprogramming: A Compendium, Part I
01h 01m“How bad is Meta-Programming still today?"
01h 01mRethinking the Way We Do Templates in C++
47mReducing Template Compilation Overhead, Using C++11, 14, 17, and 20.
58m“Template Normal Programming (part 1 of 2)”
59mModern C++ for Fun and Profit: This isn’t your old C++
55mTemplates Made Easy With C++20
