1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
// Boost.Range library
//
// Copyright Neil Groves 2009.
// Copyright Thorsten Ottosen 2003-2004. Use, modification and
// distribution is subject to the Boost Software License, Version
// 1.0. (See accompanying file LICENSE_1_0.txt or copy at
// http://www.boost.org/LICENSE_1_0.txt)
//
// For more information, see http://www.boost.org/libs/range/
//
#ifndef BOOST_RANGE_SUB_RANGE_HPP
#define BOOST_RANGE_SUB_RANGE_HPP
#include <boost/detail/workaround.hpp>
#if BOOST_WORKAROUND(BOOST_MSVC, BOOST_TESTED_AT(1500))
#pragma warning( push )
#pragma warning( disable : 4996 )
#endif
#include <boost/range/config.hpp>
#include <boost/range/iterator_range.hpp>
#include <boost/range/value_type.hpp>
#include <boost/range/size_type.hpp>
#include <boost/range/difference_type.hpp>
#include <boost/range/reference.hpp>
#include <boost/range/algorithm/equal.hpp>
#include <boost/assert.hpp>
#include <boost/type_traits/is_reference.hpp>
#include <boost/type_traits/remove_reference.hpp>
namespace boost
{
namespace range_detail
{
template<class ForwardRange, class TraversalTag>
class sub_range_base
: public iterator_range<
BOOST_DEDUCED_TYPENAME range_iterator<ForwardRange>::type
>
{
typedef iterator_range<
BOOST_DEDUCED_TYPENAME range_iterator<ForwardRange>::type
> base;
protected:
typedef BOOST_DEDUCED_TYPENAME base::iterator_range_ iterator_range_;
public:
typedef BOOST_DEDUCED_TYPENAME range_value<ForwardRange>::type value_type;
typedef BOOST_DEDUCED_TYPENAME range_iterator<ForwardRange>::type iterator;
typedef BOOST_DEDUCED_TYPENAME range_iterator<const ForwardRange>::type const_iterator;
typedef BOOST_DEDUCED_TYPENAME range_difference<ForwardRange>::type difference_type;
typedef BOOST_DEDUCED_TYPENAME range_size<ForwardRange>::type size_type;
typedef BOOST_DEDUCED_TYPENAME range_reference<ForwardRange>::type reference;
typedef BOOST_DEDUCED_TYPENAME range_reference<const ForwardRange>::type const_reference;
sub_range_base()
{
}
template<class Iterator>
sub_range_base(Iterator first, Iterator last)
: base(first, last)
{
}
reference front()
{
return base::front();
}
const_reference front() const
{
return base::front();
}
};
template<class ForwardRange>
class sub_range_base<ForwardRange, bidirectional_traversal_tag>
: public sub_range_base<ForwardRange, forward_traversal_tag>
{
typedef sub_range_base<ForwardRange, forward_traversal_tag> base;
public:
sub_range_base()
{
}
template<class Iterator>
sub_range_base(Iterator first, Iterator last)
: base(first, last)
{
}
BOOST_DEDUCED_TYPENAME base::reference back()
{
return base::back();
}
BOOST_DEDUCED_TYPENAME base::const_reference back() const
{
return base::back();
}
};
template<class ForwardRange>
class sub_range_base<ForwardRange, random_access_traversal_tag>
: public sub_range_base<ForwardRange, bidirectional_traversal_tag>
{
typedef sub_range_base<ForwardRange, bidirectional_traversal_tag> base;
public:
sub_range_base()
{
}
template<class Iterator>
sub_range_base(Iterator first, Iterator last)
: base(first, last)
{
}
BOOST_DEDUCED_TYPENAME base::reference
operator[](BOOST_DEDUCED_TYPENAME base::difference_type n)
{
return this->begin()[n];
}
BOOST_DEDUCED_TYPENAME base::const_reference
operator[](BOOST_DEDUCED_TYPENAME base::difference_type n) const
{
return this->begin()[n];
}
};
} // namespace range_detail
template<class ForwardRange>
class sub_range
: public range_detail::sub_range_base<
ForwardRange,
BOOST_DEDUCED_TYPENAME iterator_traversal<
BOOST_DEDUCED_TYPENAME range_iterator<ForwardRange>::type
>::type
>
{
typedef BOOST_DEDUCED_TYPENAME range_iterator<
ForwardRange
>::type iterator_t;
typedef range_detail::sub_range_base<
ForwardRange,
BOOST_DEDUCED_TYPENAME iterator_traversal<
BOOST_DEDUCED_TYPENAME range_iterator<ForwardRange>::type
>::type
> base;
typedef BOOST_DEDUCED_TYPENAME base::impl impl;
protected:
typedef BOOST_DEDUCED_TYPENAME base::iterator_range_ iterator_range_;
private:
template<class Source>
struct is_compatible_range
: is_convertible<
BOOST_DEDUCED_TYPENAME mpl::eval_if<
has_range_iterator<Source>,
range_iterator<Source>,
mpl::identity<void>
>::type,
BOOST_DEDUCED_TYPENAME base::iterator
>
{
};
public:
sub_range()
{ }
#if BOOST_WORKAROUND(BOOST_MSVC, BOOST_TESTED_AT(1500) )
sub_range(const sub_range& r)
: base(impl::adl_begin(static_cast<const base&>(r)),
impl::adl_end(static_cast<const base&>(r)))
{ }
#endif
template< class ForwardRange2 >
sub_range(
ForwardRange2& r,
BOOST_DEDUCED_TYPENAME ::boost::enable_if<
is_compatible_range<ForwardRange2>
>::type* = 0
)
: base(impl::adl_begin(r), impl::adl_end(r))
{
}
template< class ForwardRange2 >
sub_range(
const ForwardRange2& r,
BOOST_DEDUCED_TYPENAME ::boost::enable_if<
is_compatible_range<const ForwardRange2>
>::type* = 0
)
: base(impl::adl_begin(r), impl::adl_end(r))
{
}
BOOST_DEDUCED_TYPENAME base::const_iterator begin() const
{
return base::begin();
}
BOOST_DEDUCED_TYPENAME base::iterator begin()
{
return base::begin();
}
BOOST_DEDUCED_TYPENAME base::const_iterator end() const
{
return base::end();
}
BOOST_DEDUCED_TYPENAME base::iterator end()
{
return base::end();
}
template< class Iter >
sub_range( Iter first, Iter last ) :
base( first, last )
{ }
template<class ForwardRange2>
BOOST_DEDUCED_TYPENAME ::boost::enable_if<
is_compatible_range<ForwardRange2>,
sub_range&
>::type
operator=(ForwardRange2& r)
{
iterator_range_::operator=( r );
return *this;
}
template<class ForwardRange2>
BOOST_DEDUCED_TYPENAME ::boost::enable_if<
is_compatible_range<const ForwardRange2>,
sub_range&
>::type
operator=( const ForwardRange2& r )
{
iterator_range_::operator=( r );
return *this;
}
sub_range& operator=( const sub_range& r )
{
iterator_range_::operator=( static_cast<const iterator_range_&>(r) );
return *this;
}
sub_range& advance_begin(
BOOST_DEDUCED_TYPENAME base::difference_type n)
{
std::advance(this->m_Begin, n);
return *this;
}
sub_range& advance_end(
BOOST_DEDUCED_TYPENAME base::difference_type n)
{
std::advance(this->m_End, n);
return *this;
}
};
} // namespace 'boost'
#if BOOST_WORKAROUND(BOOST_MSVC, BOOST_TESTED_AT(1500))
#pragma warning( pop )
#endif
#endif