3 ms·
I'm not even sure what that would mean since the machinery to compute the value won't exist in the binary. You can get this behavior by initializing a variable
by gumby 7y ago
I'm not even sure what that would mean since the machinery to compute the value won't exist in the binary.
You can get this behavior by initializing a variable with the value of another variable whose value is a constexpr. This is a case in which the order of initialization of global variables is not ambiguous!
constexpr int foo_init_value = 2 + 4;
int foo = foo_init_value;
Actually not a bad idiom.
But like you I do wish you could apply constexpr-like behavior to expressions rather than just statements:
What you're If you could really apply really applied to expressions you could write something like
int foo = _compute_at_compile_time(2 + 4);
Of course the compiler can already do this degenerate example for you.
- bigcheesegs 7y agoThe first example is handled by constinit (or whatever we end up calling it) and the second is handled by consteval, although it has to be put in a function.