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_PARTITION_HPP_INCLUDED |
---|
10 | #define BOOST_RANGE_ALGORITHM_STABLE_PARTITION_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 <boost/range/detail/range_return.hpp> |
---|
17 | #include <algorithm> |
---|
18 | |
---|
19 | namespace boost |
---|
20 | { |
---|
21 | namespace range |
---|
22 | { |
---|
23 | |
---|
24 | /// \brief template function stable_partition |
---|
25 | /// |
---|
26 | /// range-based version of the stable_partition std algorithm |
---|
27 | /// |
---|
28 | /// \pre BidirectionalRange is a model of the BidirectionalRangeConcept |
---|
29 | /// \pre UnaryPredicate is a model of the UnaryPredicateConcept |
---|
30 | template<class BidirectionalRange, class UnaryPredicate> |
---|
31 | inline BOOST_DEDUCED_TYPENAME range_iterator<BidirectionalRange>::type |
---|
32 | stable_partition(BidirectionalRange& rng, UnaryPredicate pred) |
---|
33 | { |
---|
34 | BOOST_RANGE_CONCEPT_ASSERT(( BidirectionalRangeConcept<BidirectionalRange> )); |
---|
35 | return std::stable_partition(boost::begin(rng), boost::end(rng), pred); |
---|
36 | } |
---|
37 | |
---|
38 | /// \overload |
---|
39 | template<class BidirectionalRange, class UnaryPredicate> |
---|
40 | inline BOOST_DEDUCED_TYPENAME range_iterator<const BidirectionalRange>::type |
---|
41 | stable_partition(const BidirectionalRange& rng, UnaryPredicate pred) |
---|
42 | { |
---|
43 | BOOST_RANGE_CONCEPT_ASSERT(( BidirectionalRangeConcept<const BidirectionalRange> )); |
---|
44 | return std::stable_partition(boost::begin(rng),boost::end(rng),pred); |
---|
45 | } |
---|
46 | |
---|
47 | // range_return overloads |
---|
48 | template<range_return_value re, class BidirectionalRange, class UnaryPredicate> |
---|
49 | inline BOOST_DEDUCED_TYPENAME range_return<BidirectionalRange,re>::type |
---|
50 | stable_partition(BidirectionalRange& rng, UnaryPredicate pred) |
---|
51 | { |
---|
52 | BOOST_RANGE_CONCEPT_ASSERT(( BidirectionalRangeConcept<BidirectionalRange> )); |
---|
53 | return range_return<BidirectionalRange,re>::pack( |
---|
54 | std::stable_partition(boost::begin(rng), boost::end(rng), pred), |
---|
55 | rng); |
---|
56 | } |
---|
57 | |
---|
58 | /// \overload |
---|
59 | template<range_return_value re, class BidirectionalRange, class UnaryPredicate> |
---|
60 | inline BOOST_DEDUCED_TYPENAME range_return<const BidirectionalRange,re>::type |
---|
61 | stable_partition(const BidirectionalRange& rng, UnaryPredicate pred) |
---|
62 | { |
---|
63 | BOOST_RANGE_CONCEPT_ASSERT(( BidirectionalRangeConcept<const BidirectionalRange> )); |
---|
64 | return range_return<const BidirectionalRange,re>::pack( |
---|
65 | std::stable_partition(boost::begin(rng),boost::end(rng),pred), |
---|
66 | rng); |
---|
67 | } |
---|
68 | |
---|
69 | } // namespace range |
---|
70 | using range::stable_partition; |
---|
71 | } // namespace boost |
---|
72 | |
---|
73 | #endif // include guard |
---|