-
Boolean expressions are evaluated from left to right (the same in Java), so it is totally OK to write code like
if(a < x.size() && x[a]){ ... }
where
x
is a vector. -
There is no
&&=
and||=
operators in C++, instead you can use&=
and|=
. Though&=
and|=
are not specially for boolean values, they work perfectly for boolean values. -
If the numbers you work with support infinity or NaN, boolean expressions become tricky. For example, suppose
nan
is a varialbe representing Nan, both2 < nan
and2 >= nan
returnfalse
, which is not what we want. A safer way is to first check whether numbers involved are NaNs. Hopefully, ternary boolean type will be introduced into C++ in future.