Copying and in-place methods [was: Why is array truth tied to .ptr?]

Leandro Lucarella llucax at gmail.com
Tue Dec 11 20:13:33 PST 2007


Robert DaSilva, el 11 de diciembre a las 19:26 me escribiste:
> > Maybe some syntactic sugar can be used too when using the dup version,
> > something like:
> > 
> > auto t = new T();
> > auto w = t.sort.dup(); // calls dupsort()
> 
> Don't you mean t.dup.sort().

No.

> t.sort.dup() would do a inplace sort and then duplicate it.
> (t.dup().sort and t.dup.sort() mean the *exact* same
> thing, the ending () are optional for *all* function that don't tack
> arguments.)

Ok, good catch, maybe that syntax is not right but you missed the big
picture (a compiler generated default implementation for a copying
function that can be overrideable).

If you now write t.sort.dup(), you are exactly doing that: duplicating t
and then sorting it (in-place I guess). If the implementor has a more
eficient way to use the copy while sorting, you miss that, or you have to
change the syntax (to t.dupsort() for example).

-- 
Leandro Lucarella (luca) | Blog colectivo: http://www.mazziblog.com.ar/blog/
----------------------------------------------------------------------------
GPG Key: 5F5A8D05 (F8CD F9A7 BF00 5431 4145  104C 949E BFB6 5F5A 8D05)
----------------------------------------------------------------------------
El discman vuelve locos a los controles, te lleva a cualquier lugar.
Ajústense pronto los cinturones, nos vamos a estrellar.
Evidentemente, no escuchaste el speech,
que dio la azafata, antes de despegar.



More information about the Digitalmars-d mailing list