merge.hpp 2.2 KB

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