This is a way to express an expression for bool. In C ++, though, the operator! may be overloaded. Another way for C / C ++:
0 != (expr)
C ++ only:
static_cast<bool>(expr)
[edit] Thinking more about overloading the C ++ operator, it makes sense to avoid using operators. Libraries like Boost.Spirit and Boost.Lambda use expression patterns and lazy evaluation, so expressions like (expr) || call() (expr) || call() may not behave as expected. The most bulletproof version of this macro is as follows:
#define uassert(expr) if(expr) {} else { uasserted(...); }
Only the conversion of expr to bool is used here. The else branch is needed to protect against expressions like uassert(x) else something_else(); .
Maxim Egorushkin
source share