Understanding The constexpr 2-Step
summary
Explains the constexpr two-step: generate dynamic data at compile time with constexpr new/delete, copy it into an oversized stack-style array, then create a right-sized static blob and return views (std::span or std::string_view). Demonstrates a 300-element angle table that compiles to 300 doubles but initially leaves 1,696 zeros of wasted capacity until right-sizing to capacity 512→300. Shows use of template non-type parameters to force static storage, prefers consteval + NTTP to catch errors, notes a Clang bug that elides static data inside consteval and gives mitigation.
AI-written summary · about
chapters (19)
- 0:00Introduction
- 2:14Why this talk is challenging
- 3:02C++20 constexpr containers late arrival
- 4:08Using constexpr vector and string
- 7:46Compile-time memory allocation rules
- 10:58Introducing constexpr two-step
- 13:07Talk goals levels one-four
- 17:02Oversized array for compile-time storage
- 19:32Level one attempt one angles
- 22:25Level one attempt two binary size
- 27:02Level two string to constexpr string view
- 31:35Pitfalls with constexpr string views
- 36:15consteval to catch bugs early
- 38:04Builder pattern for dynamic ops
- 42:25Level 2.5 span and string view enhancements
- 48:51Right-sizing arrays avoiding bloat
- 51:41Right-sizing arrays compile-time sizes
- 57:00Level four vector of strings
- 1:00:13Summary
related talks
01h 18m“Variable Templates and Compile-Time Computation with C++14"
01h 00mconstexpr: Applications
01h 04mconstexpr: Introduction
01h 10m“constexpr ALL the Things!”
01h 01mRethinking the Way We Do Templates in C++
03mAnything can be a Constexpr if you try hard enough
01h 04m“Constant Fun"
01h 09m“Compile-time programming and reflection in C++20 and beyond”
