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_PARTIAL_SORT_COPY_HPP_INCLUDED |
10 | #define BOOST_RANGE_ALGORITHM_PARTIAL_SORT_COPY_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/value_type.hpp> |
17 | #include <algorithm> |
18 | |
19 | namespace boost |
20 | { |
21 | namespace range |
22 | { |
23 | |
24 | /// \brief template function partial_sort_copy |
25 | /// |
26 | /// range-based version of the partial_sort_copy std algorithm |
27 | /// |
28 | /// \pre SinglePassRange is a model of the SinglePassRangeConcept |
29 | /// \pre RandomAccessRange is a model of the Mutable_RandomAccessRangeConcept |
30 | /// \pre BinaryPredicate is a model of the BinaryPredicateConcept |
31 | template<class SinglePassRange, class RandomAccessRange> |
32 | inline BOOST_DEDUCED_TYPENAME range_iterator<RandomAccessRange>::type |
33 | partial_sort_copy(const SinglePassRange& rng1, RandomAccessRange& rng2) |
34 | { |
35 | BOOST_RANGE_CONCEPT_ASSERT((SinglePassRangeConcept<const SinglePassRange>)); |
36 | |
37 | return std::partial_sort_copy(boost::begin(rng1), boost::end(rng1), |
38 | boost::begin(rng2), boost::end(rng2)); |
39 | } |
40 | |
41 | /// \overload |
42 | template<class SinglePassRange, class RandomAccessRange> |
43 | inline BOOST_DEDUCED_TYPENAME range_iterator<RandomAccessRange>::type |
44 | partial_sort_copy(const SinglePassRange& rng1, const RandomAccessRange& rng2) |
45 | { |
46 | BOOST_RANGE_CONCEPT_ASSERT((SinglePassRangeConcept<const SinglePassRange>)); |
47 | |
48 | return std::partial_sort_copy(boost::begin(rng1), boost::end(rng1), |
49 | boost::begin(rng2), boost::end(rng2)); |
50 | } |
51 | |
52 | /// \overload |
53 | template<class SinglePassRange, class RandomAccessRange, |
54 | class BinaryPredicate> |
55 | inline BOOST_DEDUCED_TYPENAME range_iterator<RandomAccessRange>::type |
56 | partial_sort_copy(const SinglePassRange& rng1, RandomAccessRange& rng2, |
57 | BinaryPredicate pred) |
58 | { |
59 | BOOST_RANGE_CONCEPT_ASSERT((SinglePassRangeConcept<const SinglePassRange>)); |
60 | |
61 | return std::partial_sort_copy(boost::begin(rng1), boost::end(rng1), |
62 | boost::begin(rng2), boost::end(rng2), pred); |
63 | } |
64 | |
65 | /// \overload |
66 | template<class SinglePassRange, class RandomAccessRange, |
67 | class BinaryPredicate> |
68 | inline BOOST_DEDUCED_TYPENAME range_iterator<const RandomAccessRange>::type |
69 | partial_sort_copy(const SinglePassRange& rng1, const RandomAccessRange& rng2, |
70 | BinaryPredicate pred) |
71 | { |
72 | BOOST_RANGE_CONCEPT_ASSERT((SinglePassRangeConcept<const SinglePassRange>)); |
73 | |
74 | return std::partial_sort_copy(boost::begin(rng1), boost::end(rng1), |
75 | boost::begin(rng2), boost::end(rng2), pred); |
76 | } |
77 | |
78 | } // namespace range |
79 | using range::partial_sort_copy; |
80 | } // namespace boost |
81 | |
82 | #endif // include guard |
83 | |