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_INPLACE_MERGE_HPP_INCLUDED
10 #define BOOST_RANGE_ALGORITHM_INPLACE_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 inplace_merge
24 ///
25 /// range-based version of the inplace_merge std algorithm
26 ///
27 /// \pre BidirectionalRange is a model of the BidirectionalRangeConcept
28 /// \pre BinaryPredicate is a model of the BinaryPredicateConcept
29 template<class BidirectionalRange>
inplace_merge(BidirectionalRange & rng,BOOST_DEDUCED_TYPENAME range_iterator<BidirectionalRange>::type middle)30 inline BidirectionalRange& inplace_merge(BidirectionalRange& rng,
31     BOOST_DEDUCED_TYPENAME range_iterator<BidirectionalRange>::type middle)
32 {
33     BOOST_RANGE_CONCEPT_ASSERT(( BidirectionalRangeConcept<BidirectionalRange> ));
34     std::inplace_merge(boost::begin(rng), middle, boost::end(rng));
35     return rng;
36 }
37 
38 /// \overload
39 template<class BidirectionalRange>
inplace_merge(const BidirectionalRange & rng,BOOST_DEDUCED_TYPENAME boost::range_iterator<const BidirectionalRange>::type middle)40 inline const BidirectionalRange& inplace_merge(const BidirectionalRange& rng,
41     BOOST_DEDUCED_TYPENAME boost::range_iterator<const BidirectionalRange>::type middle)
42 {
43     BOOST_RANGE_CONCEPT_ASSERT(( BidirectionalRangeConcept<const BidirectionalRange> ));
44     std::inplace_merge(boost::begin(rng), middle, boost::end(rng));
45     return rng;
46 }
47 
48 /// \overload
49 template<class BidirectionalRange, class BinaryPredicate>
inplace_merge(BidirectionalRange & rng,BOOST_DEDUCED_TYPENAME boost::range_iterator<BidirectionalRange>::type middle,BinaryPredicate pred)50 inline BidirectionalRange& inplace_merge(BidirectionalRange& rng,
51     BOOST_DEDUCED_TYPENAME boost::range_iterator<BidirectionalRange>::type middle,
52     BinaryPredicate pred)
53 {
54     BOOST_RANGE_CONCEPT_ASSERT(( BidirectionalRangeConcept<BidirectionalRange> ));
55     std::inplace_merge(boost::begin(rng), middle, boost::end(rng), pred);
56     return rng;
57 }
58 
59 /// \overload
60 template<class BidirectionalRange, class BinaryPredicate>
inplace_merge(const BidirectionalRange & rng,BOOST_DEDUCED_TYPENAME boost::range_iterator<const BidirectionalRange>::type middle,BinaryPredicate pred)61 inline const BidirectionalRange& inplace_merge(const BidirectionalRange& rng,
62     BOOST_DEDUCED_TYPENAME boost::range_iterator<const BidirectionalRange>::type middle,
63     BinaryPredicate pred)
64 {
65     BOOST_RANGE_CONCEPT_ASSERT(( BidirectionalRangeConcept<const BidirectionalRange> ));
66     std::inplace_merge(boost::begin(rng), middle, boost::end(rng), pred);
67     return rng;
68 }
69 
70     } // namespace range
71     using range::inplace_merge;
72 } // namespace boost
73 
74 #endif // include guard
75