DMD 0.177 release

Walter Bright newshound at digitalmars.com
Thu Dec 14 01:17:08 PST 2006


Andrei Alexandrescu (See Website For Email) wrote:
> I guess compiling internally two versions, one that returns S and one 
> that returns void, might be worth looking into. Because right now user 
> code for opAssign() can't be politically correct and efficient at the 
> same time.
> 
> 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.

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))




More information about the Digitalmars-d-announce mailing list