6.3 KiB
[partial.sort]
26 Algorithms library [algorithms]
26.8 Sorting and related operations [alg.sorting]
26.8.2 Sorting [alg.sort]
26.8.2.3 partial_sort [partial.sort]
`template constexpr void partial_sort(RandomAccessIterator first, RandomAccessIterator middle, RandomAccessIterator last); template<class ExecutionPolicy, class RandomAccessIterator> void partial_sort(ExecutionPolicy&& exec, RandomAccessIterator first, RandomAccessIterator middle, RandomAccessIterator last);
template<class RandomAccessIterator, class Compare> constexpr void partial_sort(RandomAccessIterator first, RandomAccessIterator middle, RandomAccessIterator last, Compare comp); template<class ExecutionPolicy, class RandomAccessIterator, class Compare> void partial_sort(ExecutionPolicy&& exec, RandomAccessIterator first, RandomAccessIterator middle, RandomAccessIterator last, Compare comp);
template<random_access_iterator I, sentinel_for S, class Comp = ranges::less, class Proj = identity> requires sortable<I, Comp, Proj> constexpr I ranges::partial_sort(I first, I middle, S last, Comp comp = {}, Proj proj = {}); template<execution-policy Ep, random_access_iterator I, sized_sentinel_for S, class Comp = ranges::less, class Proj = identity> requires sortable<I, Comp, Proj> I ranges::partial_sort(Ep&& exec, I first, I middle, S last, Comp comp = {}, Proj proj = {}); `
Let comp be less{} and proj be identity{} for the overloads with no parameters by those names.
Preconditions: [first, middle) and [middle, last) are valid ranges.
For the overloads in namespace std,RandomAccessIterator meets the Cpp17ValueSwappable requirements ([swappable.requirements]) and the type of *first meets the Cpp17MoveConstructible (Table 31) andCpp17MoveAssignable (Table 33) requirements.
Effects: Places the first middle - first elements from the range [first, last) as sorted with respect to comp and proj into the range [first, middle).
The rest of the elements in the range [middle, last) are placed in an unspecified order.
Returns: last for the overload in namespace ranges.
Complexity: Approximately (last - first) * log(middle - first) comparisons, and twice as many projections.
template<[random_access_range](range.refinements#concept:random_access_range "25.4.6 Other range refinements [range.refinements]") R, class Comp = ranges::less, class Proj = identity> requires [sortable](alg.req.sortable#concept:sortable "24.3.7.8 Concept sortable [alg.req.sortable]")<iterator_t<R>, Comp, Proj> constexpr borrowed_iterator_t<R> ranges::partial_sort(R&& r, iterator_t<R> middle, Comp comp = {}, Proj proj = {});
Effects: Equivalent to:return ranges::partial_sort(ranges::begin(r), middle, ranges::end(r), comp, proj);
template<[execution-policy](algorithms.parallel.defns#concept:execution-policy "26.3.1 Preamble [algorithms.parallel.defns]") Ep, [sized-random-access-range](range.refinements#concept:sized-random-access-range "25.4.6 Other range refinements [range.refinements]") R, class Comp = ranges::less, class Proj = identity> requires [sortable](alg.req.sortable#concept:sortable "24.3.7.8 Concept sortable [alg.req.sortable]")<iterator_t<R>, Comp, Proj> borrowed_iterator_t<R> ranges::partial_sort(Ep&& exec, R&& r, iterator_t<R> middle, Comp comp = {}, Proj proj = {});
Effects: Equivalent to:return ranges::partial_sort(std::forward(exec), ranges::begin(r), middle, ranges::end(r), comp, proj);