digitalmars.D - opXxxAssign "return value"
- Lionello Lunesu (14/14) Dec 15 2006 I've been following the discussion in D.announce but have lost track of
- Lionello Lunesu (2/2) Dec 15 2006 Forget about the '*this'.. I was mixing C++ and D again :S
- Stewart Gordon (3/4) Dec 15 2006 For structs, it still needs to be *this.
- Lionello Lunesu (5/11) Dec 17 2006 I was referring to Walter's post, where he said that a opAssign for
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.
Dec 15 2006
Forget about the '*this'.. I was mixing C++ and D again :S L.
Dec 15 2006
Lionello Lunesu wrote:Forget about the '*this'.. I was mixing C++ and D again :SFor structs, it still needs to be *this. Stewart.
Dec 15 2006
Stewart Gordon wrote:Lionello Lunesu wrote: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.Forget about the '*this'.. I was mixing C++ and D again :SFor structs, it still needs to be *this. Stewart.
Dec 17 2006