Here, I created the constexpr function. How to determine exactly whether it will run at compile time or at runtime?
2 answers
Assign its value to a variable declared as constexpr . If everything goes well, it means that it was executed at compile time :)
- 2And if the function returns
void? - 伪位蔚蠂慰位蠀蟿 - oneand the meaning of such a function? constexpr does not have any more options how to return the result. - KoVadim
- @KoVadim as not, out-parameters are the same - Abyx
- Yes, of course you can, but the whole point of such functions is lost ... - KoVadim
|
You can try to use it in a context that involves exclusively compile-time execution. For example, static_assert :
constexpr void f(int a) { } /*const*/ int i = 42; static_assert( (f(i),true), ""); Without const , i will have an error:
error: condition for static assertion
|