This One Weird Trick: std::integral_constant
summary
Uses std::integral_constant to move computed values into types so recursion becomes compile-time and eliminates runtime calls even with no optimizations; demonstrates a Fibonacci implemented via type-level memoization that compiles fast and runs immediately. Shows using an auto return type to place results in return types, then extracting the value to avoid any function call. Builds an overload-based type map from integers to types and a get_common_size utility that returns std::optional filled when all sizes match (example: 2,2,2 → optional{2}, 2,2,3 → empty).
AI-written summary · about
chapters (4)
- 0:00Start
- 1:56Overload Resolution
- 3:06Overload on Collections of Integral Constant
- 4:23Example Main Function
related talks
29mintegral types
01h 03mHigher order functions for ordinary C++ developers
54mGeneric Programming Without (Writing Your Own) Templates
51mThe C++ Type System is your Friend
50mC++ Costless Abstractions: the compiler view
01h 13mType safe C++ – LOL! :-)
55mTemplates Made Easy With C++20
01h 06m“C++ Metaprogramming: Journey from simple to insanity and back"
