11 Algorithms library [algorithms]

11.5 Sorting and related operations [alg.sorting]

11.5.1 Sorting [alg.sort]

11.5.1.2 stable_sort [stable.sort]

template <RandomAccessIterator I, Sentinel<I> S, class Comp = less<>, class Proj = identity> requires Sortable<I, Comp, Proj> I stable_sort(I first, 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> stable_sort(Rng&& rng, Comp comp = Comp{}, Proj proj = Proj{});

Effects: Sorts the elements in the range [first,last).

Returns: last.

Complexity: Let N == last - first. If enough extra memory is available, N log(N) comparisons. Otherwise, at most N log2(N) comparisons. In either case, twice as many applications of the projection as the number of comparisons.

Remarks: Stable ( ISO/IEC 14882:2014 §[algorithm.stable]).