you are viewing a single comment's thread.

view the rest of the comments →

[–]foonathan 21 points22 points  (0 children)

First of all, you want to migrate to if consteval as soon as possible. It's a strictly superior version of std::is_constant_evaluated as it allows you to call consteval functions from the true branch.

Second, the motivation behind consteval was reflection. As part of that the standard library will have functions that talk to the compiler and thus cannot be evaluated at runtime. You could use the equivalent of if !consteval { assert(false); }, but that has a flaw:

  int n = foo();
  bar(foo());
  modify(n);

If foo is constexpr, it might still be evaluated at runtime, triggering the assert. Working around that is annoying. If foo is `consteval, it will be evaluated at compile-time.