Should there be short circuit compound assignment for booleans?

Consider the following code:
1
2
3
bool b = somefunca();
//...code...cannot do bool b = somefunca() && somefuncb();
b &= somefuncb();

In this case, even if somefunca() returned false, making b false, somefuncb() is still evaluated.

Do you think there should be short circuit compound assignment operators? EG &&=, ||=, or do you think these would be pointless due to other ways to do this, even in strange situations?
Last edited on
I don't think they're needed. That would be a very exotic case, because usually the omitted code does not need or must not be executed when somefunca() returns false, so you usually have something similar to this:
1
2
3
4
5
6
7
8
9
10
bool b=false;
if (somefunca())
{
  //...code...
  if (somefuncb())
  {
    //...more code...
    b=true;
  }
}


And if the rare case happens that the code must be always be executed, you still have
if (b)b=somefuncb();
Last edited on
Topic archived. No new replies allowed.