std.algorithm sort() and reverse() confusion

FG via Digitalmars-d-learn digitalmars-d-learn at puremagic.com
Fri Jan 30 09:50:28 PST 2015


On 2015-01-30 at 18:42, FG wrote:
> But you may wonder what the design choice behind that was that reverse doesn't return the range itself while sort does (a SortedRange, specifically).

Although, after thinking about it, it makes sense. sort is used mostly to enforce that something is sorted in case it isn't already, so chaining it with other functions is reasonable, while in case of reverse you don't normally call it very often, it's cheaper to wrap the range in a retro range and iterate backwards when required, without touching the original.



More information about the Digitalmars-d-learn mailing list