1 //  Copyright Neil Groves 2009. Use, modification and
2 //  distribution is subject to the Boost Software License, Version
3 //  1.0. (See accompanying file LICENSE_1_0.txt or copy at
4 //  http://www.boost.org/LICENSE_1_0.txt)
5 //
6 //
7 // For more information, see http://www.boost.org/libs/range/
8 //
9 #ifndef BOOST_RANGE_ALGORITHM_STABLE_SORT_HPP_INCLUDED
10 #define BOOST_RANGE_ALGORITHM_STABLE_SORT_HPP_INCLUDED
11 
12 #include <boost/concept_check.hpp>
13 #include <boost/range/begin.hpp>
14 #include <boost/range/end.hpp>
15 #include <boost/range/concepts.hpp>
16 #include <algorithm>
17 
18 namespace boost
19 {
20     namespace range
21     {
22 
23 /// \brief template function stable_sort
24 ///
25 /// range-based version of the stable_sort std algorithm
26 ///
27 /// \pre RandomAccessRange is a model of the RandomAccessRangeConcept
28 /// \pre BinaryPredicate is a model of the BinaryPredicateConcept
29 template<class RandomAccessRange>
stable_sort(RandomAccessRange & rng)30 inline RandomAccessRange& stable_sort(RandomAccessRange& rng)
31 {
32     BOOST_RANGE_CONCEPT_ASSERT(( RandomAccessRangeConcept<RandomAccessRange> ));
33     std::stable_sort(boost::begin(rng), boost::end(rng));
34     return rng;
35 }
36 
37 /// \overload
38 template<class RandomAccessRange>
stable_sort(const RandomAccessRange & rng)39 inline const RandomAccessRange& stable_sort(const RandomAccessRange& rng)
40 {
41     BOOST_RANGE_CONCEPT_ASSERT(( RandomAccessRangeConcept<const RandomAccessRange> ));
42     std::stable_sort(boost::begin(rng), boost::end(rng));
43     return rng;
44 }
45 
46 /// \overload
47 template<class RandomAccessRange, class BinaryPredicate>
stable_sort(RandomAccessRange & rng,BinaryPredicate sort_pred)48 inline RandomAccessRange& stable_sort(RandomAccessRange& rng, BinaryPredicate sort_pred)
49 {
50     BOOST_RANGE_CONCEPT_ASSERT(( RandomAccessRangeConcept<RandomAccessRange> ));
51     std::stable_sort(boost::begin(rng), boost::end(rng), sort_pred);
52     return rng;
53 }
54 
55 /// \overload
56 template<class RandomAccessRange, class BinaryPredicate>
stable_sort(const RandomAccessRange & rng,BinaryPredicate sort_pred)57 inline const RandomAccessRange& stable_sort(const RandomAccessRange& rng, BinaryPredicate sort_pred)
58 {
59     BOOST_RANGE_CONCEPT_ASSERT(( RandomAccessRangeConcept<const RandomAccessRange> ));
60     std::stable_sort(boost::begin(rng), boost::end(rng), sort_pred);
61     return rng;
62 }
63 
64     } // namespace range
65     using range::stable_sort;
66 } // namespace boost
67 
68 #endif // include guard
69