www.digitalmars.com         C & C++   DMDScript  

digitalmars.D - The copious = operator

reply "MrzlganeE" <bulletproofchest gmail.com> writes:
This  = is the .dup protocol

 = would copy, while the = is most usually a reference assign 
when that is possible.

If you have a regular method of clone which is a protocol for 
most all things who agree to use it, then = for assign by 
reference is more fair
Jun 01 2013
parent reply "MrzlganeE" <bulletproofchest gmail.com> writes:
This idea is pretty awful, because it works good for:

a  = b;

But it doesn't cover the cases where .dup is far more general:

T[] l = [ a.dup, b.dup, c ];

Modified by a stretch to macro cloning:

T[] l  = [ a, b, c ];       // all 3 of them clone. nuts for 
every reason you could come up with.

Yet, which "should" only parse properly to:

T[] l = [ a, b, c ].dup;    // even if 
expression-scope-auto-cloning was not crazy
Jun 01 2013
parent "MrzlganeE" <bulletproofchest gmail.com> writes:
I actually like the ability to clone all the elements of the 
slice being made.

If there's merit to this idea, or if it's terrible, I'd trust 
Walter and Andrei to know the real answer considering the 
implications. Hence why I did not make a proposal for this 
operator.
Jun 01 2013