6 ms·
> the compiler guarantees to evaluate it at compile time It doesn't guarantee that. For example: static constexpr int fac(int x) { return x <= 1 ? 1 : x *
by zmodem 10y ago
> the compiler guarantees to evaluate it at compile time
It doesn't guarantee that.
For example:
static constexpr int fac(int x) { return x <= 1 ? 1 : x * fac(x - 1); }
int f() {
return fac(4); // May or may not be evaluated at run-time.
}
char arr[fac(4)]; // fac(4) is evaluated at compile-time.
- JoshTriplett 10y agoI should have said, "guarantees that it can evaluate it at compile time if needed, such that you can use it where the compiler expects a compile-time constant expression". Yes, the compiler can choose to defer it until runtime in some cases.