Attempt to represent the S^2->S^3 header reorganisation as a series of "hg rename" operations
4 * Hewlett-Packard Company
6 * Copyright (c) 1996-1998
7 * Silicon Graphics Computer Systems, Inc.
10 * Moscow Center for SPARC Technology
15 * This material is provided "as is", with absolutely no warranty expressed
16 * or implied. Any use is at your own risk.
18 * Permission to use or copy this software for any purpose is hereby granted
19 * without fee, provided the above notices are retained on all copies.
20 * Permission to modify the code and to distribute modified code is granted,
21 * provided the above notices are retained, and a notice that the code was
22 * modified is included with the above copyright notice.
26 /* NOTE: This is an internal header file, included by other STL headers.
27 * You should not attempt to use it directly.
30 #ifndef _STLP_INTERNAL_ITERATOR_BASE_H
31 #define _STLP_INTERNAL_ITERATOR_BASE_H
37 # if defined (_STLP_IMPORT_VENDOR_CSTD) && ! defined (_STLP_VENDOR_GLOBAL_CSTD)
39 using namespace _STLP_VENDOR_CSTD;
41 #endif /* _STLP_IMPORT_VENDOR_CSTD */
43 #ifndef __TYPE_TRAITS_H
44 # include <stl/type_traits.h>
49 struct input_iterator_tag {};
50 struct output_iterator_tag {};
51 struct forward_iterator_tag : public input_iterator_tag {};
52 struct bidirectional_iterator_tag : public forward_iterator_tag {};
53 struct random_access_iterator_tag : public bidirectional_iterator_tag {};
56 template <class _Category, class _Tp, __DFL_TMPL_PARAM(_Distance,ptrdiff_t),
57 __DFL_TMPL_PARAM(_Pointer,_Tp*), __DFL_TMPL_PARAM(_Reference,_Tp&) >
59 typedef _Category iterator_category;
60 typedef _Tp value_type;
61 typedef _Distance difference_type;
62 typedef _Pointer pointer;
63 typedef _Reference reference;
66 struct iterator<output_iterator_tag, void, void, void, void> {
67 typedef output_iterator_tag iterator_category;
68 #ifdef _STLP_CLASS_PARTIAL_SPECIALIZATION
69 typedef void value_type;
70 typedef void difference_type;
72 typedef void reference;
76 # ifdef _STLP_USE_OLD_HP_ITERATOR_QUERIES
77 # define _STLP_ITERATOR_CATEGORY(_It, _Tp) iterator_category(_It)
78 # define _STLP_DISTANCE_TYPE(_It, _Tp) distance_type(_It)
79 # define _STLP_VALUE_TYPE(_It, _Tp) value_type(_It)
81 # ifdef _STLP_CLASS_PARTIAL_SPECIALIZATION
82 # define _STLP_VALUE_TYPE(_It, _Tp) (typename iterator_traits< _Tp >::value_type*)0
83 # define _STLP_DISTANCE_TYPE(_It, _Tp) (typename iterator_traits< _Tp >::difference_type*)0
84 # if defined (__BORLANDC__) || defined (__SUNPRO_CC) || ( defined (__MWERKS__) && (__MWERKS__ <= 0x2303)) || ( defined (__sgi) && defined (_COMPILER_VERSION)) || defined (__DMC__)
85 # define _STLP_ITERATOR_CATEGORY(_It, _Tp) iterator_traits< _Tp >::iterator_category()
87 # define _STLP_ITERATOR_CATEGORY(_It, _Tp) typename iterator_traits< _Tp >::iterator_category()
90 # define _STLP_ITERATOR_CATEGORY(_It, _Tp) __iterator_category(_It, _IsPtrType<_Tp>::_Ret())
91 # define _STLP_DISTANCE_TYPE(_It, _Tp) (ptrdiff_t*)0
92 # define _STLP_VALUE_TYPE(_It, _Tp) __value_type(_It, _IsPtrType<_Tp>::_Ret() )
96 template <class _Iterator>
97 struct iterator_traits {
98 typedef typename _Iterator::iterator_category iterator_category;
99 typedef typename _Iterator::value_type value_type;
100 typedef typename _Iterator::difference_type difference_type;
101 typedef typename _Iterator::pointer pointer;
102 typedef typename _Iterator::reference reference;
106 # if defined (_STLP_CLASS_PARTIAL_SPECIALIZATION) && ! defined (__SUNPRO_CC)
107 # define _STLP_DIFFERENCE_TYPE(_Iterator) typename iterator_traits<_Iterator>::difference_type
109 # define _STLP_DIFFERENCE_TYPE(_Iterator) ptrdiff_t
112 # ifdef _STLP_CLASS_PARTIAL_SPECIALIZATION
114 // fbp : this order keeps gcc happy
116 struct iterator_traits<const _Tp*> {
117 typedef random_access_iterator_tag iterator_category;
118 typedef _Tp value_type;
119 typedef ptrdiff_t difference_type;
120 typedef const _Tp* pointer;
121 typedef const _Tp& reference;
125 struct iterator_traits<_Tp*> {
126 typedef random_access_iterator_tag iterator_category;
127 typedef _Tp value_type;
128 typedef ptrdiff_t difference_type;
129 typedef _Tp* pointer;
130 typedef _Tp& reference;
133 # if defined (__BORLANDC__)
135 struct iterator_traits<_Tp* const> {
136 typedef random_access_iterator_tag iterator_category;
137 typedef _Tp value_type;
138 typedef ptrdiff_t difference_type;
139 typedef const _Tp* pointer;
140 typedef const _Tp& reference;
144 # endif /* _STLP_CLASS_PARTIAL_SPECIALIZATION */
147 # if defined (_STLP_CLASS_PARTIAL_SPECIALIZATION) \
148 || (defined (_STLP_SIMULATE_PARTIAL_SPEC_FOR_TYPE_TRAITS) && ! defined (_STLP_NO_ARROW_OPERATOR))
149 # define _STLP_POINTERS_SPECIALIZE( _TpP )
150 # define _STLP_DEFINE_ARROW_OPERATOR pointer operator->() const { return &(operator*()); }
152 # include <stl/_ptrs_specialize.h>
155 # ifndef _STLP_USE_OLD_HP_ITERATOR_QUERIES
156 // The overloaded functions iterator_category, distance_type, and
157 // value_type are not part of the C++ standard. (They have been
158 // replaced by struct iterator_traits.) They are included for
159 // backward compatibility with the HP STL.
160 // We introduce internal names for these functions.
162 # ifdef _STLP_CLASS_PARTIAL_SPECIALIZATION
164 template <class _Iter>
165 inline typename iterator_traits<_Iter>::iterator_category __iterator_category(const _Iter&) {
166 typedef typename iterator_traits<_Iter>::iterator_category _Category;
170 template <class _Iter>
171 inline typename iterator_traits<_Iter>::difference_type* __distance_type(const _Iter&) {
172 typedef typename iterator_traits<_Iter>::difference_type _diff_type;
173 return __STATIC_CAST(_diff_type*,0);
176 template <class _Iter>
177 inline typename iterator_traits<_Iter>::value_type* __value_type(const _Iter&) {
178 typedef typename iterator_traits<_Iter>::value_type _value_type;
179 return __STATIC_CAST(_value_type*,0);
184 template <class _Iter>
185 inline random_access_iterator_tag
186 __iterator_category(const _Iter&, const __true_type&) {
187 return random_access_iterator_tag();
190 template <class _Iter>
191 inline _STLP_TYPENAME_ON_RETURN_TYPE iterator_traits<_Iter>::iterator_category
192 __iterator_category(const _Iter&, const __false_type&) {
193 typedef typename iterator_traits<_Iter>::iterator_category _Category;
198 template <class _Iter>
199 inline ptrdiff_t* _STLP_CALL __distance_type(const _Iter&) { return (ptrdiff_t*)(0); }
201 template <class _Iter>
202 inline _STLP_TYPENAME_ON_RETURN_TYPE iterator_traits<_Iter>::value_type*
203 __value_type(const _Iter&, const __false_type&) {
204 typedef typename iterator_traits<_Iter>::value_type _value_type;
205 return __STATIC_CAST(_value_type*,0);
210 __value_type(const _Tp*, const __true_type&) {
211 return __STATIC_CAST(_Tp*, 0);
216 #else /* old queries */
217 template <class _Category, class _Tp, class _Distance, class _Pointer, class _Reference>
218 inline _Category _STLP_CALL iterator_category(const iterator<_Category,_Tp,_Distance,_Pointer,_Reference>&) { return _Category(); }
219 template <class _Category, class _Tp, class _Distance, class _Pointer, class _Reference>
220 inline _Tp* _STLP_CALL value_type(const iterator<_Category,_Tp,_Distance,_Pointer,_Reference>&) { return (_Tp*)(0); }
221 template <class _Category, class _Tp, class _Distance, class _Pointer, class _Reference>
222 inline _Distance* _STLP_CALL distance_type(const iterator<_Category,_Tp,_Distance,_Pointer,_Reference>&) { return (_Distance*)(0); }
224 inline random_access_iterator_tag _STLP_CALL iterator_category(const _Tp*) { return random_access_iterator_tag(); }
226 inline _Tp* _STLP_CALL value_type(const _Tp*) { return (_Tp*)(0); }
228 inline ptrdiff_t* _STLP_CALL distance_type(const _Tp*) { return (ptrdiff_t*)(0); }
229 #endif /* _STLP_USE_OLD_HP_ITERATOR_QUERIES */
231 # if ! defined (_STLP_NO_ANACHRONISMS)
232 // The base classes input_iterator, output_iterator, forward_iterator,
233 // bidirectional_iterator, and random_access_iterator are not part of
234 // the C++ standard. (They have been replaced by struct iterator.)
235 // They are included for backward compatibility with the HP STL.
236 template <class _Tp, class _Distance> struct input_iterator :
237 public iterator <input_iterator_tag, _Tp, _Distance, _Tp*, _Tp&> {};
238 struct output_iterator : public iterator <output_iterator_tag, void, void, void, void> {};
239 template <class _Tp, class _Distance> struct forward_iterator :
240 public iterator<forward_iterator_tag, _Tp, _Distance, _Tp*, _Tp&> {};
241 template <class _Tp, class _Distance> struct bidirectional_iterator :
242 public iterator<bidirectional_iterator_tag, _Tp, _Distance, _Tp*, _Tp&> {};
243 template <class _Tp, class _Distance> struct random_access_iterator :
244 public iterator<random_access_iterator_tag, _Tp, _Distance, _Tp*, _Tp&> {};
246 # if defined (_STLP_BASE_MATCH_BUG) && defined (_STLP_USE_OLD_HP_ITERATOR_QUERIES)
247 template <class _Tp, class _Distance>
248 inline input_iterator_tag _STLP_CALL
249 iterator_category(const input_iterator<_Tp, _Distance>&) { return input_iterator_tag(); }
250 inline output_iterator_tag _STLP_CALL
251 iterator_category(const output_iterator&) { return output_iterator_tag(); }
252 template <class _Tp, class _Distance>
253 inline forward_iterator_tag _STLP_CALL
254 iterator_category(const forward_iterator<_Tp, _Distance>&) { return forward_iterator_tag(); }
255 template <class _Tp, class _Distance>
256 inline bidirectional_iterator_tag _STLP_CALL
257 iterator_category(const bidirectional_iterator<_Tp, _Distance>&) { return bidirectional_iterator_tag(); }
258 template <class _Tp, class _Distance>
259 inline random_access_iterator_tag _STLP_CALL
260 iterator_category(const random_access_iterator<_Tp, _Distance>&) { return random_access_iterator_tag(); }
261 template <class _Tp, class _Distance>
262 inline _Tp* _STLP_CALL value_type(const input_iterator<_Tp, _Distance>&) { return (_Tp*)(0); }
263 template <class _Tp, class _Distance>
264 inline _Tp* _STLP_CALL value_type(const forward_iterator<_Tp, _Distance>&) { return (_Tp*)(0); }
265 template <class _Tp, class _Distance>
266 inline _Tp* _STLP_CALL value_type(const bidirectional_iterator<_Tp, _Distance>&) { return (_Tp*)(0); }
267 template <class _Tp, class _Distance>
268 inline _Tp* _STLP_CALL value_type(const random_access_iterator<_Tp, _Distance>&) { return (_Tp*)(0); }
269 template <class _Tp, class _Distance>
270 inline _Distance* _STLP_CALL distance_type(const input_iterator<_Tp, _Distance>&) { return (_Distance*)(0); }
271 template <class _Tp, class _Distance>
272 inline _Distance* _STLP_CALL distance_type(const forward_iterator<_Tp, _Distance>&) { return (_Distance*)(0); }
273 template <class _Tp, class _Distance>
274 inline _Distance* _STLP_CALL distance_type(const bidirectional_iterator<_Tp, _Distance>&) { return (_Distance*)(0);}
275 template <class _Tp, class _Distance>
276 inline _Distance* _STLP_CALL distance_type(const random_access_iterator<_Tp, _Distance>&) { return (_Distance*)(0); }
277 # endif /* BASE_MATCH */
279 #endif /* _STLP_NO_ANACHRONISMS */
281 template <class _InputIterator, class _Distance>
282 inline void _STLP_CALL __distance(const _InputIterator& __first, const _InputIterator& __last,
283 _Distance& __n, const input_iterator_tag &) {
284 _InputIterator __it(__first);
285 while (__it != __last) { ++__it; ++__n; }
288 # if defined (_STLP_NONTEMPL_BASE_MATCH_BUG)
289 template <class _ForwardIterator, class _Distance>
290 inline void _STLP_CALL __distance(const _ForwardIterator& __first, const _ForwardIterator& __last,
291 _Distance& __n, const forward_iterator_tag &) {
292 _ForwardIterator __it(__first);
293 while (__it != __last) { ++__first; ++__n; }
296 template <class _BidirectionalIterator, class _Distance>
297 _STLP_INLINE_LOOP void _STLP_CALL __distance(const _BidirectionalIterator& __first,
298 const _BidirectionalIterator& __last,
299 _Distance& __n, const bidirectional_iterator_tag &) {
300 _BidirectionalIterator __it(__first);
301 while (__it != __last) { ++__it; ++__n; }
305 template <class _RandomAccessIterator, class _Distance>
306 inline void _STLP_CALL __distance(const _RandomAccessIterator& __first,
307 const _RandomAccessIterator& __last,
308 _Distance& __n, const random_access_iterator_tag &) {
309 __n += __last - __first;
312 #ifndef _STLP_NO_ANACHRONISMS
313 template <class _InputIterator, class _Distance>
314 inline void _STLP_CALL distance(const _InputIterator& __first,
315 const _InputIterator& __last, _Distance& __n) {
316 __distance(__first, __last, __n, _STLP_ITERATOR_CATEGORY(__first, _InputIterator));
320 template <class _InputIterator>
321 inline _STLP_DIFFERENCE_TYPE(_InputIterator) _STLP_CALL
322 __distance(const _InputIterator& __first, const _InputIterator& __last, const input_iterator_tag &) {
323 _STLP_DIFFERENCE_TYPE(_InputIterator) __n = 0;
324 _InputIterator __it(__first);
325 while (__it != __last) {
331 # if defined (_STLP_NONTEMPL_BASE_MATCH_BUG)
332 template <class _ForwardIterator>
333 inline _STLP_DIFFERENCE_TYPE(_ForwardIterator) _STLP_CALL
334 __distance(const _ForwardIterator& __first, const _ForwardIterator& __last,
335 const forward_iterator_tag &)
337 _STLP_DIFFERENCE_TYPE(_ForwardIterator) __n = 0;
338 _ForwardIterator __it(__first);
339 while (__it != __last) {
345 template <class _BidirectionalIterator>
346 _STLP_INLINE_LOOP _STLP_DIFFERENCE_TYPE(_BidirectionalIterator) _STLP_CALL
347 __distance(const _BidirectionalIterator& __first,
348 const _BidirectionalIterator& __last,
349 const bidirectional_iterator_tag &) {
350 _STLP_DIFFERENCE_TYPE(_BidirectionalIterator) __n = 0;
351 _BidirectionalIterator __it(__first);
352 while (__it != __last) {
359 template <class _RandomAccessIterator>
360 inline _STLP_DIFFERENCE_TYPE(_RandomAccessIterator) _STLP_CALL
361 __distance(const _RandomAccessIterator& __first, const _RandomAccessIterator& __last,
362 const random_access_iterator_tag &) {
363 return __last - __first;
366 template <class _InputIterator>
367 inline _STLP_DIFFERENCE_TYPE(_InputIterator) _STLP_CALL
368 distance(const _InputIterator& __first, const _InputIterator& __last) {
369 return __distance(__first, __last, _STLP_ITERATOR_CATEGORY(__first, _InputIterator));
373 // fbp: those are being used for iterator/const_iterator definitions everywhere
375 struct _Nonconst_traits;
378 struct _Const_traits {
379 typedef _Tp value_type;
380 typedef const _Tp& reference;
381 typedef const _Tp* pointer;
382 typedef _Nonconst_traits<_Tp> _Non_const_traits;
386 struct _Nonconst_traits {
387 typedef _Tp value_type;
388 typedef _Tp& reference;
389 typedef _Tp* pointer;
390 typedef _Nonconst_traits<_Tp> _Non_const_traits;
393 # if defined (_STLP_BASE_TYPEDEF_BUG)
394 // this workaround is needed for SunPro 4.0.1
395 template <class _Traits>
396 struct __cnst_traits_aux : private _Traits
398 typedef typename _Traits::value_type value_type;
400 # define __TRAITS_VALUE_TYPE(_Traits) __cnst_traits_aux<_Traits>::value_type
402 # define __TRAITS_VALUE_TYPE(_Traits) _Traits::value_type
405 # if defined (_STLP_MSVC)
407 template <class _InputIterator, class _Dist>
408 inline void _STLP_CALL _Distance(_InputIterator __first,
409 _InputIterator __last, _Dist& __n) {
410 __distance(__first, __last, __n, _STLP_ITERATOR_CATEGORY(__first, _InputIterator));
414 template <class _InputIter, class _Distance>
415 _STLP_INLINE_LOOP void _STLP_CALL __advance(_InputIter& __i, _Distance __n, const input_iterator_tag &) {
419 // fbp : added output iterator tag variant
420 template <class _InputIter, class _Distance>
421 _STLP_INLINE_LOOP void _STLP_CALL __advance(_InputIter& __i, _Distance __n, const output_iterator_tag &) {
425 # if defined (_STLP_NONTEMPL_BASE_MATCH_BUG)
426 template <class _ForwardIterator, class _Distance>
427 _STLP_INLINE_LOOP void _STLP_CALL __advance(_ForwardIterator& i, _Distance n, const forward_iterator_tag &) {
432 template <class _BidirectionalIterator, class _Distance>
433 _STLP_INLINE_LOOP void _STLP_CALL __advance(_BidirectionalIterator& __i, _Distance __n,
434 const bidirectional_iterator_tag &) {
441 template <class _RandomAccessIterator, class _Distance>
442 inline void _STLP_CALL __advance(_RandomAccessIterator& __i, _Distance __n,
443 const random_access_iterator_tag &) {
447 template <class _InputIterator, class _Distance>
448 inline void _STLP_CALL advance(_InputIterator& __i, _Distance __n) {
449 __advance(__i, __n, _STLP_ITERATOR_CATEGORY(__i, _InputIterator));
454 # if defined (_STLP_DEBUG) && ! defined (_STLP_DEBUG_H)
455 # include <stl/debug/_debug.h>
458 #endif /* _STLP_INTERNAL_ITERATOR_BASE_H */