Sololearn: Learn to Code
New course! Every coder should learn Generative AI!
Try a free lesson
+ 14
constexpr is evaluated at compile-time , only when all of the arguments are constant expressions, otherwise it can be evaluated at runtime also. consteval (was spelled "constexpr!" in previous revision papers) make sure that function must be evaluated at compile time only. On the other hand *constinit* is meant to be applied on variables with static storage duration, to make sures that all of them are initialised at compile time only ( removing the possibility of having "static initialization order fiasco" where initialisation of one static object require other static variable to be initialised which happens to be in different compilation unit which unluckily could not be constructed by then )
23rd Jan 2021, 4:33 AM
Arsenic
Arsenic - avatar
+ 9
That being said you can't use all of them on one variable as according to cppreference (link shared by George Ryan ) " At most one of the constexpr, consteval, and constinit keyword shall appear in decl-specifier-sequence " And it makes sense as consteval is just forced constexpr at compile-time and if you look closely, you can easily see that constexpr kindof implies constinit also.
23rd Jan 2021, 4:40 AM
Arsenic
Arsenic - avatar
+ 1
ChillPill indeed, you got that right !
23rd Jan 2021, 5:01 AM
Arsenic
Arsenic - avatar
- 5
Can someone solve a code in c# tomorrow?
24th Jan 2021, 7:50 PM
Abdalrhman Wa
Abdalrhman Wa - avatar