11 Algorithms library [algorithms]

11.5 Sorting and related operations [alg.sorting]

11.5.1 Sorting [alg.sort]

11.5.1.3 partial_sort [partial.sort]

template <RandomAccessIterator I, Sentinel<I> S, class Comp = less<>, class Proj = identity> requires Sortable<I, Comp, Proj> I partial_sort(I first, I middle, S last, Comp comp = Comp{}, Proj proj = Proj{}); template <RandomAccessRange Rng, class Comp = less<>, class Proj = identity> requires Sortable<iterator_t<Rng>, Comp, Proj> safe_iterator_t<Rng> partial_sort(Rng&& rng, iterator_t<Rng> middle, Comp comp = Comp{}, Proj proj = Proj{});

Effects: Places the first middle - first sorted elements from the range [first,last) into the range [first,middle). The rest of the elements in the range [middle,last) are placed in an unspecified order.

Returns: last.

Complexity: It takes approximately (last - first) * log(middle - first) comparisons, and exactly twice as many applications of the projection.