The trick is that C++’s system of abstraction allows expressions to work on both RHS and LHS values without grammatic differentiation, and assignment just handles LHS values as implicit pointers once they’re calculated. It’s not a special syntax.
Ok I meant an LHS expression needs to resolve to a location.
a || b doesn’t do that unambiguously. It could mean if a is not false then use a else use b or it could mean use the value which is the boolean OR of the value of a and the value of b
Of course it does. Why wouldn’t it?
LikeLike
Bytes are expensive, man!
LikeLike
I did not know that.
LikeLike
The trick is that C++’s system of abstraction allows expressions to work on both RHS and LHS values without grammatic differentiation, and assignment just handles LHS values as implicit pointers once they’re calculated. It’s not a special syntax.
LikeLike
However, (a || b) = … does not work, even though it would only require stretching the abstractions a little bit further.
LikeLike
I can see why this doesn’t work. The LHS has to resolve to a symbol. JavaScript has this:
const { a: b } = { a: 1 } // const b = 1
LikeLike
John Hardy : No it doesn’t. a[1] is not a symbol, but it can be a valid LHS. So can be (a ? b[1] : *c++).
LikeLike
Ok I meant an LHS expression needs to resolve to a location.
a || b doesn’t do that unambiguously. It could mean if a is not false then use a else use b or it could mean use the value which is the boolean OR of the value of a and the value of b
LikeLike
John Hardy: It’s not ambiguous beacuse your second proposition does not make sense in an lvalue context. The first one does.
LikeLike