comparison DEPENDENCIES/generic/include/boost/range/sub_range.hpp @ 101:c530137014c0

Update Boost headers (1.58.0)
author Chris Cannam
date Mon, 07 Sep 2015 11:12:49 +0100
parents 2665513ce2d3
children
comparison
equal deleted inserted replaced
100:793467b5e61c 101:c530137014c0
22 #include <boost/range/config.hpp> 22 #include <boost/range/config.hpp>
23 #include <boost/range/iterator_range.hpp> 23 #include <boost/range/iterator_range.hpp>
24 #include <boost/range/value_type.hpp> 24 #include <boost/range/value_type.hpp>
25 #include <boost/range/size_type.hpp> 25 #include <boost/range/size_type.hpp>
26 #include <boost/range/difference_type.hpp> 26 #include <boost/range/difference_type.hpp>
27 #include <boost/range/reference.hpp>
27 #include <boost/range/algorithm/equal.hpp> 28 #include <boost/range/algorithm/equal.hpp>
28 #include <boost/assert.hpp> 29 #include <boost/assert.hpp>
29 #include <boost/type_traits/is_reference.hpp> 30 #include <boost/type_traits/is_reference.hpp>
30 #include <boost/type_traits/remove_reference.hpp> 31 #include <boost/type_traits/remove_reference.hpp>
31 32
32 namespace boost 33 namespace boost
33 { 34 {
34 35 namespace range_detail
35 template< class ForwardRange > 36 {
36 class sub_range : public iterator_range< BOOST_DEDUCED_TYPENAME range_iterator<ForwardRange>::type > 37
37 { 38 template<class ForwardRange, class TraversalTag>
38 typedef BOOST_DEDUCED_TYPENAME range_iterator<ForwardRange>::type iterator_t; 39 class sub_range_base
39 typedef iterator_range< iterator_t > base; 40 : public iterator_range<
41 BOOST_DEDUCED_TYPENAME range_iterator<ForwardRange>::type
42 >
43 {
44 typedef iterator_range<
45 BOOST_DEDUCED_TYPENAME range_iterator<ForwardRange>::type
46 > base;
47
48 protected:
49 typedef BOOST_DEDUCED_TYPENAME base::iterator_range_ iterator_range_;
50
51 public:
52 typedef BOOST_DEDUCED_TYPENAME range_value<ForwardRange>::type value_type;
53 typedef BOOST_DEDUCED_TYPENAME range_iterator<ForwardRange>::type iterator;
54 typedef BOOST_DEDUCED_TYPENAME range_iterator<const ForwardRange>::type const_iterator;
55 typedef BOOST_DEDUCED_TYPENAME range_difference<ForwardRange>::type difference_type;
56 typedef BOOST_DEDUCED_TYPENAME range_size<ForwardRange>::type size_type;
57 typedef BOOST_DEDUCED_TYPENAME range_reference<ForwardRange>::type reference;
58 typedef BOOST_DEDUCED_TYPENAME range_reference<const ForwardRange>::type const_reference;
59
60 sub_range_base()
61 {
62 }
63
64 template<class Iterator>
65 sub_range_base(Iterator first, Iterator last)
66 : base(first, last)
67 {
68 }
69
70 reference front()
71 {
72 return base::front();
73 }
74
75 const_reference front() const
76 {
77 return base::front();
78 }
79 };
80
81 template<class ForwardRange>
82 class sub_range_base<ForwardRange, bidirectional_traversal_tag>
83 : public sub_range_base<ForwardRange, forward_traversal_tag>
84 {
85 typedef sub_range_base<ForwardRange, forward_traversal_tag> base;
86 public:
87 sub_range_base()
88 {
89 }
90
91 template<class Iterator>
92 sub_range_base(Iterator first, Iterator last)
93 : base(first, last)
94 {
95 }
96
97 BOOST_DEDUCED_TYPENAME base::reference back()
98 {
99 return base::back();
100 }
101
102 BOOST_DEDUCED_TYPENAME base::const_reference back() const
103 {
104 return base::back();
105 }
106 };
107
108 template<class ForwardRange>
109 class sub_range_base<ForwardRange, random_access_traversal_tag>
110 : public sub_range_base<ForwardRange, bidirectional_traversal_tag>
111 {
112 typedef sub_range_base<ForwardRange, bidirectional_traversal_tag> base;
113
114 public:
115 sub_range_base()
116 {
117 }
118
119 template<class Iterator>
120 sub_range_base(Iterator first, Iterator last)
121 : base(first, last)
122 {
123 }
124
125 BOOST_DEDUCED_TYPENAME base::reference
126 operator[](BOOST_DEDUCED_TYPENAME base::difference_type n)
127 {
128 return this->begin()[n];
129 }
130
131 BOOST_DEDUCED_TYPENAME base::const_reference
132 operator[](BOOST_DEDUCED_TYPENAME base::difference_type n) const
133 {
134 return this->begin()[n];
135 }
136 };
137
138 } // namespace range_detail
139
140 template<class ForwardRange>
141 class sub_range
142 : public range_detail::sub_range_base<
143 ForwardRange,
144 BOOST_DEDUCED_TYPENAME iterator_traversal<
145 BOOST_DEDUCED_TYPENAME range_iterator<ForwardRange>::type
146 >::type
147 >
148 {
149 typedef BOOST_DEDUCED_TYPENAME range_iterator<
150 ForwardRange
151 >::type iterator_t;
152
153 typedef range_detail::sub_range_base<
154 ForwardRange,
155 BOOST_DEDUCED_TYPENAME iterator_traversal<
156 BOOST_DEDUCED_TYPENAME range_iterator<ForwardRange>::type
157 >::type
158 > base;
40 159
41 typedef BOOST_DEDUCED_TYPENAME base::impl impl; 160 typedef BOOST_DEDUCED_TYPENAME base::impl impl;
161
162 protected:
163 typedef BOOST_DEDUCED_TYPENAME base::iterator_range_ iterator_range_;
164
165 private:
166 template<class Source>
167 struct is_compatible_range
168 : is_convertible<
169 BOOST_DEDUCED_TYPENAME mpl::eval_if<
170 has_range_iterator<Source>,
171 range_iterator<Source>,
172 mpl::identity<void>
173 >::type,
174 BOOST_DEDUCED_TYPENAME base::iterator
175 >
176 {
177 };
178
42 public: 179 public:
43 typedef BOOST_DEDUCED_TYPENAME range_value<ForwardRange>::type value_type; 180 sub_range()
44 typedef BOOST_DEDUCED_TYPENAME range_iterator<ForwardRange>::type iterator;
45 typedef BOOST_DEDUCED_TYPENAME range_iterator<const ForwardRange>::type const_iterator;
46 typedef BOOST_DEDUCED_TYPENAME range_difference<ForwardRange>::type difference_type;
47 typedef BOOST_DEDUCED_TYPENAME range_size<ForwardRange>::type size_type;
48 typedef BOOST_DEDUCED_TYPENAME base::reference reference;
49
50 public: // for return value of front/back
51 typedef BOOST_DEDUCED_TYPENAME
52 boost::mpl::if_< boost::is_reference<reference>,
53 const BOOST_DEDUCED_TYPENAME boost::remove_reference<reference>::type&,
54 reference >::type const_reference;
55
56 public:
57 sub_range() : base()
58 { } 181 { }
59 182
60 #if BOOST_WORKAROUND(BOOST_MSVC, BOOST_TESTED_AT(1500) ) 183 #if BOOST_WORKAROUND(BOOST_MSVC, BOOST_TESTED_AT(1500) )
61 sub_range( const sub_range& r ) 184 sub_range(const sub_range& r)
62 : base( static_cast<const base&>( r ) ) 185 : base(impl::adl_begin(static_cast<const base&>(r)),
186 impl::adl_end(static_cast<const base&>(r)))
63 { } 187 { }
64 #endif 188 #endif
65 189
66 template< class ForwardRange2 > 190 template< class ForwardRange2 >
67 sub_range( ForwardRange2& r ) : 191 sub_range(
68 192 ForwardRange2& r,
69 #if BOOST_WORKAROUND(BOOST_INTEL_CXX_VERSION, <= 800 ) 193 BOOST_DEDUCED_TYPENAME ::boost::enable_if<
70 base( impl::adl_begin( r ), impl::adl_end( r ) ) 194 is_compatible_range<ForwardRange2>
71 #else 195 >::type* = 0
72 base( r ) 196 )
73 #endif 197 : base(impl::adl_begin(r), impl::adl_end(r))
74 { } 198 {
75 199 }
200
76 template< class ForwardRange2 > 201 template< class ForwardRange2 >
77 sub_range( const ForwardRange2& r ) : 202 sub_range(
78 203 const ForwardRange2& r,
79 #if BOOST_WORKAROUND(BOOST_INTEL_CXX_VERSION, <= 800 ) 204 BOOST_DEDUCED_TYPENAME ::boost::enable_if<
80 base( impl::adl_begin( r ), impl::adl_end( r ) ) 205 is_compatible_range<const ForwardRange2>
81 #else 206 >::type* = 0
82 base( r ) 207 )
83 #endif 208 : base(impl::adl_begin(r), impl::adl_end(r))
84 { } 209 {
210 }
211
212 BOOST_DEDUCED_TYPENAME base::const_iterator begin() const
213 {
214 return base::begin();
215 }
216
217 BOOST_DEDUCED_TYPENAME base::iterator begin()
218 {
219 return base::begin();
220 }
221
222 BOOST_DEDUCED_TYPENAME base::const_iterator end() const
223 {
224 return base::end();
225 }
226
227 BOOST_DEDUCED_TYPENAME base::iterator end()
228 {
229 return base::end();
230 }
85 231
86 template< class Iter > 232 template< class Iter >
87 sub_range( Iter first, Iter last ) : 233 sub_range( Iter first, Iter last ) :
88 base( first, last ) 234 base( first, last )
89 { } 235 { }
236
237 template<class ForwardRange2>
238 BOOST_DEDUCED_TYPENAME ::boost::enable_if<
239 is_compatible_range<ForwardRange2>,
240 sub_range&
241 >::type
242 operator=(ForwardRange2& r)
243 {
244 iterator_range_::operator=( r );
245 return *this;
246 }
247
248 template<class ForwardRange2>
249 BOOST_DEDUCED_TYPENAME ::boost::enable_if<
250 is_compatible_range<const ForwardRange2>,
251 sub_range&
252 >::type
253 operator=( const ForwardRange2& r )
254 {
255 iterator_range_::operator=( r );
256 return *this;
257 }
258
259 sub_range& operator=( const sub_range& r )
260 {
261 iterator_range_::operator=( static_cast<const iterator_range_&>(r) );
262 return *this;
263 }
90 264
91 template< class ForwardRange2 > 265 sub_range& advance_begin(
92 sub_range& operator=( ForwardRange2& r ) 266 BOOST_DEDUCED_TYPENAME base::difference_type n)
93 { 267 {
94 base::operator=( r ); 268 std::advance(this->m_Begin, n);
95 return *this; 269 return *this;
96 }
97
98 template< class ForwardRange2 >
99 sub_range& operator=( const ForwardRange2& r )
100 {
101 base::operator=( r );
102 return *this;
103 }
104
105 sub_range& operator=( const sub_range& r )
106 {
107 base::operator=( static_cast<const base&>(r) );
108 return *this;
109 } 270 }
110 271
111 public: 272 sub_range& advance_end(
112 273 BOOST_DEDUCED_TYPENAME base::difference_type n)
113 iterator begin() { return base::begin(); } 274 {
114 const_iterator begin() const { return base::begin(); } 275 std::advance(this->m_End, n);
115 iterator end() { return base::end(); } 276 return *this;
116 const_iterator end() const { return base::end(); } 277 }
117 difference_type size() const { return base::size(); }
118
119
120 public: // convenience
121 reference front()
122 {
123 return base::front();
124 }
125
126 const_reference front() const
127 {
128 return base::front();
129 }
130
131 reference back()
132 {
133 return base::back();
134 }
135
136 const_reference back() const
137 {
138 return base::back();
139 }
140
141 reference operator[]( difference_type sz )
142 {
143 return base::operator[](sz);
144 }
145
146 const_reference operator[]( difference_type sz ) const
147 {
148 return base::operator[](sz);
149 }
150
151 }; 278 };
152
153 template< class ForwardRange, class ForwardRange2 >
154 inline bool operator==( const sub_range<ForwardRange>& l,
155 const sub_range<ForwardRange2>& r )
156 {
157 return boost::equal( l, r );
158 }
159
160 template< class ForwardRange, class ForwardRange2 >
161 inline bool operator!=( const sub_range<ForwardRange>& l,
162 const sub_range<ForwardRange2>& r )
163 {
164 return !boost::equal( l, r );
165 }
166
167 template< class ForwardRange, class ForwardRange2 >
168 inline bool operator<( const sub_range<ForwardRange>& l,
169 const sub_range<ForwardRange2>& r )
170 {
171 return iterator_range_detail::less_than( l, r );
172 }
173
174 279
175 } // namespace 'boost' 280 } // namespace 'boost'
176 281
177 #if BOOST_WORKAROUND(BOOST_MSVC, BOOST_TESTED_AT(1500)) 282 #if BOOST_WORKAROUND(BOOST_MSVC, BOOST_TESTED_AT(1500))
178 #pragma warning( pop ) 283 #pragma warning( pop )