2 Copyright 2010 Neil Groves
3 Distributed under the Boost Software License, Version 1.0.
4 (See accompanying file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
6 [section:stable_sort stable_sort]
11 template<class RandomAccessRange>
12 RandomAccessRange& stable_sort(RandomAccessRange& rng);
14 template<class RandomAccessRange>
15 const RandomAccessRange& stable_sort(const RandomAccessRange& rng);
17 template<class RandomAccessRange, class BinaryPredicate>
18 RandomAccessRange& stable_sort(RandomAccessRange& rng, BinaryPredicate pred);
20 template<class RandomAccessRange, class BinaryPredicate>
21 const RandomAccessRange& stable_sort(const RandomAccessRange& rng, BinaryPredicate pred);
26 `stable_sort` sorts the elements in `rng` into ascending order. `stable_sort` is guaranteed to be stable. The order is preserved for equivalent elements.
28 For versions of the `stable_sort` function without a predicate ascending order is defined by `operator<()` such that for all adjacent elements `[x,y]`, `y < x == false`.
30 For versions of the `stable_sort` function with a predicate, ascending order is designed by `pred` such that for all adjacent elements `[x,y]`, `pred(y,x) == false`.
34 Defined in the header file `boost/range/algorithm/stable_sort.hpp`
36 [heading Requirements]
38 [*For versions of stable_sort without a predicate]
40 * `RandomAccessRange` is a model of the __random_access_range__ Concept.
41 * `RandomAccessRange` is mutable.
42 * `RandomAccessRange`'s value type is a model of the `LessThanComparableConcept`.
43 * The ordering relation on `RandomAccessRange`'s value type is a [*strict weak ordering], as defined in the `LessThanComparableConcept` requirements.
45 [*For versions of stable_sort with a predicate:]
47 * `RandomAccessRange` is a model of the __random_access_range__ Concept.
48 * `RandomAccessRange` is mutable.
49 * `BinaryPredicate` is a model of the `StrictWeakOrderingConcept`.
50 * `RandomAccessRange`'s value type is convertible to both of `BinaryPredicate`'s argument types.
54 Best case: `O(N)` where `N` is `distance(rng)`.
55 Worst case: `O(N log(N)^2)` comparisons, where `N` is `distance(rng)`.