inplace_merge.hpp 2.5 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374
  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. #include <boost/concept_check.hpp>
  12. #include <boost/range/begin.hpp>
  13. #include <boost/range/end.hpp>
  14. #include <boost/range/concepts.hpp>
  15. #include <algorithm>
  16. namespace boost
  17. {
  18. namespace range
  19. {
  20. /// \brief template function inplace_merge
  21. ///
  22. /// range-based version of the inplace_merge std algorithm
  23. ///
  24. /// \pre BidirectionalRange is a model of the BidirectionalRangeConcept
  25. /// \pre BinaryPredicate is a model of the BinaryPredicateConcept
  26. template<class BidirectionalRange>
  27. inline BidirectionalRange& inplace_merge(BidirectionalRange& rng,
  28. BOOST_DEDUCED_TYPENAME range_iterator<BidirectionalRange>::type middle)
  29. {
  30. BOOST_RANGE_CONCEPT_ASSERT(( BidirectionalRangeConcept<BidirectionalRange> ));
  31. std::inplace_merge(boost::begin(rng), middle, boost::end(rng));
  32. return rng;
  33. }
  34. /// \overload
  35. template<class BidirectionalRange>
  36. inline const BidirectionalRange& inplace_merge(const BidirectionalRange& rng,
  37. BOOST_DEDUCED_TYPENAME boost::range_iterator<const BidirectionalRange>::type middle)
  38. {
  39. BOOST_RANGE_CONCEPT_ASSERT(( BidirectionalRangeConcept<const BidirectionalRange> ));
  40. std::inplace_merge(boost::begin(rng), middle, boost::end(rng));
  41. return rng;
  42. }
  43. /// \overload
  44. template<class BidirectionalRange, class BinaryPredicate>
  45. inline BidirectionalRange& inplace_merge(BidirectionalRange& rng,
  46. BOOST_DEDUCED_TYPENAME boost::range_iterator<BidirectionalRange>::type middle,
  47. BinaryPredicate pred)
  48. {
  49. BOOST_RANGE_CONCEPT_ASSERT(( BidirectionalRangeConcept<BidirectionalRange> ));
  50. std::inplace_merge(boost::begin(rng), middle, boost::end(rng), pred);
  51. return rng;
  52. }
  53. /// \overload
  54. template<class BidirectionalRange, class BinaryPredicate>
  55. inline const BidirectionalRange& inplace_merge(const BidirectionalRange& rng,
  56. BOOST_DEDUCED_TYPENAME boost::range_iterator<const BidirectionalRange>::type middle,
  57. BinaryPredicate pred)
  58. {
  59. BOOST_RANGE_CONCEPT_ASSERT(( BidirectionalRangeConcept<const BidirectionalRange> ));
  60. std::inplace_merge(boost::begin(rng), middle, boost::end(rng), pred);
  61. return rng;
  62. }
  63. } // namespace range
  64. using range::inplace_merge;
  65. } // namespace boost
  66. #endif // include guard