Add these to Phobos?

Jonathan M Davis jmdavisProg at gmx.com
Mon Oct 15 17:42:43 PDT 2012


On Monday, October 15, 2012 23:35:59 Mehrdad wrote:
> auto sorted(alias F = q{a < b}, SwapStrategy S =
> SwapStrategy.unstable, R)(R range)
> {
> auto arr = range.array();
> arr.sort!(F, S)();
> return arr;
> }

What does this gain over sort? If you use sort

auto result = sort(range);

you get a SortedRange, which functions like find can take advantage of, and 
it's one line just like your sorted function. If you need a new array for it, 
then just call array.

auto result = sort(array(range));

I don't see what your proposed function buys you. Is it just that you want to 
operate on the sorted array rather than a SortedRange? In that case, it's just

auto arr = array(range);
sort(arr);

So, sorted would save you all of one line. Such a function seems incredibly 
lightweight to be adding it to the standard library.

- Jonathan M Davis


More information about the Digitalmars-d mailing list