DMD 0.177 release

Sean Kelly sean at f4.ca
Thu Dec 14 08:36:00 PST 2006


Kevin Bealer wrote:
 >
> == Quote from Andrei Alexandrescu (See Website For Email)
> (SeeWebsiteForEmail at erdani.org)'s article
>>
>> Here's a better alternative:
>> 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.
> 
> I wonder, are there cases where assignment should not return 'this'?

I've been thinking the same thing, and so far haven't been able to come 
up with an example where "correct" use of an assignment operator should 
not return 'this'.  I was considering suggestion the same thing as 
Andrei above, but was hoping someone would post a counterexample in the 
interim :-)  About the only weird thing with returning void and allowing 
this:

     a = b = c;

Is that it isn't equivalent to this:

     a.opAssign( b.opAssign( c ) );

Which may be a bit confusing.  But it does seem quite natural that the 
result of an assignment should always be the LHS of the assignment.


Sean



More information about the Digitalmars-d-announce mailing list