DMD 0.177 release
Andrei Alexandrescu (See Website for Email)
SeeWebsiteForEmail at erdani.org
Thu Dec 14 17:06:59 PST 2006
Walter Bright wrote:
> Andrei Alexandrescu (See Website For Email) wrote:
>> Require opAssign() to always return void and have the compiler return
>> a reference to the left-hand side. That is, transform:
>>
>> a = b;
>>
>> into:
>>
>> (a.opAssign(b), a);
>>
>> with the mention that a only gets evaluated once.
>>
>> This way assignment _always_ returns its left-hand side and user code
>> cannot subvert that behavior. Also the code will be efficient because
>> no more spurious copies are being made.
>
> It is possible to force the return type of opAssign. But I'd suggest
> making it an S*, with the rewrite to:
>
> *(a.opAssign(b))
Makes sense, but then I keep on racking my brain to ever think of any
C++ code that ever return something else than *this. Never saw any,
never wrote any - ever.
So I just conclude that customizing =, +=, -= etc. is a good thing, but
customizing their return type and value is not. Adding the silly "return
this;" litany at the end of every single operator is not something for a
language that wants to do things the right way. The speed will be
better, too. It's kind of annoying to know that I can't write:
a = b;
and simply have the compiler do what it takes and no more. Every of
those spurious copies is just some more discomfort I have to put in.
Andrei
More information about the Digitalmars-d-announce
mailing list