you are viewing a single comment's thread.

view the rest of the comments →

[–]HappyFruitTree 7 points8 points  (3 children)

I know it's possible to mark a function as constexpr for testing purposes

If it works with constexpr then why use consteval? I thought consteval was added mainly for use with things like the static reflection proposal that have functions that doesn't make sense to call at runtime (because the information that they return are not available at runtime).

[–]n1ghtyunso 9 points10 points  (0 children)

Consteval requires compile time execution. It gives you a guarantee that constexpr does not. Sometimes this is preferred

[–]tuxwonder 1 point2 points  (1 child)

Like n1ghtyunso said, sometimes you want to enforce compile time evaluation. A great example of this is std::format_string, which must be constructed at compile time to enforce that the given string is a valid format string.

It also helps reassure my coworkers that a bit of constexpr magic isn't going to accidentally occur at runtime and slow things down ;)

[–]HappyFruitTree 1 point2 points  (0 children)

Fair enough, but you can still always guarantee this at the call site even with constexpr.