4 ms·
I didn't understand the difference between constinit and consteval. It appears that constinit is just consteval applied to global/static variables. Why two keyw
by fractalb 4y ago
I didn't understand the difference between constinit and consteval. It appears that constinit is just consteval applied to global/static variables. Why two keywords then?
- gpderetta 4y agoThey are unrelated. consteval is applied to functions and asserts that a function definition can be evaluated at compile time, and only at compile time, for all possible arguments; the compiler is required to check this. This is different form contexpr that merely allows it and possibly only for a subset of the arguments. constinit is applied to static variables and asserts that the initialization is static (static variables can otherwise still be initialized dynamically on startup or on first use).
- fractalb 4y agoBoth consteval and constinit are evaluated at compile-time, right? If yes, then why two different keywords?