williamr@4
|
1 |
/*
|
williamr@4
|
2 |
*
|
williamr@4
|
3 |
* Copyright (c) 1994
|
williamr@4
|
4 |
* Hewlett-Packard Company
|
williamr@4
|
5 |
*
|
williamr@4
|
6 |
* Copyright (c) 1996-1998
|
williamr@4
|
7 |
* Silicon Graphics Computer Systems, Inc.
|
williamr@4
|
8 |
*
|
williamr@4
|
9 |
* Copyright (c) 1997
|
williamr@4
|
10 |
* Moscow Center for SPARC Technology
|
williamr@4
|
11 |
*
|
williamr@4
|
12 |
* Copyright (c) 1999
|
williamr@4
|
13 |
* Boris Fomitchev
|
williamr@4
|
14 |
*
|
williamr@4
|
15 |
* This material is provided "as is", with absolutely no warranty expressed
|
williamr@4
|
16 |
* or implied. Any use is at your own risk.
|
williamr@4
|
17 |
*
|
williamr@4
|
18 |
* Permission to use or copy this software for any purpose is hereby granted
|
williamr@4
|
19 |
* without fee, provided the above notices are retained on all copies.
|
williamr@4
|
20 |
* Permission to modify the code and to distribute modified code is granted,
|
williamr@4
|
21 |
* provided the above notices are retained, and a notice that the code was
|
williamr@4
|
22 |
* modified is included with the above copyright notice.
|
williamr@4
|
23 |
*
|
williamr@4
|
24 |
*/
|
williamr@4
|
25 |
|
williamr@4
|
26 |
/* NOTE: This is an internal header file, included by other STL headers.
|
williamr@4
|
27 |
* You should not attempt to use it directly.
|
williamr@4
|
28 |
*/
|
williamr@4
|
29 |
|
williamr@4
|
30 |
#ifndef _STLP_INTERNAL_ITERATOR_BASE_H
|
williamr@4
|
31 |
#define _STLP_INTERNAL_ITERATOR_BASE_H
|
williamr@4
|
32 |
|
williamr@4
|
33 |
#ifndef _STLP_INTERNAL_CSTDDEF
|
williamr@4
|
34 |
# include <stl/_cstddef.h>
|
williamr@4
|
35 |
#endif
|
williamr@4
|
36 |
|
williamr@4
|
37 |
//# if defined (_STLP_IMPORT_VENDOR_CSTD) && ! defined (_STLP_VENDOR_GLOBAL_CSTD)
|
williamr@4
|
38 |
//_STLP_BEGIN_NAMESPACE
|
williamr@4
|
39 |
//using namespace _STLP_VENDOR_CSTD;
|
williamr@4
|
40 |
//_STLP_END_NAMESPACE
|
williamr@4
|
41 |
//#endif /* _STLP_IMPORT_VENDOR_CSTD */
|
williamr@4
|
42 |
|
williamr@4
|
43 |
#if !defined(_STLP_USE_OLD_HP_ITERATOR_QUERIES) && !defined(_STLP_CLASS_PARTIAL_SPECIALIZATION)
|
williamr@4
|
44 |
# ifndef _STLP_TYPE_TRAITS_H
|
williamr@4
|
45 |
# include <stl/type_traits.h>
|
williamr@4
|
46 |
# endif
|
williamr@4
|
47 |
#endif
|
williamr@4
|
48 |
|
williamr@4
|
49 |
_STLP_BEGIN_NAMESPACE
|
williamr@4
|
50 |
|
williamr@4
|
51 |
struct input_iterator_tag {};
|
williamr@4
|
52 |
struct output_iterator_tag {};
|
williamr@4
|
53 |
struct forward_iterator_tag : public input_iterator_tag {};
|
williamr@4
|
54 |
struct bidirectional_iterator_tag : public forward_iterator_tag {};
|
williamr@4
|
55 |
struct random_access_iterator_tag : public bidirectional_iterator_tag {};
|
williamr@4
|
56 |
|
williamr@4
|
57 |
|
williamr@4
|
58 |
template <class _Category, class _Tp, _STLP_DFL_TMPL_PARAM(_Distance,ptrdiff_t),
|
williamr@4
|
59 |
_STLP_DFL_TMPL_PARAM(_Pointer,_Tp*), _STLP_DFL_TMPL_PARAM(_Reference,_Tp&) >
|
williamr@4
|
60 |
struct iterator {
|
williamr@4
|
61 |
typedef _Category iterator_category;
|
williamr@4
|
62 |
typedef _Tp value_type;
|
williamr@4
|
63 |
typedef _Distance difference_type;
|
williamr@4
|
64 |
typedef _Pointer pointer;
|
williamr@4
|
65 |
typedef _Reference reference;
|
williamr@4
|
66 |
};
|
williamr@4
|
67 |
_STLP_TEMPLATE_NULL
|
williamr@4
|
68 |
struct iterator<output_iterator_tag, void, void, void, void> {
|
williamr@4
|
69 |
typedef output_iterator_tag iterator_category;
|
williamr@4
|
70 |
#ifdef _STLP_CLASS_PARTIAL_SPECIALIZATION
|
williamr@4
|
71 |
typedef void value_type;
|
williamr@4
|
72 |
typedef void difference_type;
|
williamr@4
|
73 |
typedef void pointer;
|
williamr@4
|
74 |
typedef void reference;
|
williamr@4
|
75 |
#endif
|
williamr@4
|
76 |
};
|
williamr@4
|
77 |
|
williamr@4
|
78 |
#if defined (_STLP_USE_OLD_HP_ITERATOR_QUERIES)
|
williamr@4
|
79 |
# define _STLP_ITERATOR_CATEGORY(_It, _Tp) iterator_category(_It)
|
williamr@4
|
80 |
# define _STLP_DISTANCE_TYPE(_It, _Tp) distance_type(_It)
|
williamr@4
|
81 |
# define _STLP_VALUE_TYPE(_It, _Tp) value_type(_It)
|
williamr@4
|
82 |
//Old HP iterator queries do not give information about the iterator
|
williamr@4
|
83 |
//associated reference type so we consider that it is not a real reference.
|
williamr@4
|
84 |
# define _STLP_IS_REF_TYPE_REAL_REF(_It, _Tp) __false_type()
|
williamr@4
|
85 |
#else
|
williamr@4
|
86 |
# if defined (_STLP_CLASS_PARTIAL_SPECIALIZATION)
|
williamr@4
|
87 |
# define _STLP_VALUE_TYPE(_It, _Tp) (typename iterator_traits< _Tp >::value_type*)0
|
williamr@4
|
88 |
# define _STLP_DISTANCE_TYPE(_It, _Tp) (typename iterator_traits< _Tp >::difference_type*)0
|
williamr@4
|
89 |
# if defined (__BORLANDC__) || defined (__SUNPRO_CC) || ( defined (__MWERKS__) && (__MWERKS__ <= 0x2303)) || ( defined (__sgi) && defined (_COMPILER_VERSION)) || defined (__DMC__)
|
williamr@4
|
90 |
# define _STLP_ITERATOR_CATEGORY(_It, _Tp) iterator_traits< _Tp >::iterator_category()
|
williamr@4
|
91 |
# else
|
williamr@4
|
92 |
# define _STLP_ITERATOR_CATEGORY(_It, _Tp) typename iterator_traits< _Tp >::iterator_category()
|
williamr@4
|
93 |
# endif
|
williamr@4
|
94 |
# define _STLP_IS_REF_TYPE_REAL_REF(_It, _Tp) _IsRefType< typename iterator_traits< _Tp >::reference >::_Ret()
|
williamr@4
|
95 |
# else
|
williamr@4
|
96 |
# define _STLP_ITERATOR_CATEGORY(_It, _Tp) __iterator_category(_It, _IsPtrType<_Tp>::_Ret())
|
williamr@4
|
97 |
# define _STLP_DISTANCE_TYPE(_It, _Tp) (ptrdiff_t*)0
|
williamr@4
|
98 |
# define _STLP_VALUE_TYPE(_It, _Tp) __value_type(_It, _IsPtrType<_Tp>::_Ret() )
|
williamr@4
|
99 |
# define _STLP_IS_REF_TYPE_REAL_REF(_It, _Tp) __false_type()
|
williamr@4
|
100 |
# endif
|
williamr@4
|
101 |
#endif
|
williamr@4
|
102 |
|
williamr@4
|
103 |
template <class _Iterator>
|
williamr@4
|
104 |
struct iterator_traits {
|
williamr@4
|
105 |
typedef typename _Iterator::iterator_category iterator_category;
|
williamr@4
|
106 |
typedef typename _Iterator::value_type value_type;
|
williamr@4
|
107 |
typedef typename _Iterator::difference_type difference_type;
|
williamr@4
|
108 |
typedef typename _Iterator::pointer pointer;
|
williamr@4
|
109 |
typedef typename _Iterator::reference reference;
|
williamr@4
|
110 |
};
|
williamr@4
|
111 |
|
williamr@4
|
112 |
|
williamr@4
|
113 |
#if defined (_STLP_CLASS_PARTIAL_SPECIALIZATION) && ! defined (__SUNPRO_CC)
|
williamr@4
|
114 |
# define _STLP_DIFFERENCE_TYPE(_Iterator) typename iterator_traits<_Iterator>::difference_type
|
williamr@4
|
115 |
#else
|
williamr@4
|
116 |
# define _STLP_DIFFERENCE_TYPE(_Iterator) ptrdiff_t
|
williamr@4
|
117 |
#endif
|
williamr@4
|
118 |
|
williamr@4
|
119 |
#ifdef _STLP_CLASS_PARTIAL_SPECIALIZATION
|
williamr@4
|
120 |
|
williamr@4
|
121 |
// fbp : this order keeps gcc happy
|
williamr@4
|
122 |
template <class _Tp>
|
williamr@4
|
123 |
struct iterator_traits<const _Tp*> {
|
williamr@4
|
124 |
typedef random_access_iterator_tag iterator_category;
|
williamr@4
|
125 |
typedef _Tp value_type;
|
williamr@4
|
126 |
typedef ptrdiff_t difference_type;
|
williamr@4
|
127 |
typedef const _Tp* pointer;
|
williamr@4
|
128 |
typedef const _Tp& reference;
|
williamr@4
|
129 |
};
|
williamr@4
|
130 |
|
williamr@4
|
131 |
template <class _Tp>
|
williamr@4
|
132 |
struct iterator_traits<_Tp*> {
|
williamr@4
|
133 |
typedef random_access_iterator_tag iterator_category;
|
williamr@4
|
134 |
typedef _Tp value_type;
|
williamr@4
|
135 |
typedef ptrdiff_t difference_type;
|
williamr@4
|
136 |
typedef _Tp* pointer;
|
williamr@4
|
137 |
typedef _Tp& reference;
|
williamr@4
|
138 |
};
|
williamr@4
|
139 |
|
williamr@4
|
140 |
# if defined (__BORLANDC__)
|
williamr@4
|
141 |
template <class _Tp>
|
williamr@4
|
142 |
struct iterator_traits<_Tp* const> {
|
williamr@4
|
143 |
typedef random_access_iterator_tag iterator_category;
|
williamr@4
|
144 |
typedef _Tp value_type;
|
williamr@4
|
145 |
typedef ptrdiff_t difference_type;
|
williamr@4
|
146 |
typedef const _Tp* pointer;
|
williamr@4
|
147 |
typedef const _Tp& reference;
|
williamr@4
|
148 |
};
|
williamr@4
|
149 |
# endif
|
williamr@4
|
150 |
|
williamr@4
|
151 |
#endif /* _STLP_CLASS_PARTIAL_SPECIALIZATION */
|
williamr@4
|
152 |
|
williamr@4
|
153 |
|
williamr@4
|
154 |
#if defined (_STLP_CLASS_PARTIAL_SPECIALIZATION) || \
|
williamr@4
|
155 |
(defined (_STLP_SIMULATE_PARTIAL_SPEC_FOR_TYPE_TRAITS) && ! defined (_STLP_NO_ARROW_OPERATOR))
|
williamr@4
|
156 |
# define _STLP_POINTERS_SPECIALIZE( _TpP )
|
williamr@4
|
157 |
# define _STLP_DEFINE_ARROW_OPERATOR pointer operator->() const { return &(operator*()); }
|
williamr@4
|
158 |
#else
|
williamr@4
|
159 |
# include <stl/_ptrs_specialize.h>
|
williamr@4
|
160 |
#endif
|
williamr@4
|
161 |
|
williamr@4
|
162 |
#ifndef _STLP_USE_OLD_HP_ITERATOR_QUERIES
|
williamr@4
|
163 |
// The overloaded functions iterator_category, distance_type, and
|
williamr@4
|
164 |
// value_type are not part of the C++ standard. (They have been
|
williamr@4
|
165 |
// replaced by struct iterator_traits.) They are included for
|
williamr@4
|
166 |
// backward compatibility with the HP STL.
|
williamr@4
|
167 |
// We introduce internal names for these functions.
|
williamr@4
|
168 |
|
williamr@4
|
169 |
# ifdef _STLP_CLASS_PARTIAL_SPECIALIZATION
|
williamr@4
|
170 |
|
williamr@4
|
171 |
template <class _Iter>
|
williamr@4
|
172 |
inline typename iterator_traits<_Iter>::iterator_category __iterator_category(const _Iter&) {
|
williamr@4
|
173 |
typedef typename iterator_traits<_Iter>::iterator_category _Category;
|
williamr@4
|
174 |
return _Category();
|
williamr@4
|
175 |
}
|
williamr@4
|
176 |
|
williamr@4
|
177 |
template <class _Iter>
|
williamr@4
|
178 |
inline typename iterator_traits<_Iter>::difference_type* __distance_type(const _Iter&) {
|
williamr@4
|
179 |
typedef typename iterator_traits<_Iter>::difference_type _diff_type;
|
williamr@4
|
180 |
return __STATIC_CAST(_diff_type*,0);
|
williamr@4
|
181 |
}
|
williamr@4
|
182 |
|
williamr@4
|
183 |
template <class _Iter>
|
williamr@4
|
184 |
inline typename iterator_traits<_Iter>::value_type* __value_type(const _Iter&) {
|
williamr@4
|
185 |
typedef typename iterator_traits<_Iter>::value_type _value_type;
|
williamr@4
|
186 |
return __STATIC_CAST(_value_type*,0);
|
williamr@4
|
187 |
}
|
williamr@4
|
188 |
|
williamr@4
|
189 |
# else /* _STLP_CLASS_PARTIAL_SPECIALIZATION */
|
williamr@4
|
190 |
|
williamr@4
|
191 |
template <class _Iter>
|
williamr@4
|
192 |
inline random_access_iterator_tag
|
williamr@4
|
193 |
__iterator_category(const _Iter&, const __true_type&) {
|
williamr@4
|
194 |
return random_access_iterator_tag();
|
williamr@4
|
195 |
}
|
williamr@4
|
196 |
|
williamr@4
|
197 |
template <class _Iter>
|
williamr@4
|
198 |
inline _STLP_TYPENAME_ON_RETURN_TYPE iterator_traits<_Iter>::iterator_category
|
williamr@4
|
199 |
__iterator_category(const _Iter&, const __false_type&) {
|
williamr@4
|
200 |
typedef typename iterator_traits<_Iter>::iterator_category _Category;
|
williamr@4
|
201 |
return _Category();
|
williamr@4
|
202 |
}
|
williamr@4
|
203 |
|
williamr@4
|
204 |
|
williamr@4
|
205 |
template <class _Iter>
|
williamr@4
|
206 |
inline ptrdiff_t* _STLP_CALL __distance_type(const _Iter&) { return __STATIC_CAST(ptrdiff_t*, 0); }
|
williamr@4
|
207 |
|
williamr@4
|
208 |
template <class _Iter>
|
williamr@4
|
209 |
inline _STLP_TYPENAME_ON_RETURN_TYPE iterator_traits<_Iter>::value_type*
|
williamr@4
|
210 |
__value_type(const _Iter&, const __false_type&) {
|
williamr@4
|
211 |
typedef typename iterator_traits<_Iter>::value_type _value_type;
|
williamr@4
|
212 |
return __STATIC_CAST(_value_type*,0);
|
williamr@4
|
213 |
}
|
williamr@4
|
214 |
|
williamr@4
|
215 |
template <class _Tp>
|
williamr@4
|
216 |
inline _Tp*
|
williamr@4
|
217 |
__value_type(const _Tp*, const __true_type&) {
|
williamr@4
|
218 |
return __STATIC_CAST(_Tp*, 0);
|
williamr@4
|
219 |
}
|
williamr@4
|
220 |
|
williamr@4
|
221 |
# endif /* _STLP_CLASS_PARTIAL_SPECIALIZATION */
|
williamr@4
|
222 |
|
williamr@4
|
223 |
#else /* _STLP_USE_OLD_HP_ITERATOR_QUERIES */
|
williamr@4
|
224 |
template <class _Category, class _Tp, class _Distance, class _Pointer, class _Reference>
|
williamr@4
|
225 |
inline _Category _STLP_CALL iterator_category(const iterator<_Category,_Tp,_Distance,_Pointer,_Reference>&) { return _Category(); }
|
williamr@4
|
226 |
template <class _Category, class _Tp, class _Distance, class _Pointer, class _Reference>
|
williamr@4
|
227 |
inline _Tp* _STLP_CALL value_type(const iterator<_Category,_Tp,_Distance,_Pointer,_Reference>&) { return __STATIC_CAST(_Tp*, 0); }
|
williamr@4
|
228 |
template <class _Category, class _Tp, class _Distance, class _Pointer, class _Reference>
|
williamr@4
|
229 |
inline _Distance* _STLP_CALL distance_type(const iterator<_Category,_Tp,_Distance,_Pointer,_Reference>&) { return __STATIC_CAST(_Distance*, 0); }
|
williamr@4
|
230 |
template <class _Tp>
|
williamr@4
|
231 |
inline random_access_iterator_tag _STLP_CALL iterator_category(const _Tp*) { return random_access_iterator_tag(); }
|
williamr@4
|
232 |
template <class _Tp>
|
williamr@4
|
233 |
inline _Tp* _STLP_CALL value_type(const _Tp*) { return __STATIC_CAST(_Tp*, 0); }
|
williamr@4
|
234 |
template <class _Tp>
|
williamr@4
|
235 |
inline ptrdiff_t* _STLP_CALL distance_type(const _Tp*) { return __STATIC_CAST(ptrdiff_t*, 0); }
|
williamr@4
|
236 |
#endif /* _STLP_USE_OLD_HP_ITERATOR_QUERIES */
|
williamr@4
|
237 |
|
williamr@4
|
238 |
# if ! defined (_STLP_NO_ANACHRONISMS)
|
williamr@4
|
239 |
// The base classes input_iterator, output_iterator, forward_iterator,
|
williamr@4
|
240 |
// bidirectional_iterator, and random_access_iterator are not part of
|
williamr@4
|
241 |
// the C++ standard. (They have been replaced by struct iterator.)
|
williamr@4
|
242 |
// They are included for backward compatibility with the HP STL.
|
williamr@4
|
243 |
template <class _Tp, class _Distance> struct input_iterator :
|
williamr@4
|
244 |
public iterator <input_iterator_tag, _Tp, _Distance, _Tp*, _Tp&> {};
|
williamr@4
|
245 |
struct output_iterator : public iterator <output_iterator_tag, void, void, void, void> {};
|
williamr@4
|
246 |
template <class _Tp, class _Distance> struct forward_iterator :
|
williamr@4
|
247 |
public iterator<forward_iterator_tag, _Tp, _Distance, _Tp*, _Tp&> {};
|
williamr@4
|
248 |
template <class _Tp, class _Distance> struct bidirectional_iterator :
|
williamr@4
|
249 |
public iterator<bidirectional_iterator_tag, _Tp, _Distance, _Tp*, _Tp&> {};
|
williamr@4
|
250 |
template <class _Tp, class _Distance> struct random_access_iterator :
|
williamr@4
|
251 |
public iterator<random_access_iterator_tag, _Tp, _Distance, _Tp*, _Tp&> {};
|
williamr@4
|
252 |
|
williamr@4
|
253 |
# if defined (_STLP_BASE_MATCH_BUG) && defined (_STLP_USE_OLD_HP_ITERATOR_QUERIES)
|
williamr@4
|
254 |
template <class _Tp, class _Distance>
|
williamr@4
|
255 |
inline input_iterator_tag _STLP_CALL
|
williamr@4
|
256 |
iterator_category(const input_iterator<_Tp, _Distance>&) { return input_iterator_tag(); }
|
williamr@4
|
257 |
inline output_iterator_tag _STLP_CALL
|
williamr@4
|
258 |
iterator_category(const output_iterator&) { return output_iterator_tag(); }
|
williamr@4
|
259 |
template <class _Tp, class _Distance>
|
williamr@4
|
260 |
inline forward_iterator_tag _STLP_CALL
|
williamr@4
|
261 |
iterator_category(const forward_iterator<_Tp, _Distance>&) { return forward_iterator_tag(); }
|
williamr@4
|
262 |
template <class _Tp, class _Distance>
|
williamr@4
|
263 |
inline bidirectional_iterator_tag _STLP_CALL
|
williamr@4
|
264 |
iterator_category(const bidirectional_iterator<_Tp, _Distance>&) { return bidirectional_iterator_tag(); }
|
williamr@4
|
265 |
template <class _Tp, class _Distance>
|
williamr@4
|
266 |
inline random_access_iterator_tag _STLP_CALL
|
williamr@4
|
267 |
iterator_category(const random_access_iterator<_Tp, _Distance>&) { return random_access_iterator_tag(); }
|
williamr@4
|
268 |
template <class _Tp, class _Distance>
|
williamr@4
|
269 |
inline _Tp* _STLP_CALL value_type(const input_iterator<_Tp, _Distance>&) { return __STATIC_CAST(_Tp*, 0); }
|
williamr@4
|
270 |
template <class _Tp, class _Distance>
|
williamr@4
|
271 |
inline _Tp* _STLP_CALL value_type(const forward_iterator<_Tp, _Distance>&) { return __STATIC_CAST(_Tp*, 0); }
|
williamr@4
|
272 |
template <class _Tp, class _Distance>
|
williamr@4
|
273 |
inline _Tp* _STLP_CALL value_type(const bidirectional_iterator<_Tp, _Distance>&) { return __STATIC_CAST(_Tp*, 0); }
|
williamr@4
|
274 |
template <class _Tp, class _Distance>
|
williamr@4
|
275 |
inline _Tp* _STLP_CALL value_type(const random_access_iterator<_Tp, _Distance>&) { return __STATIC_CAST(_Tp*, 0); }
|
williamr@4
|
276 |
template <class _Tp, class _Distance>
|
williamr@4
|
277 |
inline _Distance* _STLP_CALL distance_type(const input_iterator<_Tp, _Distance>&) { return __STATIC_CAST(_Distance*, 0); }
|
williamr@4
|
278 |
template <class _Tp, class _Distance>
|
williamr@4
|
279 |
inline _Distance* _STLP_CALL distance_type(const forward_iterator<_Tp, _Distance>&) { return __STATIC_CAST(_Distance*, 0); }
|
williamr@4
|
280 |
template <class _Tp, class _Distance>
|
williamr@4
|
281 |
inline _Distance* _STLP_CALL distance_type(const bidirectional_iterator<_Tp, _Distance>&) { return __STATIC_CAST(_Distance*, 0);}
|
williamr@4
|
282 |
template <class _Tp, class _Distance>
|
williamr@4
|
283 |
inline _Distance* _STLP_CALL distance_type(const random_access_iterator<_Tp, _Distance>&) { return __STATIC_CAST(_Distance*, 0); }
|
williamr@4
|
284 |
# endif /* BASE_MATCH */
|
williamr@4
|
285 |
|
williamr@4
|
286 |
#endif /* _STLP_NO_ANACHRONISMS */
|
williamr@4
|
287 |
|
williamr@4
|
288 |
template <class _InputIterator, class _Distance>
|
williamr@4
|
289 |
inline void _STLP_CALL __distance(const _InputIterator& __first, const _InputIterator& __last,
|
williamr@4
|
290 |
_Distance& __n, const input_iterator_tag &) {
|
williamr@4
|
291 |
_InputIterator __it(__first);
|
williamr@4
|
292 |
while (__it != __last) { ++__it; ++__n; }
|
williamr@4
|
293 |
}
|
williamr@4
|
294 |
|
williamr@4
|
295 |
|
williamr@4
|
296 |
# if defined (_STLP_NONTEMPL_BASE_MATCH_BUG)
|
williamr@4
|
297 |
template <class _ForwardIterator, class _Distance>
|
williamr@4
|
298 |
inline void _STLP_CALL __distance(const _ForwardIterator& __first, const _ForwardIterator& __last,
|
williamr@4
|
299 |
_Distance& __n, const forward_iterator_tag &) {
|
williamr@4
|
300 |
_ForwardIterator __it(__first);
|
williamr@4
|
301 |
while (__it != __last) { ++__first; ++__n; }
|
williamr@4
|
302 |
}
|
williamr@4
|
303 |
|
williamr@4
|
304 |
template <class _BidirectionalIterator, class _Distance>
|
williamr@4
|
305 |
_STLP_INLINE_LOOP void _STLP_CALL __distance(const _BidirectionalIterator& __first,
|
williamr@4
|
306 |
const _BidirectionalIterator& __last,
|
williamr@4
|
307 |
_Distance& __n, const bidirectional_iterator_tag &) {
|
williamr@4
|
308 |
_BidirectionalIterator __it(__first);
|
williamr@4
|
309 |
while (__it != __last) { ++__it; ++__n; }
|
williamr@4
|
310 |
}
|
williamr@4
|
311 |
# endif
|
williamr@4
|
312 |
|
williamr@4
|
313 |
template <class _RandomAccessIterator, class _Distance>
|
williamr@4
|
314 |
inline void _STLP_CALL __distance(const _RandomAccessIterator& __first,
|
williamr@4
|
315 |
const _RandomAccessIterator& __last,
|
williamr@4
|
316 |
_Distance& __n, const random_access_iterator_tag &) {
|
williamr@4
|
317 |
__n += __last - __first;
|
williamr@4
|
318 |
}
|
williamr@4
|
319 |
|
williamr@4
|
320 |
#ifndef _STLP_NO_ANACHRONISMS
|
williamr@4
|
321 |
template <class _InputIterator, class _Distance>
|
williamr@4
|
322 |
inline void _STLP_CALL distance(const _InputIterator& __first,
|
williamr@4
|
323 |
const _InputIterator& __last, _Distance& __n) {
|
williamr@4
|
324 |
__distance(__first, __last, __n, _STLP_ITERATOR_CATEGORY(__first, _InputIterator));
|
williamr@4
|
325 |
}
|
williamr@4
|
326 |
#endif
|
williamr@4
|
327 |
|
williamr@4
|
328 |
template <class _InputIterator>
|
williamr@4
|
329 |
inline _STLP_DIFFERENCE_TYPE(_InputIterator) _STLP_CALL
|
williamr@4
|
330 |
__distance(const _InputIterator& __first, const _InputIterator& __last, const input_iterator_tag &) {
|
williamr@4
|
331 |
_STLP_DIFFERENCE_TYPE(_InputIterator) __n = 0;
|
williamr@4
|
332 |
_InputIterator __it(__first);
|
williamr@4
|
333 |
while (__it != __last) {
|
williamr@4
|
334 |
++__it; ++__n;
|
williamr@4
|
335 |
}
|
williamr@4
|
336 |
return __n;
|
williamr@4
|
337 |
}
|
williamr@4
|
338 |
|
williamr@4
|
339 |
# if defined (_STLP_NONTEMPL_BASE_MATCH_BUG)
|
williamr@4
|
340 |
template <class _ForwardIterator>
|
williamr@4
|
341 |
inline _STLP_DIFFERENCE_TYPE(_ForwardIterator) _STLP_CALL
|
williamr@4
|
342 |
__distance(const _ForwardIterator& __first, const _ForwardIterator& __last,
|
williamr@4
|
343 |
const forward_iterator_tag &)
|
williamr@4
|
344 |
{
|
williamr@4
|
345 |
_STLP_DIFFERENCE_TYPE(_ForwardIterator) __n = 0;
|
williamr@4
|
346 |
_ForwardIterator __it(__first);
|
williamr@4
|
347 |
while (__it != __last) {
|
williamr@4
|
348 |
++__it; ++__n;
|
williamr@4
|
349 |
}
|
williamr@4
|
350 |
return __n;
|
williamr@4
|
351 |
|
williamr@4
|
352 |
}
|
williamr@4
|
353 |
|
williamr@4
|
354 |
template <class _BidirectionalIterator>
|
williamr@4
|
355 |
_STLP_INLINE_LOOP _STLP_DIFFERENCE_TYPE(_BidirectionalIterator) _STLP_CALL
|
williamr@4
|
356 |
__distance(const _BidirectionalIterator& __first,
|
williamr@4
|
357 |
const _BidirectionalIterator& __last,
|
williamr@4
|
358 |
const bidirectional_iterator_tag &) {
|
williamr@4
|
359 |
_STLP_DIFFERENCE_TYPE(_BidirectionalIterator) __n = 0;
|
williamr@4
|
360 |
_BidirectionalIterator __it(__first);
|
williamr@4
|
361 |
while (__it != __last) {
|
williamr@4
|
362 |
++__it; ++__n;
|
williamr@4
|
363 |
}
|
williamr@4
|
364 |
return __n;
|
williamr@4
|
365 |
}
|
williamr@4
|
366 |
# endif
|
williamr@4
|
367 |
|
williamr@4
|
368 |
template <class _RandomAccessIterator>
|
williamr@4
|
369 |
inline _STLP_DIFFERENCE_TYPE(_RandomAccessIterator) _STLP_CALL
|
williamr@4
|
370 |
__distance(const _RandomAccessIterator& __first, const _RandomAccessIterator& __last,
|
williamr@4
|
371 |
const random_access_iterator_tag &) {
|
williamr@4
|
372 |
return __last - __first;
|
williamr@4
|
373 |
}
|
williamr@4
|
374 |
|
williamr@4
|
375 |
template <class _InputIterator>
|
williamr@4
|
376 |
inline _STLP_DIFFERENCE_TYPE(_InputIterator) _STLP_CALL
|
williamr@4
|
377 |
distance(_InputIterator __first, _InputIterator __last) {
|
williamr@4
|
378 |
return __distance(__first, __last, _STLP_ITERATOR_CATEGORY(__first, _InputIterator));
|
williamr@4
|
379 |
}
|
williamr@4
|
380 |
|
williamr@4
|
381 |
// fbp: those are being used for iterator/const_iterator definitions everywhere
|
williamr@4
|
382 |
template <class _Tp>
|
williamr@4
|
383 |
struct _Nonconst_traits;
|
williamr@4
|
384 |
|
williamr@4
|
385 |
template <class _Tp>
|
williamr@4
|
386 |
struct _Const_traits {
|
williamr@4
|
387 |
typedef _Tp value_type;
|
williamr@4
|
388 |
typedef const _Tp& reference;
|
williamr@4
|
389 |
typedef const _Tp* pointer;
|
williamr@4
|
390 |
typedef _Const_traits<_Tp> _ConstTraits;
|
williamr@4
|
391 |
typedef _Nonconst_traits<_Tp> _NonConstTraits;
|
williamr@4
|
392 |
};
|
williamr@4
|
393 |
|
williamr@4
|
394 |
template <class _Tp>
|
williamr@4
|
395 |
struct _Nonconst_traits {
|
williamr@4
|
396 |
typedef _Tp value_type;
|
williamr@4
|
397 |
typedef _Tp& reference;
|
williamr@4
|
398 |
typedef _Tp* pointer;
|
williamr@4
|
399 |
typedef _Const_traits<_Tp> _ConstTraits;
|
williamr@4
|
400 |
typedef _Nonconst_traits<_Tp> _NonConstTraits;
|
williamr@4
|
401 |
};
|
williamr@4
|
402 |
|
williamr@4
|
403 |
/*
|
williamr@4
|
404 |
* dums: A special iterator/const_iterator traits for set and multiset for which even
|
williamr@4
|
405 |
* the iterator is not mutable
|
williamr@4
|
406 |
*/
|
williamr@4
|
407 |
template <class _Tp>
|
williamr@4
|
408 |
struct _Nonconst_Const_traits;
|
williamr@4
|
409 |
|
williamr@4
|
410 |
template <class _Tp>
|
williamr@4
|
411 |
struct _Const_Const_traits {
|
williamr@4
|
412 |
typedef _Tp value_type;
|
williamr@4
|
413 |
typedef const _Tp& reference;
|
williamr@4
|
414 |
typedef const _Tp* pointer;
|
williamr@4
|
415 |
typedef _Const_Const_traits<_Tp> _ConstTraits;
|
williamr@4
|
416 |
typedef _Nonconst_Const_traits<_Tp> _NonConstTraits;
|
williamr@4
|
417 |
};
|
williamr@4
|
418 |
|
williamr@4
|
419 |
template <class _Tp>
|
williamr@4
|
420 |
struct _Nonconst_Const_traits {
|
williamr@4
|
421 |
typedef _Tp value_type;
|
williamr@4
|
422 |
typedef const _Tp& reference;
|
williamr@4
|
423 |
typedef const _Tp* pointer;
|
williamr@4
|
424 |
typedef _Const_Const_traits<_Tp> _ConstTraits;
|
williamr@4
|
425 |
typedef _Nonconst_Const_traits<_Tp> _NonConstTraits;
|
williamr@4
|
426 |
};
|
williamr@4
|
427 |
|
williamr@4
|
428 |
/*
|
williamr@4
|
429 |
* A macro to generate a new iterator traits from one of the
|
williamr@4
|
430 |
* previous one. Changing the iterator traits type make iterators
|
williamr@4
|
431 |
* from different containers not comparable.
|
williamr@4
|
432 |
*/
|
williamr@4
|
433 |
#define _STLP_CREATE_ITERATOR_TRAITS_BASE(Motif, Traits) \
|
williamr@4
|
434 |
template <class _Tp> \
|
williamr@4
|
435 |
struct _##Motif; \
|
williamr@4
|
436 |
template <class _Tp> \
|
williamr@4
|
437 |
struct _Const##Motif : public _STLP_STD::_Const_##Traits<_Tp> { \
|
williamr@4
|
438 |
typedef _Const##Motif<_Tp> _ConstTraits; \
|
williamr@4
|
439 |
typedef _##Motif<_Tp> _NonConstTraits; \
|
williamr@4
|
440 |
}; \
|
williamr@4
|
441 |
template <class _Tp> \
|
williamr@4
|
442 |
struct _##Motif : public _STLP_STD::_Nonconst_##Traits<_Tp> { \
|
williamr@4
|
443 |
typedef _Const##Motif<_Tp> _ConstTraits; \
|
williamr@4
|
444 |
typedef _##Motif<_Tp> _NonConstTraits; \
|
williamr@4
|
445 |
};
|
williamr@4
|
446 |
|
williamr@4
|
447 |
#define _STLP_CREATE_ITERATOR_TRAITS(Motif, Traits) \
|
williamr@4
|
448 |
_STLP_MOVE_TO_PRIV_NAMESPACE \
|
williamr@4
|
449 |
_STLP_CREATE_ITERATOR_TRAITS_BASE(Motif, Traits) \
|
williamr@4
|
450 |
_STLP_MOVE_TO_STD_NAMESPACE
|
williamr@4
|
451 |
|
williamr@4
|
452 |
#define _STLP_CREATE_HASH_ITERATOR_TRAITS(Motif, Traits) \
|
williamr@4
|
453 |
_STLP_MOVE_TO_PRIV_NAMESPACE \
|
williamr@4
|
454 |
_STLP_CREATE_ITERATOR_TRAITS_BASE(NonLocal##Motif, Traits) \
|
williamr@4
|
455 |
_STLP_CREATE_ITERATOR_TRAITS_BASE(Local##Motif, Traits) \
|
williamr@4
|
456 |
template <class _Tp> \
|
williamr@4
|
457 |
struct _##Motif { \
|
williamr@4
|
458 |
typedef _ConstNonLocal##Motif<_Tp> _ConstTraits; \
|
williamr@4
|
459 |
typedef _NonLocal##Motif<_Tp> _NonConstTraits; \
|
williamr@4
|
460 |
typedef _ConstLocal##Motif<_Tp> _ConstLocalTraits; \
|
williamr@4
|
461 |
typedef _Local##Motif<_Tp> _NonConstLocalTraits; \
|
williamr@4
|
462 |
}; \
|
williamr@4
|
463 |
_STLP_MOVE_TO_STD_NAMESPACE
|
williamr@4
|
464 |
|
williamr@4
|
465 |
/*
|
williamr@4
|
466 |
# if defined (_STLP_BASE_TYPEDEF_BUG)
|
williamr@4
|
467 |
// this workaround is needed for SunPro 4.0.1
|
williamr@4
|
468 |
template <class _Traits>
|
williamr@4
|
469 |
struct __cnst_traits_aux : private _Traits {
|
williamr@4
|
470 |
typedef typename _Traits::value_type value_type;
|
williamr@4
|
471 |
};
|
williamr@4
|
472 |
# define __TRAITS_VALUE_TYPE(_Traits) __cnst_traits_aux<_Traits>::value_type
|
williamr@4
|
473 |
# else
|
williamr@4
|
474 |
# define __TRAITS_VALUE_TYPE(_Traits) _Traits::value_type
|
williamr@4
|
475 |
# endif
|
williamr@4
|
476 |
*/
|
williamr@4
|
477 |
|
williamr@4
|
478 |
#if defined (_STLP_MSVC)
|
williamr@4
|
479 |
// MSVC specific
|
williamr@4
|
480 |
template <class _InputIterator, class _Dist>
|
williamr@4
|
481 |
inline void _STLP_CALL _Distance(_InputIterator __first,
|
williamr@4
|
482 |
_InputIterator __last, _Dist& __n) {
|
williamr@4
|
483 |
__distance(__first, __last, __n, _STLP_ITERATOR_CATEGORY(__first, _InputIterator));
|
williamr@4
|
484 |
}
|
williamr@4
|
485 |
#endif
|
williamr@4
|
486 |
|
williamr@4
|
487 |
template <class _InputIter, class _Distance>
|
williamr@4
|
488 |
_STLP_INLINE_LOOP void _STLP_CALL
|
williamr@4
|
489 |
__advance(_InputIter& __i, _Distance __n, const input_iterator_tag &) {
|
williamr@4
|
490 |
while (__n--) ++__i;
|
williamr@4
|
491 |
}
|
williamr@4
|
492 |
|
williamr@4
|
493 |
// fbp : added output iterator tag variant
|
williamr@4
|
494 |
template <class _InputIter, class _Distance>
|
williamr@4
|
495 |
_STLP_INLINE_LOOP void _STLP_CALL
|
williamr@4
|
496 |
__advance(_InputIter& __i, _Distance __n, const output_iterator_tag &) {
|
williamr@4
|
497 |
while (__n--) ++__i;
|
williamr@4
|
498 |
}
|
williamr@4
|
499 |
|
williamr@4
|
500 |
#if defined (_STLP_NONTEMPL_BASE_MATCH_BUG)
|
williamr@4
|
501 |
template <class _ForwardIterator, class _Distance>
|
williamr@4
|
502 |
_STLP_INLINE_LOOP void _STLP_CALL
|
williamr@4
|
503 |
__advance(_ForwardIterator& i, _Distance n, const forward_iterator_tag &) {
|
williamr@4
|
504 |
while (n--) ++i;
|
williamr@4
|
505 |
}
|
williamr@4
|
506 |
#endif
|
williamr@4
|
507 |
|
williamr@4
|
508 |
template <class _BidirectionalIterator, class _Distance>
|
williamr@4
|
509 |
_STLP_INLINE_LOOP void _STLP_CALL
|
williamr@4
|
510 |
__advance(_BidirectionalIterator& __i, _Distance __n,
|
williamr@4
|
511 |
const bidirectional_iterator_tag &) {
|
williamr@4
|
512 |
if (__n > 0)
|
williamr@4
|
513 |
while (__n--) ++__i;
|
williamr@4
|
514 |
else
|
williamr@4
|
515 |
while (__n++) --__i;
|
williamr@4
|
516 |
}
|
williamr@4
|
517 |
|
williamr@4
|
518 |
template <class _RandomAccessIterator, class _Distance>
|
williamr@4
|
519 |
inline void _STLP_CALL
|
williamr@4
|
520 |
__advance(_RandomAccessIterator& __i, _Distance __n,
|
williamr@4
|
521 |
const random_access_iterator_tag &) {
|
williamr@4
|
522 |
__i += __n;
|
williamr@4
|
523 |
}
|
williamr@4
|
524 |
|
williamr@4
|
525 |
template <class _InputIterator, class _Distance>
|
williamr@4
|
526 |
inline void _STLP_CALL advance(_InputIterator& __i, _Distance __n) {
|
williamr@4
|
527 |
__advance(__i, __n, _STLP_ITERATOR_CATEGORY(__i, _InputIterator));
|
williamr@4
|
528 |
}
|
williamr@4
|
529 |
|
williamr@4
|
530 |
_STLP_END_NAMESPACE
|
williamr@4
|
531 |
|
williamr@4
|
532 |
#if defined (_STLP_DEBUG) && !defined (_STLP_DEBUG_H)
|
williamr@4
|
533 |
# include <stl/debug/_debug.h>
|
williamr@4
|
534 |
#endif
|
williamr@4
|
535 |
|
williamr@4
|
536 |
#endif /* _STLP_INTERNAL_ITERATOR_BASE_H */
|
williamr@4
|
537 |
|
williamr@4
|
538 |
|
williamr@4
|
539 |
// Local Variables:
|
williamr@4
|
540 |
// mode:C++
|
williamr@4
|
541 |
// End:
|