How To Use `constexpr` In C++23
summary
C++23 widens what can run at compile time and the rules matter: you cannot deallocate memory not allocated during constant evaluation, use reinterpret_cast, or rely on virtual inheritance, and many cmath trigonometric functions and thread/mutex/atomics remain non-constexpr in practice. Demonstrations show fixing a unique_ptr by adding a constexpr destructor, move ops and conditional noexcept so tests compile, using immediately-invoked constexpr lambdas and Catch2’s static_require compiled twice for runtime/compile-time parity, and building a compile-time scripting engine "consexer" and an ARM emulator that actually work at compile time.
AI-written summary · about
chapters (11)
- 0:00Introduction to constexpr
- 1:55Rules and limitations
- 8:17History of constexpr
- 12:11Why use constexpr
- 14:46Building constexpr unique_ptr
- 27:14Legacy code to constexpr
- 33:37Virtual inheritance limits
- 35:45Real-world constexpr examples
- 45:37Stdlib constexpr limits
- 57:00Adopting constexpr in C++23
- 59:28Q&A
related talks
39mconstexpr everything?!
01h 00mRemoving Metaprogramming From C++, Part 1 of N: constexpr Function Params
01h 31mconsteval All The Things?
32mCute C++ Tricks, Part 2 of N: More code you should learn from and never write
59mHow C++23 changes the way we write code
01h 03mC++20: The small things
24mC++17 and 20 Goodies
54mC++ is a Metacompiler
