Guarantee function call in logical AND expression
In if (std::atomic_exchange(&someFlag, false) &&
cond1 && cond2)
std::atomic_exchange(&someFlag, false)
will be called first.If evaluate to
true
, evaluatescond1
If
cond1
is true, evaluatescond2
.and finally
performSomeAction()
ifcond2
is alsotrue
.
Yes, the order is guaranteed. From cppreference.com:
Every value computation and side effect of the first (left) argument of the built-in logical AND operator
&&
and the built-in logical OR operator||
is sequenced before every value computation and side effect of the second (right) argument.