Copying and in-place methods [was: Why is array truth tied to .ptr?]
Robert DaSilva
sp.unit.262+digitalmars at gmail.com
Tue Dec 11 21:31:32 PST 2007
Leandro Lucarella wrote:
> 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).
>
I'm just saying that t.sort.dup() can *only* mean sort t then duplicate
what sort returns (an error as sort returns void); unless sort is a
struck that overloads opCall, but it's not.
More information about the Digitalmars-d
mailing list