C++: consteval vs constexpr vs runtime functions
There is this in-depth blog post
going over consteval, constexpr, and runtime functions.
consteval functions are evaluated only at compile-time.
constexpr functions can be evaluated at compile- or runtime.
Main point of the post: They can all call each other as long as the taken code path (branch) fits the call type.
Side notes to keep in mind:
- The C++23 feature
if constevalcan be especially useful forconstexprfunctions. constexprfunctions can be implemented s.t. they are only callable either at compile-time XOR runtime. This is considered bad practice.- C++23 Foot Gun: A templated
constexprfunction can be implicitly converted to aconstevalfunction (Escalation).