I want to get rid of most #ifdef
-clauses if possible. To that end, my code would contain many cases of the following pattern:
template<bool b>
void f(){
if constexpr (b) {
invalid;
}
}
to replace code of the form
void f(){
#ifdef FOO
code_invalid_unless_FOO_is_defined;
#endif
}
The first example not compile, as invalid_code
is not declared.
I had hoped that everything inside if constexpr
is ignored, which seems to be not the case. Can I use if constexpr
at all to eliminate preprocessor usage of that form?
Edit: this question is different from the linked one, because it involves templates. The statements on this site made me think that in that case, the code inside a discarded constexpr
is not checked.