.sort vs sort(): std.algorithm not up to the task?

Andrew Edwards via Digitalmars-d-learn digitalmars-d-learn at puremagic.com
Wed Jun 7 21:34:29 PDT 2017


On Thursday, 8 June 2017 at 04:15:12 UTC, Stanislav Blinov wrote:
>
> Earns you nothing? How about not performing an allocation and 
> copy?

Seen through the eyes of a complete beginner, this means 
absolutely nothing. Those are the eyes I am using as I'm reading 
a book and simply following the instructions provided. I took 
care of the problem with the first thing that came to mind, 
because that all that's required.

> aa.keys.sort().release;

somehow, I missed the point that actually came as a byproduct of 
importing sort. When I tried it in the original code it 
"ostensibly" did not work because, i recompiled the edited 
version posed here.

> No need to import anything but std.algorithm : sort.
>
>> But it doesn't, it decides what i'm gonna get like it or not. 
>> But the fact, a lot of times I just want to work with the 
>> underlying data after the operation is performed. And it 
>> should be noted that this applies to Ranges in general not 
>> just sort.
>
> A crucial point of any good design is to *not rob the caller of 
> useful information*. sort() follows that philosophy. If you 
> don't need the extra information, you're free to get rid of it. 
> The other way around that you seem to be proposing would 
> require having a ton of overloads for sort() for any imaginable 
> use case.

No I'm not proposing that at all, if the predicate is initialized 
such that it functions the exact same way it does now, then only 
in instances where necessary would the user need to specify 
anything. Anyway, the functionality I'm asking for is the one 
forded by release so i'm satisfied.

Thank you.


More information about the Digitalmars-d-learn mailing list