Functional Sort

"Nordlöw" via Digitalmars-d-learn digitalmars-d-learn at puremagic.com
Sat Nov 15 05:33:36 PST 2014


On Saturday, 15 November 2014 at 03:47:25 UTC, Steven 
Schveighoffer wrote:
> Note, there isn't any generic way to say "give me a copy of 
> this range, as the same type." array is probably the best you 
> will get. Just make sure you call it *before* you sort, unless 
> you want both ranges sorted :)
>
> -Steve

Does this mean that r.array is better than my current

auto sorted(R)(const R r) if (isInputRange!R &&
                               !(isArray!R))
{
     alias E = ElementType!R;
     import std.algorithm: sort, copy;
     auto s = new E[r.length]; // TODO length is probably not 
available here
     r.copy(s);
     s.sort;
     return s;
}

at https://github.com/nordlow/justd/blob/master/sort_ex.d#L117

?


More information about the Digitalmars-d-learn mailing list