According to https://en.cppreference.com/w/cpp/language/statements, I know I can express condition in C++ by at least the following two ways:
- An if statement
if (a) { b } else { c }
- An expression statement
a ? b : c
And we have constexpr for if
if constexpr (a) { b } else { c }
Since in some area, we can only use expression statement for conditions, to avoid getting a "error: expected expression". So I write
cond ? call_func(), 0 : 0
However, how can we involve constexpr this in expression statement? This is a real problem, consider
template <int FLAG>
void f() {
SOME_MACRO_ONLY_ALLOW_EXPRS({ FLAG ? call_func(), 0 : 0; })
}
I know I can specialize f
for FLAG=1
and FLAG=0
. However, it may involves lots of modification.