1 | // Boost.Range library |
---|
2 | // |
---|
3 | // Copyright Neil Groves 2009. |
---|
4 | // Copyright Thorsten Ottosen 2003-2004. Use, modification and |
---|
5 | // distribution is subject to the Boost Software License, Version |
---|
6 | // 1.0. (See accompanying file LICENSE_1_0.txt or copy at |
---|
7 | // http://www.boost.org/LICENSE_1_0.txt) |
---|
8 | // |
---|
9 | // For more information, see http://www.boost.org/libs/range/ |
---|
10 | // |
---|
11 | |
---|
12 | #ifndef BOOST_RANGE_SUB_RANGE_HPP |
---|
13 | #define BOOST_RANGE_SUB_RANGE_HPP |
---|
14 | |
---|
15 | #if BOOST_WORKAROUND(BOOST_MSVC, BOOST_TESTED_AT(1500)) |
---|
16 | #pragma warning( push ) |
---|
17 | #pragma warning( disable : 4996 ) |
---|
18 | #endif |
---|
19 | |
---|
20 | #include <boost/detail/workaround.hpp> |
---|
21 | #include <boost/range/config.hpp> |
---|
22 | #include <boost/range/iterator_range.hpp> |
---|
23 | #include <boost/range/value_type.hpp> |
---|
24 | #include <boost/range/size_type.hpp> |
---|
25 | #include <boost/range/difference_type.hpp> |
---|
26 | #include <boost/range/algorithm/equal.hpp> |
---|
27 | #include <boost/assert.hpp> |
---|
28 | #include <boost/type_traits/is_reference.hpp> |
---|
29 | #include <boost/type_traits/remove_reference.hpp> |
---|
30 | |
---|
31 | namespace boost |
---|
32 | { |
---|
33 | |
---|
34 | template< class ForwardRange > |
---|
35 | class sub_range : public iterator_range< BOOST_DEDUCED_TYPENAME range_iterator<ForwardRange>::type > |
---|
36 | { |
---|
37 | typedef BOOST_DEDUCED_TYPENAME range_iterator<ForwardRange>::type iterator_t; |
---|
38 | typedef iterator_range< iterator_t > base; |
---|
39 | |
---|
40 | typedef BOOST_DEDUCED_TYPENAME base::impl impl; |
---|
41 | public: |
---|
42 | typedef BOOST_DEDUCED_TYPENAME range_value<ForwardRange>::type value_type; |
---|
43 | typedef BOOST_DEDUCED_TYPENAME range_iterator<ForwardRange>::type iterator; |
---|
44 | typedef BOOST_DEDUCED_TYPENAME range_iterator<const ForwardRange>::type const_iterator; |
---|
45 | typedef BOOST_DEDUCED_TYPENAME range_difference<ForwardRange>::type difference_type; |
---|
46 | typedef BOOST_DEDUCED_TYPENAME range_size<ForwardRange>::type size_type; |
---|
47 | typedef BOOST_DEDUCED_TYPENAME base::reference reference; |
---|
48 | |
---|
49 | public: // for return value of front/back |
---|
50 | typedef BOOST_DEDUCED_TYPENAME |
---|
51 | boost::mpl::if_< boost::is_reference<reference>, |
---|
52 | const BOOST_DEDUCED_TYPENAME boost::remove_reference<reference>::type&, |
---|
53 | reference >::type const_reference; |
---|
54 | |
---|
55 | public: |
---|
56 | sub_range() : base() |
---|
57 | { } |
---|
58 | |
---|
59 | #if BOOST_WORKAROUND(BOOST_MSVC, BOOST_TESTED_AT(1500) ) |
---|
60 | sub_range( const sub_range& r ) |
---|
61 | : base( static_cast<const base&>( r ) ) |
---|
62 | { } |
---|
63 | #endif |
---|
64 | |
---|
65 | template< class ForwardRange2 > |
---|
66 | sub_range( ForwardRange2& r ) : |
---|
67 | |
---|
68 | #if BOOST_WORKAROUND(BOOST_INTEL_CXX_VERSION, <= 800 ) |
---|
69 | base( impl::adl_begin( r ), impl::adl_end( r ) ) |
---|
70 | #else |
---|
71 | base( r ) |
---|
72 | #endif |
---|
73 | { } |
---|
74 | |
---|
75 | template< class ForwardRange2 > |
---|
76 | sub_range( const ForwardRange2& r ) : |
---|
77 | |
---|
78 | #if BOOST_WORKAROUND(BOOST_INTEL_CXX_VERSION, <= 800 ) |
---|
79 | base( impl::adl_begin( r ), impl::adl_end( r ) ) |
---|
80 | #else |
---|
81 | base( r ) |
---|
82 | #endif |
---|
83 | { } |
---|
84 | |
---|
85 | template< class Iter > |
---|
86 | sub_range( Iter first, Iter last ) : |
---|
87 | base( first, last ) |
---|
88 | { } |
---|
89 | |
---|
90 | template< class ForwardRange2 > |
---|
91 | sub_range& operator=( ForwardRange2& r ) |
---|
92 | { |
---|
93 | base::operator=( r ); |
---|
94 | return *this; |
---|
95 | } |
---|
96 | |
---|
97 | template< class ForwardRange2 > |
---|
98 | sub_range& operator=( const ForwardRange2& r ) |
---|
99 | { |
---|
100 | base::operator=( r ); |
---|
101 | return *this; |
---|
102 | } |
---|
103 | |
---|
104 | sub_range& operator=( const sub_range& r ) |
---|
105 | { |
---|
106 | base::operator=( static_cast<const base&>(r) ); |
---|
107 | return *this; |
---|
108 | } |
---|
109 | |
---|
110 | public: |
---|
111 | |
---|
112 | iterator begin() { return base::begin(); } |
---|
113 | const_iterator begin() const { return base::begin(); } |
---|
114 | iterator end() { return base::end(); } |
---|
115 | const_iterator end() const { return base::end(); } |
---|
116 | difference_type size() const { return base::size(); } |
---|
117 | |
---|
118 | |
---|
119 | public: // convenience |
---|
120 | reference front() |
---|
121 | { |
---|
122 | return base::front(); |
---|
123 | } |
---|
124 | |
---|
125 | const_reference front() const |
---|
126 | { |
---|
127 | return base::front(); |
---|
128 | } |
---|
129 | |
---|
130 | reference back() |
---|
131 | { |
---|
132 | return base::back(); |
---|
133 | } |
---|
134 | |
---|
135 | const_reference back() const |
---|
136 | { |
---|
137 | return base::back(); |
---|
138 | } |
---|
139 | |
---|
140 | reference operator[]( difference_type sz ) |
---|
141 | { |
---|
142 | return base::operator[](sz); |
---|
143 | } |
---|
144 | |
---|
145 | const_reference operator[]( difference_type sz ) const |
---|
146 | { |
---|
147 | return base::operator[](sz); |
---|
148 | } |
---|
149 | |
---|
150 | }; |
---|
151 | |
---|
152 | template< class ForwardRange, class ForwardRange2 > |
---|
153 | inline bool operator==( const sub_range<ForwardRange>& l, |
---|
154 | const sub_range<ForwardRange2>& r ) |
---|
155 | { |
---|
156 | return boost::equal( l, r ); |
---|
157 | } |
---|
158 | |
---|
159 | template< class ForwardRange, class ForwardRange2 > |
---|
160 | inline bool operator!=( const sub_range<ForwardRange>& l, |
---|
161 | const sub_range<ForwardRange2>& r ) |
---|
162 | { |
---|
163 | return !boost::equal( l, r ); |
---|
164 | } |
---|
165 | |
---|
166 | template< class ForwardRange, class ForwardRange2 > |
---|
167 | inline bool operator<( const sub_range<ForwardRange>& l, |
---|
168 | const sub_range<ForwardRange2>& r ) |
---|
169 | { |
---|
170 | return iterator_range_detail::less_than( l, r ); |
---|
171 | } |
---|
172 | |
---|
173 | |
---|
174 | } // namespace 'boost' |
---|
175 | |
---|
176 | #if BOOST_WORKAROUND(BOOST_MSVC, BOOST_TESTED_AT(1500)) |
---|
177 | #pragma warning( pop ) |
---|
178 | #endif |
---|
179 | |
---|
180 | #endif |
---|
181 | |
---|