Thread overview | ||||||
---|---|---|---|---|---|---|
|
December 15, 2006 opXxxAssign "return value" | ||||
---|---|---|---|---|
| ||||
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. |
December 15, 2006 Re: opXxxAssign "return value" | ||||
---|---|---|---|---|
| ||||
Posted in reply to Lionello Lunesu | Forget about the '*this'.. I was mixing C++ and D again :S L. |
December 15, 2006 Re: opXxxAssign "return value" | ||||
---|---|---|---|---|
| ||||
Posted in reply to Lionello Lunesu | Lionello Lunesu wrote:
> Forget about the '*this'.. I was mixing C++ and D again :S
For structs, it still needs to be *this.
Stewart.
|
December 18, 2006 Re: opXxxAssign "return value" | ||||
---|---|---|---|---|
| ||||
Posted in reply to Stewart Gordon | Stewart Gordon wrote:
> Lionello Lunesu wrote:
>> Forget about the '*this'.. I was mixing C++ and D again :S
>
> For structs, it still needs to be *this.
>
> Stewart.
I was referring to Walter's post, where he said that a opAssign for class C should return C (return this) and for a struct S it should return S* (also, return this). In C++ it would be S& (return *this).
L.
|
Copyright © 1999-2021 by the D Language Foundation