Which one is more appropriate for compile-time configurations (such as debug/release), preprocessor directives, or if constexpr
?
#define DBG
#if DBG
// some code
#endif
// --------------------------------- or
inline constexpr bool DEBUG { true };
if constexpr ( DEBUG )
{
// some code
}
Note that, if
if constexpr
is not part of a template, then the other parts of theif
(such as theelse
s) are still compiled and checked for validity.From cppreference: