1[/ 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) 5/] 6[section:stable_sort stable_sort] 7 8[heading Prototype] 9 10`` 11template<class RandomAccessRange> 12RandomAccessRange& stable_sort(RandomAccessRange& rng); 13 14template<class RandomAccessRange> 15const RandomAccessRange& stable_sort(const RandomAccessRange& rng); 16 17template<class RandomAccessRange, class BinaryPredicate> 18RandomAccessRange& stable_sort(RandomAccessRange& rng, BinaryPredicate pred); 19 20template<class RandomAccessRange, class BinaryPredicate> 21const RandomAccessRange& stable_sort(const RandomAccessRange& rng, BinaryPredicate pred); 22`` 23 24[heading Description] 25 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. 27 28For 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`. 29 30For 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`. 31 32[heading Definition] 33 34Defined in the header file `boost/range/algorithm/stable_sort.hpp` 35 36[heading Requirements] 37 38[*For versions of stable_sort without a predicate] 39 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. 44 45[*For versions of stable_sort with a predicate:] 46 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. 51 52[heading Complexity] 53 54Best case: `O(N)` where `N` is `distance(rng)`. 55Worst case: `O(N log(N)^2)` comparisons, where `N` is `distance(rng)`. 56 57[endsect] 58 59 60