Sorting a subrange

Per Nordlöw per.nordlow at gmail.com
Fri Nov 16 13:50:01 UTC 2018


On Friday, 16 November 2018 at 12:08:33 UTC, Stanislav Blinov 
wrote:
> import std.range.primitives : isRandomAccessRange;
>
> auto sortSubRange(R)(R range, size_t i, size_t j) if 
> (isRandomAccessRange!R) {
>     import std.algorithm.sorting : topN, partialSort;
>     size_t start = i;
>     if (i != 0) {
>         topN(range, i);
>         start++;
>     }
>     partialSort(range[start .. $], j-start);
>     return range[i .. j];
> }

Wonderful!


More information about the Digitalmars-d-learn mailing list