Most (but I only actually know a small number so lets not get picky on that point) high level languages support multiple different assignment operators.
a += 5; // increment a and assign result beack to a.
But none (that I have looked at (again a small number)) seem to support the &&= operator.
The reason I ask I recently saw this:
// simplified.
bool x = false;
x = x && testA(); // perform test A/B/C/D stop on first failure.
x = x && testB();
x = x && testC();
x = x && testD();
And I was wondering why we could not use:
x &&= testA(); // perform test A/B/C/D stop on first failure.
x &&= testB();
x &&= testC();
x &&= testD();
The reason being that &&= is not supported in C/C++ which made we think why.
Is there a logical (no pun intended) reason why the language supports all the other major operators with an assignment form but not the &&= or ||=
I have a vague recollection for an argument against these, but google and SO searches are hard when your search term is '&&=' and as a result I found nothing.
&&
and ||
are special in the sense that they are, in most languages, the only constructions that provide short circuiting evaluation so it kind of makes sense for them to be treated differently from the normal, non short-circuiting, operators when it comes to the abbreviated forms. The easiest way to avoid the confusion of &&=
short-circuiting or not is not including it in the first place.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With