williamr@4
|
1 |
// (C) Copyright David Abrahams 2002.
|
williamr@4
|
2 |
// Distributed under the Boost Software License, Version 1.0. (See
|
williamr@4
|
3 |
// accompanying file LICENSE_1_0.txt or copy at
|
williamr@4
|
4 |
// http://www.boost.org/LICENSE_1_0.txt)
|
williamr@4
|
5 |
|
williamr@4
|
6 |
// Boost versions of
|
williamr@2
|
7 |
//
|
williamr@4
|
8 |
// std::iterator_traits<>::iterator_category
|
williamr@4
|
9 |
// std::iterator_traits<>::difference_type
|
williamr@4
|
10 |
// std::distance()
|
williamr@2
|
11 |
//
|
williamr@4
|
12 |
// ...for all compilers and iterators
|
williamr@2
|
13 |
//
|
williamr@4
|
14 |
// Additionally, if X is a pointer
|
williamr@4
|
15 |
// std::iterator_traits<X>::pointer
|
williamr@2
|
16 |
|
williamr@4
|
17 |
// Otherwise, if partial specialization is supported or X is not a pointer
|
williamr@4
|
18 |
// std::iterator_traits<X>::value_type
|
williamr@4
|
19 |
// std::iterator_traits<X>::pointer
|
williamr@4
|
20 |
// std::iterator_traits<X>::reference
|
williamr@4
|
21 |
//
|
williamr@4
|
22 |
// See http://www.boost.org for most recent version including documentation.
|
williamr@2
|
23 |
|
williamr@4
|
24 |
// Revision History
|
williamr@4
|
25 |
// 04 Mar 2001 - More attempted fixes for Intel C++ (David Abrahams)
|
williamr@4
|
26 |
// 03 Mar 2001 - Put all implementation into namespace
|
williamr@4
|
27 |
// boost::detail::iterator_traits_. Some progress made on fixes
|
williamr@4
|
28 |
// for Intel compiler. (David Abrahams)
|
williamr@4
|
29 |
// 02 Mar 2001 - Changed BOOST_MSVC to BOOST_MSVC_STD_ITERATOR in a few
|
williamr@4
|
30 |
// places. (Jeremy Siek)
|
williamr@4
|
31 |
// 19 Feb 2001 - Improved workarounds for stock MSVC6; use yes_type and
|
williamr@4
|
32 |
// no_type from type_traits.hpp; stopped trying to remove_cv
|
williamr@4
|
33 |
// before detecting is_pointer, in honor of the new type_traits
|
williamr@4
|
34 |
// semantics. (David Abrahams)
|
williamr@4
|
35 |
// 13 Feb 2001 - Make it work with nearly all standard-conforming iterators
|
williamr@4
|
36 |
// under raw VC6. The one category remaining which will fail is
|
williamr@4
|
37 |
// that of iterators derived from std::iterator but not
|
williamr@4
|
38 |
// boost::iterator and which redefine difference_type.
|
williamr@4
|
39 |
// 11 Feb 2001 - Clean away code which can never be used (David Abrahams)
|
williamr@4
|
40 |
// 09 Feb 2001 - Always have a definition for each traits member, even if it
|
williamr@4
|
41 |
// can't be properly deduced. These will be incomplete types in
|
williamr@4
|
42 |
// some cases (undefined<void>), but it helps suppress MSVC errors
|
williamr@4
|
43 |
// elsewhere (David Abrahams)
|
williamr@4
|
44 |
// 07 Feb 2001 - Support for more of the traits members where possible, making
|
williamr@4
|
45 |
// this useful as a replacement for std::iterator_traits<T> when
|
williamr@4
|
46 |
// used as a default template parameter.
|
williamr@4
|
47 |
// 06 Feb 2001 - Removed useless #includes of standard library headers
|
williamr@4
|
48 |
// (David Abrahams)
|
williamr@2
|
49 |
|
williamr@4
|
50 |
#ifndef ITERATOR_DWA122600_HPP_
|
williamr@4
|
51 |
# define ITERATOR_DWA122600_HPP_
|
williamr@2
|
52 |
|
williamr@4
|
53 |
# include <boost/config.hpp>
|
williamr@4
|
54 |
# include <iterator>
|
williamr@2
|
55 |
|
williamr@4
|
56 |
// STLPort 4.0 and betas have a bug when debugging is enabled and there is no
|
williamr@4
|
57 |
// partial specialization: instead of an iterator_category typedef, the standard
|
williamr@4
|
58 |
// container iterators have _Iterator_category.
|
williamr@4
|
59 |
//
|
williamr@4
|
60 |
// Also, whether debugging is enabled or not, there is a broken specialization
|
williamr@4
|
61 |
// of std::iterator<output_iterator_tag,void,void,void,void> which has no
|
williamr@4
|
62 |
// typedefs but iterator_category.
|
williamr@4
|
63 |
# if defined(__SGI_STL_PORT)
|
williamr@2
|
64 |
|
williamr@4
|
65 |
# if (__SGI_STL_PORT <= 0x410) && !defined(__STL_CLASS_PARTIAL_SPECIALIZATION) && defined(__STL_DEBUG)
|
williamr@4
|
66 |
# define BOOST_BAD_CONTAINER_ITERATOR_CATEGORY_TYPEDEF
|
williamr@4
|
67 |
# endif
|
williamr@4
|
68 |
|
williamr@4
|
69 |
# define BOOST_BAD_OUTPUT_ITERATOR_SPECIALIZATION
|
williamr@4
|
70 |
|
williamr@4
|
71 |
# endif // STLPort <= 4.1b4 && no partial specialization
|
williamr@4
|
72 |
|
williamr@4
|
73 |
# if !defined(BOOST_NO_STD_ITERATOR_TRAITS) \
|
williamr@4
|
74 |
&& !defined(BOOST_NO_TEMPLATE_PARTIAL_SPECIALIZATION) \
|
williamr@4
|
75 |
&& !defined(BOOST_MSVC_STD_ITERATOR)
|
williamr@4
|
76 |
|
williamr@4
|
77 |
namespace boost { namespace detail {
|
williamr@4
|
78 |
|
williamr@4
|
79 |
// Define a new template so it can be specialized
|
williamr@4
|
80 |
template <class Iterator>
|
williamr@4
|
81 |
struct iterator_traits
|
williamr@4
|
82 |
: std::iterator_traits<Iterator>
|
williamr@4
|
83 |
{};
|
williamr@4
|
84 |
using std::distance;
|
williamr@4
|
85 |
|
williamr@4
|
86 |
}} // namespace boost::detail
|
williamr@4
|
87 |
|
williamr@4
|
88 |
# else
|
williamr@4
|
89 |
|
williamr@4
|
90 |
# if !defined(BOOST_NO_TEMPLATE_PARTIAL_SPECIALIZATION) \
|
williamr@4
|
91 |
&& !defined(BOOST_MSVC_STD_ITERATOR)
|
williamr@4
|
92 |
|
williamr@4
|
93 |
// This is the case where everything conforms except BOOST_NO_STD_ITERATOR_TRAITS
|
williamr@4
|
94 |
|
williamr@4
|
95 |
namespace boost { namespace detail {
|
williamr@4
|
96 |
|
williamr@4
|
97 |
// Rogue Wave Standard Library fools itself into thinking partial
|
williamr@4
|
98 |
// specialization is missing on some platforms (e.g. Sun), so fails to
|
williamr@4
|
99 |
// supply iterator_traits!
|
williamr@4
|
100 |
template <class Iterator>
|
williamr@4
|
101 |
struct iterator_traits
|
williamr@2
|
102 |
{
|
williamr@4
|
103 |
typedef typename Iterator::value_type value_type;
|
williamr@4
|
104 |
typedef typename Iterator::reference reference;
|
williamr@4
|
105 |
typedef typename Iterator::pointer pointer;
|
williamr@4
|
106 |
typedef typename Iterator::difference_type difference_type;
|
williamr@4
|
107 |
typedef typename Iterator::iterator_category iterator_category;
|
williamr@4
|
108 |
};
|
williamr@4
|
109 |
|
williamr@4
|
110 |
template <class T>
|
williamr@4
|
111 |
struct iterator_traits<T*>
|
williamr@4
|
112 |
{
|
williamr@4
|
113 |
typedef T value_type;
|
williamr@4
|
114 |
typedef T& reference;
|
williamr@4
|
115 |
typedef T* pointer;
|
williamr@4
|
116 |
typedef std::ptrdiff_t difference_type;
|
williamr@4
|
117 |
typedef std::random_access_iterator_tag iterator_category;
|
williamr@4
|
118 |
};
|
williamr@4
|
119 |
|
williamr@4
|
120 |
template <class T>
|
williamr@4
|
121 |
struct iterator_traits<T const*>
|
williamr@4
|
122 |
{
|
williamr@4
|
123 |
typedef T value_type;
|
williamr@4
|
124 |
typedef T const& reference;
|
williamr@4
|
125 |
typedef T const* pointer;
|
williamr@4
|
126 |
typedef std::ptrdiff_t difference_type;
|
williamr@4
|
127 |
typedef std::random_access_iterator_tag iterator_category;
|
williamr@4
|
128 |
};
|
williamr@4
|
129 |
|
williamr@4
|
130 |
}} // namespace boost::detail
|
williamr@4
|
131 |
|
williamr@4
|
132 |
# else
|
williamr@4
|
133 |
|
williamr@4
|
134 |
# include <boost/type_traits/remove_const.hpp>
|
williamr@4
|
135 |
# include <boost/type_traits/detail/yes_no_type.hpp>
|
williamr@4
|
136 |
# include <boost/type_traits/is_pointer.hpp>
|
williamr@4
|
137 |
|
williamr@4
|
138 |
# ifdef BOOST_NO_TEMPLATE_PARTIAL_SPECIALIZATION
|
williamr@4
|
139 |
# include <boost/type_traits/is_same.hpp>
|
williamr@4
|
140 |
# include <boost/type_traits/remove_pointer.hpp>
|
williamr@4
|
141 |
# endif
|
williamr@4
|
142 |
# ifdef BOOST_BAD_OUTPUT_ITERATOR_SPECIALIZATION
|
williamr@4
|
143 |
# include <boost/type_traits/is_base_and_derived.hpp>
|
williamr@4
|
144 |
# endif
|
williamr@4
|
145 |
|
williamr@4
|
146 |
# include <boost/mpl/if.hpp>
|
williamr@4
|
147 |
# include <boost/mpl/has_xxx.hpp>
|
williamr@4
|
148 |
# include <cstddef>
|
williamr@4
|
149 |
|
williamr@4
|
150 |
// should be the last #include
|
williamr@4
|
151 |
# include "boost/type_traits/detail/bool_trait_def.hpp"
|
williamr@4
|
152 |
|
williamr@4
|
153 |
namespace boost { namespace detail {
|
williamr@4
|
154 |
|
williamr@4
|
155 |
BOOST_MPL_HAS_XXX_TRAIT_DEF(value_type)
|
williamr@4
|
156 |
BOOST_MPL_HAS_XXX_TRAIT_DEF(reference)
|
williamr@4
|
157 |
BOOST_MPL_HAS_XXX_TRAIT_DEF(pointer)
|
williamr@4
|
158 |
BOOST_MPL_HAS_XXX_TRAIT_DEF(difference_type)
|
williamr@4
|
159 |
BOOST_MPL_HAS_XXX_TRAIT_DEF(iterator_category)
|
williamr@4
|
160 |
|
williamr@4
|
161 |
// is_mutable_iterator --
|
williamr@4
|
162 |
//
|
williamr@4
|
163 |
// A metafunction returning true iff T is a mutable iterator type
|
williamr@4
|
164 |
// with a nested value_type. Will only work portably with iterators
|
williamr@4
|
165 |
// whose operator* returns a reference, but that seems to be OK for
|
williamr@4
|
166 |
// the iterators supplied by Dinkumware. Some input iterators may
|
williamr@4
|
167 |
// compile-time if they arrive here, and if the compiler is strict
|
williamr@4
|
168 |
// about not taking the address of an rvalue.
|
williamr@4
|
169 |
|
williamr@4
|
170 |
// This one detects ordinary mutable iterators - the result of
|
williamr@4
|
171 |
// operator* is convertible to the value_type.
|
williamr@4
|
172 |
template <class T>
|
williamr@4
|
173 |
type_traits::yes_type is_mutable_iterator_helper(T const*, BOOST_DEDUCED_TYPENAME T::value_type*);
|
williamr@4
|
174 |
|
williamr@4
|
175 |
// Since you can't take the address of an rvalue, the guts of
|
williamr@4
|
176 |
// is_mutable_iterator_impl will fail if we use &*t directly. This
|
williamr@4
|
177 |
// makes sure we can still work with non-lvalue iterators.
|
williamr@4
|
178 |
template <class T> T* mutable_iterator_lvalue_helper(T& x);
|
williamr@4
|
179 |
int mutable_iterator_lvalue_helper(...);
|
williamr@4
|
180 |
|
williamr@4
|
181 |
|
williamr@4
|
182 |
// This one detects output iterators such as ostream_iterator which
|
williamr@4
|
183 |
// return references to themselves.
|
williamr@4
|
184 |
template <class T>
|
williamr@4
|
185 |
type_traits::yes_type is_mutable_iterator_helper(T const*, T const*);
|
williamr@4
|
186 |
|
williamr@4
|
187 |
type_traits::no_type is_mutable_iterator_helper(...);
|
williamr@4
|
188 |
|
williamr@4
|
189 |
template <class T>
|
williamr@4
|
190 |
struct is_mutable_iterator_impl
|
williamr@4
|
191 |
{
|
williamr@4
|
192 |
static T t;
|
williamr@2
|
193 |
|
williamr@4
|
194 |
BOOST_STATIC_CONSTANT(
|
williamr@4
|
195 |
bool, value = sizeof(
|
williamr@4
|
196 |
detail::is_mutable_iterator_helper(
|
williamr@4
|
197 |
(T*)0
|
williamr@4
|
198 |
, mutable_iterator_lvalue_helper(*t) // like &*t
|
williamr@4
|
199 |
))
|
williamr@4
|
200 |
== sizeof(type_traits::yes_type)
|
williamr@4
|
201 |
);
|
williamr@4
|
202 |
};
|
williamr@4
|
203 |
|
williamr@4
|
204 |
BOOST_TT_AUX_BOOL_TRAIT_DEF1(
|
williamr@4
|
205 |
is_mutable_iterator,T,::boost::detail::is_mutable_iterator_impl<T>::value)
|
williamr@4
|
206 |
|
williamr@4
|
207 |
|
williamr@4
|
208 |
// is_full_iterator_traits --
|
williamr@4
|
209 |
//
|
williamr@4
|
210 |
// A metafunction returning true iff T has all the requisite nested
|
williamr@4
|
211 |
// types to satisfy the requirements for a fully-conforming
|
williamr@4
|
212 |
// iterator_traits implementation.
|
williamr@4
|
213 |
template <class T>
|
williamr@4
|
214 |
struct is_full_iterator_traits_impl
|
williamr@4
|
215 |
{
|
williamr@4
|
216 |
enum { value =
|
williamr@4
|
217 |
has_value_type<T>::value
|
williamr@4
|
218 |
& has_reference<T>::value
|
williamr@4
|
219 |
& has_pointer<T>::value
|
williamr@4
|
220 |
& has_difference_type<T>::value
|
williamr@4
|
221 |
& has_iterator_category<T>::value
|
williamr@2
|
222 |
};
|
williamr@4
|
223 |
};
|
williamr@4
|
224 |
|
williamr@4
|
225 |
BOOST_TT_AUX_BOOL_TRAIT_DEF1(
|
williamr@4
|
226 |
is_full_iterator_traits,T,::boost::detail::is_full_iterator_traits_impl<T>::value)
|
williamr@4
|
227 |
|
williamr@4
|
228 |
|
williamr@4
|
229 |
# ifdef BOOST_BAD_CONTAINER_ITERATOR_CATEGORY_TYPEDEF
|
williamr@4
|
230 |
BOOST_MPL_HAS_XXX_TRAIT_DEF(_Iterator_category)
|
williamr@2
|
231 |
|
williamr@4
|
232 |
// is_stlport_40_debug_iterator --
|
williamr@4
|
233 |
//
|
williamr@4
|
234 |
// A metafunction returning true iff T has all the requisite nested
|
williamr@4
|
235 |
// types to satisfy the requirements of an STLPort 4.0 debug iterator
|
williamr@4
|
236 |
// iterator_traits implementation.
|
williamr@4
|
237 |
template <class T>
|
williamr@4
|
238 |
struct is_stlport_40_debug_iterator_impl
|
williamr@4
|
239 |
{
|
williamr@4
|
240 |
enum { value =
|
williamr@4
|
241 |
has_value_type<T>::value
|
williamr@4
|
242 |
& has_reference<T>::value
|
williamr@4
|
243 |
& has_pointer<T>::value
|
williamr@4
|
244 |
& has_difference_type<T>::value
|
williamr@4
|
245 |
& has__Iterator_category<T>::value
|
williamr@4
|
246 |
};
|
williamr@4
|
247 |
};
|
williamr@2
|
248 |
|
williamr@4
|
249 |
BOOST_TT_AUX_BOOL_TRAIT_DEF1(
|
williamr@4
|
250 |
is_stlport_40_debug_iterator,T,::boost::detail::is_stlport_40_debug_iterator_impl<T>::value)
|
williamr@4
|
251 |
|
williamr@4
|
252 |
template <class T>
|
williamr@4
|
253 |
struct stlport_40_debug_iterator_traits
|
williamr@4
|
254 |
{
|
williamr@4
|
255 |
typedef typename T::value_type value_type;
|
williamr@4
|
256 |
typedef typename T::reference reference;
|
williamr@4
|
257 |
typedef typename T::pointer pointer;
|
williamr@4
|
258 |
typedef typename T::difference_type difference_type;
|
williamr@4
|
259 |
typedef typename T::_Iterator_category iterator_category;
|
williamr@4
|
260 |
};
|
williamr@4
|
261 |
# endif // BOOST_BAD_CONTAINER_ITERATOR_CATEGORY_TYPEDEF
|
williamr@4
|
262 |
|
williamr@4
|
263 |
template <class T> struct pointer_iterator_traits;
|
williamr@4
|
264 |
|
williamr@4
|
265 |
# ifndef BOOST_NO_TEMPLATE_PARTIAL_SPECIALIZATION
|
williamr@4
|
266 |
template <class T>
|
williamr@4
|
267 |
struct pointer_iterator_traits<T*>
|
williamr@4
|
268 |
{
|
williamr@4
|
269 |
typedef typename remove_const<T>::type value_type;
|
williamr@4
|
270 |
typedef T* pointer;
|
williamr@4
|
271 |
typedef T& reference;
|
williamr@4
|
272 |
typedef std::random_access_iterator_tag iterator_category;
|
williamr@4
|
273 |
typedef std::ptrdiff_t difference_type;
|
williamr@4
|
274 |
};
|
williamr@4
|
275 |
# else
|
williamr@4
|
276 |
|
williamr@4
|
277 |
// In case of no template partial specialization, and if T is a
|
williamr@4
|
278 |
// pointer, iterator_traits<T>::value_type can still be computed. For
|
williamr@4
|
279 |
// some basic types, remove_pointer is manually defined in
|
williamr@4
|
280 |
// type_traits/broken_compiler_spec.hpp. For others, do it yourself.
|
williamr@4
|
281 |
|
williamr@4
|
282 |
template<class P> class please_invoke_BOOST_TT_BROKEN_COMPILER_SPEC_on_cv_unqualified_pointee;
|
williamr@4
|
283 |
|
williamr@4
|
284 |
template<class P>
|
williamr@4
|
285 |
struct pointer_value_type
|
williamr@4
|
286 |
: mpl::if_<
|
williamr@4
|
287 |
is_same<P, typename remove_pointer<P>::type>
|
williamr@4
|
288 |
, please_invoke_BOOST_TT_BROKEN_COMPILER_SPEC_on_cv_unqualified_pointee<P>
|
williamr@4
|
289 |
, typename remove_const<
|
williamr@4
|
290 |
typename remove_pointer<P>::type
|
williamr@4
|
291 |
>::type
|
williamr@4
|
292 |
>
|
williamr@4
|
293 |
{
|
williamr@4
|
294 |
};
|
williamr@4
|
295 |
|
williamr@4
|
296 |
|
williamr@4
|
297 |
template<class P>
|
williamr@4
|
298 |
struct pointer_reference
|
williamr@4
|
299 |
: mpl::if_<
|
williamr@4
|
300 |
is_same<P, typename remove_pointer<P>::type>
|
williamr@4
|
301 |
, please_invoke_BOOST_TT_BROKEN_COMPILER_SPEC_on_cv_unqualified_pointee<P>
|
williamr@4
|
302 |
, typename remove_pointer<P>::type&
|
williamr@4
|
303 |
>
|
williamr@4
|
304 |
{
|
williamr@4
|
305 |
};
|
williamr@4
|
306 |
|
williamr@4
|
307 |
template <class T>
|
williamr@4
|
308 |
struct pointer_iterator_traits
|
williamr@4
|
309 |
{
|
williamr@4
|
310 |
typedef T pointer;
|
williamr@4
|
311 |
typedef std::random_access_iterator_tag iterator_category;
|
williamr@4
|
312 |
typedef std::ptrdiff_t difference_type;
|
williamr@4
|
313 |
|
williamr@4
|
314 |
typedef typename pointer_value_type<T>::type value_type;
|
williamr@4
|
315 |
typedef typename pointer_reference<T>::type reference;
|
williamr@4
|
316 |
};
|
williamr@4
|
317 |
|
williamr@4
|
318 |
# endif // BOOST_NO_TEMPLATE_PARTIAL_SPECIALIZATION
|
williamr@4
|
319 |
|
williamr@4
|
320 |
// We'll sort iterator types into one of these classifications, from which we
|
williamr@4
|
321 |
// can determine the difference_type, pointer, reference, and value_type
|
williamr@4
|
322 |
template <class Iterator>
|
williamr@4
|
323 |
struct standard_iterator_traits
|
williamr@4
|
324 |
{
|
williamr@4
|
325 |
typedef typename Iterator::difference_type difference_type;
|
williamr@4
|
326 |
typedef typename Iterator::value_type value_type;
|
williamr@4
|
327 |
typedef typename Iterator::pointer pointer;
|
williamr@4
|
328 |
typedef typename Iterator::reference reference;
|
williamr@4
|
329 |
typedef typename Iterator::iterator_category iterator_category;
|
williamr@4
|
330 |
};
|
williamr@4
|
331 |
|
williamr@4
|
332 |
template <class Iterator>
|
williamr@4
|
333 |
struct msvc_stdlib_mutable_traits
|
williamr@4
|
334 |
: std::iterator_traits<Iterator>
|
williamr@4
|
335 |
{
|
williamr@4
|
336 |
typedef typename std::iterator_traits<Iterator>::distance_type difference_type;
|
williamr@4
|
337 |
typedef typename std::iterator_traits<Iterator>::value_type* pointer;
|
williamr@4
|
338 |
typedef typename std::iterator_traits<Iterator>::value_type& reference;
|
williamr@4
|
339 |
};
|
williamr@4
|
340 |
|
williamr@4
|
341 |
template <class Iterator>
|
williamr@4
|
342 |
struct msvc_stdlib_const_traits
|
williamr@4
|
343 |
: std::iterator_traits<Iterator>
|
williamr@4
|
344 |
{
|
williamr@4
|
345 |
typedef typename std::iterator_traits<Iterator>::distance_type difference_type;
|
williamr@4
|
346 |
typedef const typename std::iterator_traits<Iterator>::value_type* pointer;
|
williamr@4
|
347 |
typedef const typename std::iterator_traits<Iterator>::value_type& reference;
|
williamr@4
|
348 |
};
|
williamr@4
|
349 |
|
williamr@4
|
350 |
# ifdef BOOST_BAD_OUTPUT_ITERATOR_SPECIALIZATION
|
williamr@4
|
351 |
template <class Iterator>
|
williamr@4
|
352 |
struct is_bad_output_iterator
|
williamr@4
|
353 |
: is_base_and_derived<
|
williamr@4
|
354 |
std::iterator<std::output_iterator_tag,void,void,void,void>
|
williamr@4
|
355 |
, Iterator>
|
williamr@4
|
356 |
{
|
williamr@4
|
357 |
};
|
williamr@4
|
358 |
|
williamr@4
|
359 |
struct bad_output_iterator_traits
|
williamr@4
|
360 |
{
|
williamr@4
|
361 |
typedef void value_type;
|
williamr@4
|
362 |
typedef void difference_type;
|
williamr@4
|
363 |
typedef std::output_iterator_tag iterator_category;
|
williamr@4
|
364 |
typedef void pointer;
|
williamr@4
|
365 |
typedef void reference;
|
williamr@4
|
366 |
};
|
williamr@4
|
367 |
# endif
|
williamr@4
|
368 |
|
williamr@4
|
369 |
// If we're looking at an MSVC6 (old Dinkumware) ``standard''
|
williamr@4
|
370 |
// iterator, this will generate an appropriate traits class.
|
williamr@4
|
371 |
template <class Iterator>
|
williamr@4
|
372 |
struct msvc_stdlib_iterator_traits
|
williamr@4
|
373 |
: mpl::if_<
|
williamr@4
|
374 |
is_mutable_iterator<Iterator>
|
williamr@4
|
375 |
, msvc_stdlib_mutable_traits<Iterator>
|
williamr@4
|
376 |
, msvc_stdlib_const_traits<Iterator>
|
williamr@4
|
377 |
>::type
|
williamr@4
|
378 |
{};
|
williamr@4
|
379 |
|
williamr@4
|
380 |
template <class Iterator>
|
williamr@4
|
381 |
struct non_pointer_iterator_traits
|
williamr@4
|
382 |
: mpl::if_<
|
williamr@4
|
383 |
// if the iterator contains all the right nested types...
|
williamr@4
|
384 |
is_full_iterator_traits<Iterator>
|
williamr@4
|
385 |
// Use a standard iterator_traits implementation
|
williamr@4
|
386 |
, standard_iterator_traits<Iterator>
|
williamr@4
|
387 |
# ifdef BOOST_BAD_CONTAINER_ITERATOR_CATEGORY_TYPEDEF
|
williamr@4
|
388 |
// Check for STLPort 4.0 broken _Iterator_category type
|
williamr@4
|
389 |
, mpl::if_<
|
williamr@4
|
390 |
is_stlport_40_debug_iterator<Iterator>
|
williamr@4
|
391 |
, stlport_40_debug_iterator_traits<Iterator>
|
williamr@4
|
392 |
# endif
|
williamr@4
|
393 |
// Otherwise, assume it's a Dinkum iterator
|
williamr@4
|
394 |
, msvc_stdlib_iterator_traits<Iterator>
|
williamr@4
|
395 |
# ifdef BOOST_BAD_CONTAINER_ITERATOR_CATEGORY_TYPEDEF
|
williamr@4
|
396 |
>::type
|
williamr@4
|
397 |
# endif
|
williamr@4
|
398 |
>::type
|
williamr@4
|
399 |
{
|
williamr@4
|
400 |
};
|
williamr@4
|
401 |
|
williamr@4
|
402 |
template <class Iterator>
|
williamr@4
|
403 |
struct iterator_traits_aux
|
williamr@4
|
404 |
: mpl::if_<
|
williamr@4
|
405 |
is_pointer<Iterator>
|
williamr@4
|
406 |
, pointer_iterator_traits<Iterator>
|
williamr@4
|
407 |
, non_pointer_iterator_traits<Iterator>
|
williamr@4
|
408 |
>::type
|
williamr@4
|
409 |
{
|
williamr@4
|
410 |
};
|
williamr@4
|
411 |
|
williamr@4
|
412 |
template <class Iterator>
|
williamr@4
|
413 |
struct iterator_traits
|
williamr@4
|
414 |
{
|
williamr@4
|
415 |
// Explicit forwarding from base class needed to keep MSVC6 happy
|
williamr@4
|
416 |
// under some circumstances.
|
williamr@4
|
417 |
private:
|
williamr@4
|
418 |
# ifdef BOOST_BAD_OUTPUT_ITERATOR_SPECIALIZATION
|
williamr@4
|
419 |
typedef
|
williamr@4
|
420 |
typename mpl::if_<
|
williamr@4
|
421 |
is_bad_output_iterator<Iterator>
|
williamr@4
|
422 |
, bad_output_iterator_traits
|
williamr@4
|
423 |
, iterator_traits_aux<Iterator>
|
williamr@4
|
424 |
>::type base;
|
williamr@4
|
425 |
# else
|
williamr@4
|
426 |
typedef iterator_traits_aux<Iterator> base;
|
williamr@4
|
427 |
# endif
|
williamr@4
|
428 |
public:
|
williamr@4
|
429 |
typedef typename base::value_type value_type;
|
williamr@4
|
430 |
typedef typename base::pointer pointer;
|
williamr@4
|
431 |
typedef typename base::reference reference;
|
williamr@4
|
432 |
typedef typename base::difference_type difference_type;
|
williamr@4
|
433 |
typedef typename base::iterator_category iterator_category;
|
williamr@4
|
434 |
};
|
williamr@4
|
435 |
|
williamr@4
|
436 |
// This specialization cuts off ETI (Early Template Instantiation) for MSVC.
|
williamr@4
|
437 |
template <> struct iterator_traits<int>
|
williamr@4
|
438 |
{
|
williamr@4
|
439 |
typedef int value_type;
|
williamr@4
|
440 |
typedef int pointer;
|
williamr@4
|
441 |
typedef int reference;
|
williamr@4
|
442 |
typedef int difference_type;
|
williamr@4
|
443 |
typedef int iterator_category;
|
williamr@4
|
444 |
};
|
williamr@4
|
445 |
|
williamr@4
|
446 |
}} // namespace boost::detail
|
williamr@4
|
447 |
|
williamr@4
|
448 |
# endif // workarounds
|
williamr@4
|
449 |
|
williamr@4
|
450 |
namespace boost { namespace detail {
|
williamr@4
|
451 |
|
williamr@4
|
452 |
namespace iterator_traits_
|
williamr@4
|
453 |
{
|
williamr@4
|
454 |
template <class Iterator, class Difference>
|
williamr@4
|
455 |
struct distance_select
|
williamr@4
|
456 |
{
|
williamr@4
|
457 |
static Difference execute(Iterator i1, const Iterator i2, ...)
|
williamr@4
|
458 |
{
|
williamr@4
|
459 |
Difference result = 0;
|
williamr@4
|
460 |
while (i1 != i2)
|
williamr@4
|
461 |
{
|
williamr@4
|
462 |
++i1;
|
williamr@4
|
463 |
++result;
|
williamr@4
|
464 |
}
|
williamr@4
|
465 |
return result;
|
williamr@4
|
466 |
}
|
williamr@4
|
467 |
|
williamr@4
|
468 |
static Difference execute(Iterator i1, const Iterator i2, std::random_access_iterator_tag*)
|
williamr@4
|
469 |
{
|
williamr@4
|
470 |
return i2 - i1;
|
williamr@4
|
471 |
}
|
williamr@4
|
472 |
};
|
williamr@4
|
473 |
} // namespace boost::detail::iterator_traits_
|
williamr@4
|
474 |
|
williamr@4
|
475 |
template <class Iterator>
|
williamr@4
|
476 |
inline typename iterator_traits<Iterator>::difference_type
|
williamr@4
|
477 |
distance(Iterator first, Iterator last)
|
williamr@4
|
478 |
{
|
williamr@4
|
479 |
typedef typename iterator_traits<Iterator>::difference_type diff_t;
|
williamr@4
|
480 |
typedef typename ::boost::detail::iterator_traits<Iterator>::iterator_category iterator_category;
|
williamr@2
|
481 |
|
williamr@4
|
482 |
return iterator_traits_::distance_select<Iterator,diff_t>::execute(
|
williamr@4
|
483 |
first, last, (iterator_category*)0);
|
williamr@4
|
484 |
}
|
williamr@2
|
485 |
|
williamr@4
|
486 |
}}
|
williamr@2
|
487 |
|
williamr@4
|
488 |
# endif
|
williamr@2
|
489 |
|
williamr@2
|
490 |
|
williamr@4
|
491 |
# undef BOOST_BAD_CONTAINER_ITERATOR_CATEGORY_TYPEDEF
|
williamr@4
|
492 |
# undef BOOST_BAD_OUTPUT_ITERATOR_SPECIALIZATION
|
williamr@2
|
493 |
|
williamr@4
|
494 |
#endif // ITERATOR_DWA122600_HPP_
|