Apparently, consteval
is going to be a keyword in C++20. The cppreference page for it is currently blank. What is it going to be and how does it relate to constexpr
?
C++20 introduces the keyword consteval, which is used to indicate that a function must evaluate at compile-time, otherwise a compile error will result. Such functions are called immediate functions. In the above example, the first two calls to greater() will evaluate at compile-time.
A consteval function can only invoke a constexpr function but not the other way around. use fundamental data types as variables that have to be initialized with a constant expression. A consteval (constexpr) function cannot. have static or thread_local data.
A constexpr function is a function that can be invoked within a constant expression. A constexpr function must satisfy the following conditions: It is not virtual. Its return type is a literal type. Each of its parameters must be of a literal type.
constinit - asserts that a variable has static initialization, i.e. zero initialization and constant initialization, otherwise the program is ill-formed.
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).
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With