In which class of tasks is it constexpr use constexpr ? I got the impression that almost always I can use const . When do I need to set the value at compile time?

1 answer 1

The const methods imply compile-time checking for the absence of modification (and such possibilities, for example, returning a non-constant pointer) of the type state, excluding mutable fields. The expression itself can be calculated at run-time.

constexpr other constexpr , allows you to mark expressions that are necessarily computed at compile time and can be used, say, as template parameters, or in constant initializers.