Problems with sort
Andrei Alexandrescu
SeeWebsiteForEmail at erdani.org
Fri Dec 10 18:54:31 PST 2010
On 12/10/10 6:37 PM, Craig Black wrote:
> Thanks for the help guys. I implemented length and opIndex and now I get
> the following errors:
>
> C:\dmd2\windows\bin\..\..\src\phobos\std\algorithm.d(5341): Error:
> template std.algorithm.swap(T) if
> (!is(typeof(T.init.proxySwap(T.init)))) does not match any function
> template declaration
>
> C:\dmd2\windows\bin\..\..\src\phobos\std\algorithm.d(5341): Error:
> template std.algorithm.swap(T) if
> (!is(typeof(T.init.proxySwap(T.init)))) cannot deduce template function
> from argument types !()(_error_,Range)
>
> -Craig
This concerns a decision not yet firmed-up on whether objects should be
cheap to copy or not.
What happens is that sort wants to swap elements at given indices. Your
opIndex, I assume, returns by value. (If it returned by reference you'd
have no problem sorting.) Then sort makes a number of heroic attempts at
figuring out how to swap elements in your range (e.g. by trying
moveAt()) before failing in frustration.
If we mandate cheap copy, then swap via two copies should be fine, which
simplifies implementation a great deal and also your life as a user of
it. We haven't made that decision yet. There is the concern that things
would become too inefficient.
Andrei
More information about the Digitalmars-d
mailing list