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_MERGE_HPP_INCLUDED |
---|
10 | #define BOOST_RANGE_ALGORITHM_MERGE_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 merge |
---|
24 | /// |
---|
25 | /// range-based version of the merge std algorithm |
---|
26 | /// |
---|
27 | /// \pre SinglePassRange1 is a model of the SinglePassRangeConcept |
---|
28 | /// \pre SinglePassRange2 is a model of the SinglePassRangeConcept |
---|
29 | /// \pre BinaryPredicate is a model of the BinaryPredicateConcept |
---|
30 | /// |
---|
31 | template<class SinglePassRange1, class SinglePassRange2, |
---|
32 | class OutputIterator> |
---|
33 | inline OutputIterator merge(const SinglePassRange1& rng1, |
---|
34 | const SinglePassRange2& rng2, |
---|
35 | OutputIterator out) |
---|
36 | { |
---|
37 | BOOST_RANGE_CONCEPT_ASSERT(( SinglePassRangeConcept<const SinglePassRange1> )); |
---|
38 | BOOST_RANGE_CONCEPT_ASSERT(( SinglePassRangeConcept<const SinglePassRange2> )); |
---|
39 | return std::merge(boost::begin(rng1), boost::end(rng1), |
---|
40 | boost::begin(rng2), boost::end(rng2), out); |
---|
41 | } |
---|
42 | |
---|
43 | /// \overload |
---|
44 | template<class SinglePassRange1, class SinglePassRange2, |
---|
45 | class OutputIterator, class BinaryPredicate> |
---|
46 | inline OutputIterator merge(const SinglePassRange1& rng1, |
---|
47 | const SinglePassRange2& rng2, |
---|
48 | OutputIterator out, |
---|
49 | BinaryPredicate pred) |
---|
50 | { |
---|
51 | BOOST_RANGE_CONCEPT_ASSERT(( SinglePassRangeConcept<const SinglePassRange1> )); |
---|
52 | BOOST_RANGE_CONCEPT_ASSERT(( SinglePassRangeConcept<const SinglePassRange2> )); |
---|
53 | return std::merge(boost::begin(rng1), boost::end(rng1), |
---|
54 | boost::begin(rng2), boost::end(rng2), out, pred); |
---|
55 | } |
---|
56 | |
---|
57 | } // namespace range |
---|
58 | using range::merge; |
---|
59 | } // namespace boost |
---|
60 | |
---|
61 | #endif // include guard |
---|