join.hpp 2.8 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091
  1. // Boost.Range library
  2. //
  3. // Copyright Neil Groves 2009. Use, modification and
  4. // distribution is subject to the Boost Software License, Version
  5. // 1.0. (See accompanying file LICENSE_1_0.txt or copy at
  6. // http://www.boost.org/LICENSE_1_0.txt)
  7. //
  8. //
  9. // For more information, see http://www.boost.org/libs/range/
  10. //
  11. #ifndef BOOST_RANGE_JOIN_HPP_INCLUDED
  12. #define BOOST_RANGE_JOIN_HPP_INCLUDED
  13. #include <boost/config.hpp>
  14. #include <boost/range/detail/join_iterator.hpp>
  15. #include <boost/range/concepts.hpp>
  16. #include <boost/range/iterator_range.hpp>
  17. namespace boost
  18. {
  19. namespace range_detail
  20. {
  21. template<class SinglePassRange1, class SinglePassRange2>
  22. class joined_type
  23. {
  24. public:
  25. typedef iterator_range<
  26. range_detail::join_iterator<
  27. BOOST_DEDUCED_TYPENAME range_iterator<SinglePassRange1>::type,
  28. BOOST_DEDUCED_TYPENAME range_iterator<SinglePassRange2>::type,
  29. BOOST_DEDUCED_TYPENAME range_value<SinglePassRange1>::type
  30. >
  31. > type;
  32. };
  33. } // namespace range_detail
  34. namespace range
  35. {
  36. template<class SinglePassRange1, class SinglePassRange2>
  37. class joined_range
  38. : public range_detail::joined_type<SinglePassRange1, SinglePassRange2>::type
  39. {
  40. typedef range_detail::join_iterator<
  41. BOOST_DEDUCED_TYPENAME range_iterator<SinglePassRange1>::type,
  42. BOOST_DEDUCED_TYPENAME range_iterator<SinglePassRange2>::type,
  43. BOOST_DEDUCED_TYPENAME range_value<SinglePassRange1>::type
  44. > iterator_t;
  45. typedef BOOST_DEDUCED_TYPENAME range_detail::joined_type<
  46. SinglePassRange1, SinglePassRange2>::type base_t;
  47. public:
  48. joined_range(SinglePassRange1& rng1, SinglePassRange2& rng2)
  49. : base_t(
  50. iterator_t(rng1, rng2, range_detail::join_iterator_begin_tag()),
  51. iterator_t(rng1, rng2, range_detail::join_iterator_end_tag())
  52. )
  53. {
  54. }
  55. };
  56. template<class SinglePassRange1, class SinglePassRange2>
  57. joined_range<const SinglePassRange1, const SinglePassRange2>
  58. join(const SinglePassRange1& r1, const SinglePassRange2& r2)
  59. {
  60. BOOST_RANGE_CONCEPT_ASSERT(( SinglePassRangeConcept<SinglePassRange1> ));
  61. BOOST_RANGE_CONCEPT_ASSERT(( SinglePassRangeConcept<SinglePassRange2> ));
  62. return joined_range<const SinglePassRange1, const SinglePassRange2>(r1, r2);
  63. }
  64. template<class SinglePassRange1, class SinglePassRange2>
  65. joined_range<SinglePassRange1, SinglePassRange2>
  66. join(SinglePassRange1& r1, SinglePassRange2& r2)
  67. {
  68. BOOST_RANGE_CONCEPT_ASSERT(( SinglePassRangeConcept<SinglePassRange1> ));
  69. BOOST_RANGE_CONCEPT_ASSERT(( SinglePassRangeConcept<SinglePassRange2> ));
  70. return joined_range<SinglePassRange1, SinglePassRange2>(r1, r2);
  71. }
  72. } // namespace range
  73. using ::boost::range::joined_range;
  74. using ::boost::range::join;
  75. } // namespace boost
  76. #endif // include guard