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, evaluates cond1

  • If cond1 is true, evaluates cond2.

  • and finally performSomeAction() if cond2 is also true.


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.