opXxxAssign "return value"
Lionello Lunesu
lio at lunesu.remove.com
Fri Dec 15 05:25:52 PST 2006
I've been following the discussion in D.announce but have lost track of
the sub-thread :S
Anyway, in the end, I'd have to agree with Andrei. I think opAssign (and
opMulAssign, etc) should return "void". The compiler can still implement
a=b as (a.opAssign(b),a), like Andrei suggested.
The reason this would work, is that 'this' (and '*this') are not
actually return values of the op-function. The caller already has the
value and simply makes it available to other calls.
This way, the compiler can select the most efficient implementation:
this, *this for classes, structs resp. and the implementer no longer has
to write "return this" (or worse, something else!). No hidden copy that
is (or not) optimized away. In fact, like I said, no return value, since
the caller already has it.
L.
More information about the Digitalmars-d
mailing list