Files
2025-10-25 03:02:53 +03:00

5.0 KiB

[sort]

26 Algorithms library [algorithms]

26.8.2 Sorting [alg.sort]

26.8.2.1 sort [sort]

🔗

`template constexpr void sort(RandomAccessIterator first, RandomAccessIterator last); template<class ExecutionPolicy, class RandomAccessIterator> void sort(ExecutionPolicy&& exec, RandomAccessIterator first, RandomAccessIterator last);

template<class RandomAccessIterator, class Compare> constexpr void sort(RandomAccessIterator first, RandomAccessIterator last, Compare comp); template<class ExecutionPolicy, class RandomAccessIterator, class Compare> void sort(ExecutionPolicy&& exec, RandomAccessIterator first, 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::sort(I first, S last, Comp comp = {}, Proj proj = {}); template<random_access_range R, class Comp = ranges::less, class Proj = identity> requires sortable<iterator_t, Comp, Proj> constexpr borrowed_iterator_t ranges::sort(R&& r, 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::sort(Ep&& exec, I first, S last, Comp comp = {}, Proj proj = {}); template<execution-policy Ep, sized-random-access-range R, class Comp = ranges::less, class Proj = identity> requires sortable<iterator_t, Comp, Proj> borrowed_iterator_t ranges::sort(Ep&& exec, R&& r, Comp comp = {}, Proj proj = {}); `

1

#

Let comp be less{} and proj be identity{} for the overloads with no parameters by those names.

2

#

Preconditions: 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.

3

#

Effects: Sorts the elements in the range [first, last) with respect to comp and proj.

4

#

Returns: last for the overloads in namespace ranges.

5

#

Complexity: Let N be last - first.

O(NlogN) comparisons and projections.