91

Apparently, consteval is going to be a keyword in C++20.

What is it going to be and how does it relate to constexpr?

6
  • "Apparently, consteval is going to be a keyword in C++20" - provide a link to support this assertion. Commented Nov 17, 2018 at 1:17
  • 12
    @NeilButterworth The cppreference page I already linked to claims it to be. Commented Nov 17, 2018 at 1:19
  • decltype(std::declval<f()>)'ish but .. fun stuff. Commented Nov 17, 2018 at 1:20
  • 20
    @NeilButterworth: By that reasoning, nobody can even call it "C++20" or say that there will even be a next version of C++. It is not unreasonable to ask about upcoming features that have been approved in accord with WG21 procedures at the various meetings. Like the most recent one. Commented Nov 17, 2018 at 1:36
  • 2
    cppreference now provides some info Commented Sep 8, 2019 at 19:44

1 Answer 1

70

It declares immediate functions, that is, functions that must be evaluated at compile time to produce a constant. (It used to be spelled constexpr! in a previous revision of the paper.) In contrast, constexpr functions may be evaluated at compile time or run time, and need not produce a constant in all cases.

The adopted paper is P1073R3, which is not yet publicly available, but a previous revision is available and the introductory (motivation and high-level description) portion is about the same (except that the "Source Locations" section is deleted in R3).

Sign up to request clarification or add additional context in comments.

13 Comments

No, you can't, just like constexpr.
It might be worth pointing out that the motivation is to have functions that rely on compiler data structures that need not be preserved in the binary.
@Andry: it's not just about compile-timedness. It's about that the result is wrong. Check out: godbolt.org/z/12aZCH. The result depends on optimization level.
Does this mean consteval functions aren't available at runtime?
That's correct, @MarcusJ, consteval functions won't be available at runtime because there's no way to call them unless all their parameters are known at compile-time. And of course, if that's true, the compiler can figure out (at compile-time) what those routines return, with no need to actually generate code for them.
|

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.