Who's Afraid of the Big Bad Template?
summary
Claim: templates, including NTTPs and TTPs, can replace repetitive runtime containers and drive entire data structures at compile time. Builds a grocery example that evolves from 5- and 10-item baskets to a 50-item cart, using std::array, std::tuple-like std::tuple access with std::get, fold expressions, UDLs and constexpr constructors to create compile-time groceries, bags and a compile-time cart whose total is computed in a static_assert — a working proof that templates handle this use case.
AI-written summary · about
chapters (17)
- 0:00Introduction
- 2:13Why developers fear templates
- 5:06Templates vs metaprogramming
- 6:08NTP vs TTP explained
- 8:12NTP restrictions and limitations
- 11:29Creating compile-time structures
- 12:52Implementing grocery interfaces
- 14:21Building compile-time carts
- 16:32User-defined literals demo
- 18:42Full compile-time program goal
- 19:05Switching to compile-time containers
- 20:31Using std::tuple for type diversity
- 22:18Compile-time cart implementation
- 24:05Calculating total cost at compile time
- 25:31Generating receipt with fold expressions
- 26:56Final compile-time UDL adjustments
- 27:39Summary and conclusion
