Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Is &= guaranteed to behave like hypothetical &&= operator?

sometimes I would like to do

bool success= true;
success &&= dosmthing1();
success &&= dosmthing2();
success &&= dosmthing3();
if (success)

Lets ignore that I could be using exceptions... my question is is it guaranteed by C++ standard that &= will behave like nonexisting &&= for my use case? ...

EDIT: do smthing-s return bool

like image 621
NoSenseEtAl Avatar asked Jun 21 '13 13:06

NoSenseEtAl


People also ask

What type of word is is?

Is is what is known as a state of being verb. State of being verbs do not express any specific activity or action but instead describe existence. The most common state of being verb is to be, along with its conjugations (is, am, are, was, were, being, been).

What are the meanings of is?

present tense third-person singular of be.

What does minus 1 mean?

In mathematics, −1 (also known as negative one or minus one) is the additive inverse of 1, that is, the number that when added to 1 gives the additive identity element, 0. It is the negative integer greater than negative two (−2) and less than 0.

Is or a conjunction?

Or is a conjunction that connects two or more possibilities or alternatives. It connects words, phrases and clauses which are the same grammatical type: Which do you prefer? Leather or suede? You can have some freshly baked scones or some chocolate cake or both.


2 Answers

That depends on how you expect &&= to work. If you want x &&= y(); to be equivalent to x = x && y();, then no, because in this expression y() is not called if x starts out as false, but in x &= y(); it will be.

If you don't expect it to be short-circuiting and all your expression really have type bool (not something convertible to bool, like pointers, integers, or user-defined objects), it works. That's a lot of restrictions though.

like image 137
Sebastian Redl Avatar answered Nov 15 '22 18:11

Sebastian Redl


No, & is a bitwise and, && is boolean and. If dosmthing* returns something other than 1 or 0, the results will be different.

like image 43
zennehoy Avatar answered Nov 15 '22 19:11

zennehoy