3 ms·
I don’t think you should count on compilers doing that, especially not if it is easy to do better. The modern way to enforce that would be to write constexpr f
by Someone 4y ago
I don’t think you should count on compilers doing that, especially not if it is easy to do better.
The modern way to enforce that would be to write constexpr functions to do the conversions (or not? Are compilers required to evaluate constexpr expressions at compile time, where possible?)
- twic 4y ago> Are compilers required to evaluate constexpr expressions at compile time, where possible? No. But C++20 adds consteval, which does carry that requirement: https://www.modernescpp.com/index.php/c-20-consteval-and-constinit https://www.modernescpp.com/index.php/c-20-consteval-and-con... Well, sort of. It has to produce a constant expression, and in practice the way to do that is to evaluate it at compile-time. But under the as-if rule, a compiler can do what it likes, up to and including producing a binary containing your source code and a copy of gcc, and compiling your entire program when you run it.