3 ms·
constexpr isn't mean to replace the preprocessor. This will not compile for the same reason that if (false constexpr) { random gibberish } will not compil
by revelation 10y ago
constexpr isn't mean to replace the preprocessor. This will not compile for the same reason that
if (false constexpr) { random gibberish }
will not compile, and that's a good thing. I think it would be odd to "hack" static_assert for this special case.
- toth 10y agoOpinions differ I guess. I would love it if if constexpr ( COND) { CODE }; would compile even if CODE only compiles when COND is true. There a lot of nice use cases for that, and that's how the static_if in D works. You can still do this sort of stuff with template overloads, but it's much more cumbersome.
- Kristine1975 10y agoThat's the case though, as long as CODE is syntactically correct. So this would compile: if constexpr (condition) { print("yes"); } While this wouldn't: if constexpr (condition) { print({ } At least that's my understanding.