Do the &= and |= operators for bool short-circuit?

From C++11 5.17 Assignment and compound assignment operators:

The behavior of an expression of the form E1 op = E2 is equivalent to E1 = E1 op E2 except that E1 is evaluated only once.

However, you're mixing up logical AND which does short-circuit, and the bitwise AND which never does.

The text snippet &&=, which would be how you would do what you're asking about, is nowhere to be found in the standard. The reason for that is that it doesn't actually exist: there is no logical-and-assignment operator.


The short-circuit (i.e. lazy) evaluation is only for logical && and ||. Bitwise & and | evaluate both arguments.


The code allTrue &= check_foo(); is equivalent to allTrue = allTrue & check_foo() In which you are using bitwise AND and no lazy evaluation is performed.

The bitwise AND must take two arguments who's binary representation has the same length, and useslogical AND operation to compare each corresponding pair of bits.


No, they do not cut-short.

Note that the &= and |= operators are formed as &+= and |+=. Bit operators & and | does not perform shortcut evaluation.

Only boolean operators && and || perform it.

It means, that a shortcutting operator would have to be traditionally named &&= and ||=. Some languages provide them. C/C++ does not.