Add these to Phobos?

Mehrdad wfunction at hotmail.com
Mon Oct 15 18:29:17 PDT 2012


On Tuesday, 16 October 2012 at 00:42:55 UTC, Jonathan M Davis
wrote:
> 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));

Hmm, I didn't know 'sort' returns a value. That's very confusing
since now I have no idea if it's mutating or not. Python has both
sort and sorted, with clear meanings. (The goal was to make a
non-mutating version that I could call functional.) Maybe we
should clarify what sort exactly does and doesn't do...


More information about the Digitalmars-d mailing list