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
14 #include <boost/config.hpp>
15 #include <boost/range/detail/join_iterator.hpp>
16 #include <boost/range/concepts.hpp>
17 #include <boost/range/iterator_range.hpp>
18
19 namespace boost
20 {
21 namespace range_detail
22 {
23
24 template<class SinglePassRange1, class SinglePassRange2>
25 class joined_type
26 {
27 public:
28 typedef iterator_range<
29 range_detail::join_iterator<
30 BOOST_DEDUCED_TYPENAME range_iterator<SinglePassRange1>::type,
31 BOOST_DEDUCED_TYPENAME range_iterator<SinglePassRange2>::type,
32 BOOST_DEDUCED_TYPENAME range_value<SinglePassRange1>::type
33 >
34 > type;
35 };
36
37 } // namespace range_detail
38
39 namespace range
40 {
41
42 template<class SinglePassRange1, class SinglePassRange2>
43 class joined_range
44 : public range_detail::joined_type<SinglePassRange1, SinglePassRange2>::type
45 {
46 typedef range_detail::join_iterator<
47 BOOST_DEDUCED_TYPENAME range_iterator<SinglePassRange1>::type,
48 BOOST_DEDUCED_TYPENAME range_iterator<SinglePassRange2>::type,
49 BOOST_DEDUCED_TYPENAME range_value<SinglePassRange1>::type
50 > iterator_t;
51
52 typedef BOOST_DEDUCED_TYPENAME range_detail::joined_type<
53 SinglePassRange1, SinglePassRange2>::type base_t;
54 public:
joined_range(SinglePassRange1 & rng1,SinglePassRange2 & rng2)55 joined_range(SinglePassRange1& rng1, SinglePassRange2& rng2)
56 : base_t(
57 iterator_t(rng1, rng2, range_detail::join_iterator_begin_tag()),
58 iterator_t(rng1, rng2, range_detail::join_iterator_end_tag())
59 )
60 {
61 }
62 };
63
64 template<class SinglePassRange1, class SinglePassRange2>
65 joined_range<const SinglePassRange1, const SinglePassRange2>
join(const SinglePassRange1 & r1,const SinglePassRange2 & r2)66 join(const SinglePassRange1& r1, const SinglePassRange2& r2)
67 {
68 BOOST_RANGE_CONCEPT_ASSERT(( SinglePassRangeConcept<SinglePassRange1> ));
69 BOOST_RANGE_CONCEPT_ASSERT(( SinglePassRangeConcept<SinglePassRange2> ));
70
71 return joined_range<const SinglePassRange1, const SinglePassRange2>(r1, r2);
72 }
73
74 template<class SinglePassRange1, class SinglePassRange2>
75 joined_range<SinglePassRange1, SinglePassRange2>
join(SinglePassRange1 & r1,SinglePassRange2 & r2)76 join(SinglePassRange1& r1, SinglePassRange2& r2)
77 {
78 BOOST_RANGE_CONCEPT_ASSERT(( SinglePassRangeConcept<SinglePassRange1> ));
79 BOOST_RANGE_CONCEPT_ASSERT(( SinglePassRangeConcept<SinglePassRange2> ));
80
81 return joined_range<SinglePassRange1, SinglePassRange2>(r1, r2);
82 }
83
84 } // namespace range
85
86 using ::boost::range::joined_range;
87 using ::boost::range::join;
88
89 } // namespace boost
90
91 #endif // include guard
92