consteval All The Things?
summary
Consteval is a C++20 tool that forces compile-time evaluation but also requires arguments to be constant expressions, so ordinary function parameters are never constant expressions and many calls fail to compile. Examples: consteval constructors and implicit conversions make a string_view impossible to dangle; consteval lambdas and UDLs let parsing fail at compile time; defaulted consteval constructors shrink debug binaries. Downsides: no emitted code to debug, sanitizers and fuzzers don’t apply, and compilers (GCC vs Clang) behave differently. Testing strategy uses dual-compilation with static_asserts and runtime builds.
AI-written summary · about
chapters (13)
- 0:00Introduction and background
- 3:22In memory of Rainer Grimm
- 4:58Constexpr and compile time
- 8:20Constant evaluation rules
- 21:02Understanding constinit
- 23:20The role of consteval
- 32:31Constant evaluation and UB
- 44:10If constexpr vs. if consteval
- 50:41Consteval constructors
- 56:04Consteval member functions
- 1:04:06Consteval special members
- 1:16:24Consteval UDLs and functions
- 1:22:22Testing and debugging consteval
related talks
39mconstexpr everything?!
01h 00mHow To Use `constexpr` In C++23
01h 29mTesting Everything in Constexpr
54mC++ is a Metacompiler
55mTemplates Made Easy With C++20
01h 00mRemoving Metaprogramming From C++, Part 1 of N: constexpr Function Params
01h 35mC++20 – My Favourite Code Examples
01h 03mC++20: The small things
