Is there a way of using the compound assignment operator to achieve something like this:
a = (a * 10) + b;
Initially I tried the following:
a *= 10 + b;
but this is equivalent to:
a = a * (10 + b)
Just curious. Ran across this today. This is not homework.
If you really need to make sure
ais evaluated only once, you could use the fact that*=returns lvalue:but it’s hardly good code, and I think it might be invoking undefined behaviour prior to C++11 due to modifying
atwice (once in *= and once in +=) without intervening sequence points.