Ne.app NeANT
The Ne.app NeANT User module of the NeANT distribution.
_iterbase.h
Go to the documentation of this file.
1
45#ifndef _RWSTD_RW_ITERBASE_H_INCLUDED
46#define _RWSTD_RW_ITERBASE_H_INCLUDED
47
48#ifndef _RWSTD_RW_DEFS_H_INCLUDED
49# include <rw/_defs.h>
50#endif // _RWSTD_RW_DEFS_H_INCLUDED
51
52
54
55
56// 24.3.1 - Iterator traits
57template <class _Iterator>
58struct iterator_traits
59{
60 typedef typename _Iterator::value_type value_type;
61 typedef typename _Iterator::difference_type difference_type;
62 typedef typename _Iterator::pointer pointer;
63 typedef typename _Iterator::reference reference;
64 typedef typename _Iterator::iterator_category iterator_category;
65};
66
67
68// 24.3.3 - Standard iterator tags
69struct input_iterator_tag { };
70struct output_iterator_tag { };
71struct forward_iterator_tag : public input_iterator_tag { };
72struct bidirectional_iterator_tag : public forward_iterator_tag { };
73struct random_access_iterator_tag : public bidirectional_iterator_tag { };
74
75
76#ifndef _RWSTD_NO_CLASS_PARTIAL_SPEC
77
78template <class _TypeT>
79struct iterator_traits<_TypeT*>
80{
81 typedef _TypeT value_type;
82 typedef _RWSTD_PTRDIFF_T difference_type;
83 typedef value_type* pointer;
84 typedef value_type& reference;
85 typedef random_access_iterator_tag iterator_category;
86};
87
88
89template <class _TypeT>
90struct iterator_traits<const _TypeT*>
91{
92 typedef _TypeT value_type;
93 typedef _RWSTD_PTRDIFF_T difference_type;
94 typedef const value_type* pointer;
95 typedef const value_type& reference;
96 typedef random_access_iterator_tag iterator_category;
97};
98
99#endif // _RWSTD_NO_CLASS_PARTIAL_SPEC
100
101
102// 24.3.2 - Basic iterator
103template <class _Category, class _TypeT,
104 class _Distance = _RWSTD_PTRDIFF_T,
105 class _Pointer = _TypeT*,
106 class _Reference = _TypeT&>
107struct iterator
108{
109 typedef _TypeT value_type;
110 typedef _Distance difference_type;
111 typedef _Pointer pointer;
112 typedef _Reference reference;
113 typedef _Category iterator_category;
114};
115
116
117// returns the category of an iterator
118template <class _TypeT>
119inline random_access_iterator_tag __iterator_category (const _TypeT*)
120{
121 return random_access_iterator_tag ();
122}
123
124
125template <class _Category, class _TypeT, class _Distance,
126 class _Pointer, class _Reference>
127inline _Category
128__iterator_category (const iterator<_Category, _TypeT,
129 _Distance, _Pointer, _Reference>&)
130{
131 typedef typename iterator<_Category, _TypeT, _Distance, _TypeT*,
132 _TypeT&>::iterator_category _IterCategory;
133
134 return _IterCategory ();
135}
136
137
138template <class _Tag>
139inline bool __is_input_iterator (_Tag)
140{
141 return false;
142}
143
144
145template <class _Tag>
146inline bool __is_bidirectional_iterator (_Tag)
147{
148 return false;
149}
150
151
152template <class _Tag>
153inline bool __is_random_access_iterator (_Tag)
154{
155 return false;
156}
157
158
160inline bool __is_input_iterator (input_iterator_tag)
161{
162 return true;
163}
164
165
167inline bool __is_bidirectional_iterator (bidirectional_iterator_tag)
168{
169 return true;
170}
171
172
174inline bool __is_bidirectional_iterator (random_access_iterator_tag)
175{
176 return true;
177}
178
179
181inline bool __is_random_access_iterator (random_access_iterator_tag)
182{
183 return true;
184}
185
186
187#ifndef _RWSTD_NO_CLASS_PARTIAL_SPEC
188
189template <class _Iterator>
190inline typename iterator_traits<_Iterator>::value_type*
191__value_type (const _Iterator*)
192{
193 return 0;
194}
195
196#else // if defined (_RWSTD_NO_CLASS_PARTIAL_SPEC)
197
198template <class _Category, class _TypeT, class _Distance,
199 class _Pointer, class _Reference>
200inline _TypeT*
201__value_type (const iterator<_Category, _TypeT, _Distance,
202 _Pointer, _Reference>*)
203{
204 return 0;
205}
206
207template <class _TypeT>
208inline _TypeT* __value_type (const _TypeT* const*)
209{
210 return 0;
211}
212
213#endif // _RWSTD_NO_CLASS_PARTIAL_SPEC
214
215
216#ifndef _RWSTD_NO_CLASS_PARTIAL_SPEC
217
218template <class _Iterator>
219inline typename iterator_traits<_Iterator>::difference_type*
220__distance_type (_Iterator)
221{
222 return 0;
223}
224
225#else // if defined (_RWSTD_NO_CLASS_PARTIAL_SPEC)
226
227template <class _Category, class _TypeT, class _Distance,
228 class _Pointer, class _Reference>
229inline _Distance*
230__distance_type (iterator<_Category, _TypeT, _Distance, _Pointer, _Reference>)
231{
232 return 0;
233}
234
235template <class _TypeT>
236inline _RWSTD_PTRDIFF_T* __distance_type (const _TypeT*)
237{
238 return 0;
239}
240
241#endif // _RWSTD_NO_CLASS_PARTIAL_SPEC
242
243
244// 24.3.4 - Iterator operations
245
246template <class _InputIterator, class _Distance>
247inline void __advance (_InputIterator &__it, _Distance __n, input_iterator_tag)
248{
249 _RWSTD_ASSERT (__n == 0 || __n > 0);
250
251 while (__n > 0) {
252 --__n;
253 ++__it;
254 }
255}
256
257
258template <class _ForwardIterator, class _Distance>
259inline void __advance (_ForwardIterator &__it, _Distance __n,
260 forward_iterator_tag)
261{
262 __advance (__it, __n, input_iterator_tag ());
263}
264
265
266template <class _BidirectionalIterator, class _Distance>
267inline void __advance (_BidirectionalIterator &__it, _Distance __n,
268 bidirectional_iterator_tag)
269{
270 if (__n > 0)
271 __advance (__it, __n, input_iterator_tag ());
272 else
273 while (__n) {
274 ++__n;
275 --__it;
276 }
277}
278
279
280template <class _RandomAccessIterator, class _Distance>
281inline void __advance (_RandomAccessIterator& __it, _Distance __n,
282 random_access_iterator_tag)
283{
284 __it += __n;
285}
286
287
288// 24.3.4, p2
289template <class _InputIterator, class _Distance>
290inline void advance (_InputIterator& __it, _Distance __n)
291{
292 __advance (__it, __n, _RWSTD_ITERATOR_CATEGORY (_InputIterator, __it));
293}
294
295
296template <class _InputIterator, class _Distance>
297inline void __distance (const _InputIterator &__first,
298 const _InputIterator &__last,
299 _Distance &__n,
300 input_iterator_tag)
301{
302 for (_InputIterator __it = __first; !(__it == __last); ++__it)
303 ++__n;
304}
305
306
307template <class _ForwardIterator, class _Distance>
308inline void __distance (const _ForwardIterator &__first,
309 const _ForwardIterator &__last,
310 _Distance &__n,
311 forward_iterator_tag)
312{
313 __distance (__first, __last, __n, input_iterator_tag ());
314}
315
316template <class _BidirectionalIterator, class _Distance>
317inline void __distance (const _BidirectionalIterator &__first,
318 const _BidirectionalIterator &__last,
319 _Distance &__n,
320 bidirectional_iterator_tag)
321{
322 __distance (__first, __last, __n, input_iterator_tag ());
323}
324
325
326template <class _RandomAccessIterator, class _Distance>
327inline void __distance (const _RandomAccessIterator &__first,
328 const _RandomAccessIterator &__last,
329 _Distance &__n,
330 random_access_iterator_tag)
331{
332 __n = __last - __first;
333}
334
335
336#ifndef _RWSTD_NO_CLASS_PARTIAL_SPEC
337
338// 24.3.4, p4
339template <class _ForwardIterator>
340inline typename iterator_traits<_ForwardIterator>::difference_type
341distance (_ForwardIterator __first, _ForwardIterator __last)
342{
343 typename iterator_traits<_ForwardIterator>::difference_type __n = 0;
344
345 __distance (__first, __last, __n,
346 _RWSTD_ITERATOR_CATEGORY (_ForwardIterator, __first));
347
348 return __n;
349}
350
351#endif // _RWSTD_NO_CLASS_PARTIAL_SPEC
352
353
354#if !defined (_RWSTD_NO_EXT_VOID_DISTANCE) \
355 || defined (_RWSTD_NO_CLASS_PARTIAL_SPEC)
356
357template <class _ForwardIterator, class _Distance>
358inline void distance (const _ForwardIterator &__first,
359 const _ForwardIterator &__last,
360 _Distance &__n)
361{
362 __distance (__first, __last, __n,
363 _RWSTD_ITERATOR_CATEGORY (_ForwardIterator, __first));
364}
365
366#endif // !_RWSTD_NO_EXT_VOID_DISTANCE || _RWSTD_NO_CLASS_PARTIAL_SPEC
367
368
369} // namespace std
370
371
373
374// __rw_distance: Same purpose as 3-parameter distance function, but
375// with return value.
376
377template <class _ForwardIterator, class _Distance>
378inline _Distance
379__rw_distance (const _ForwardIterator &__first,
380 const _ForwardIterator &__last,
381 _Distance __n)
382{
383 _STD::__distance (__first, __last, __n,
384 _RWSTD_ITERATOR_CATEGORY (_ForwardIterator, __first));
385 return __n;
386}
387
388
389} // namespace __rw
390
391
392#ifndef _RWSTD_NO_DEBUG_ITER
393
395
396// __rw_debug_iter - iterator adapter with debugging support
397// _Iterator is either iterator or const_iterator; if the latter,
398// _MutableIterator should be iterator to allow for implicit
399// conversions from non-const (mutable) to const_iterator objects
400
401
402template <class _Container, class _Iterator, class _MutableIterator>
403class __rw_debug_iter
404{
405 typedef _Container container_type;
406 typedef _Iterator iterator_type;
407 typedef _STD::iterator_traits<iterator_type> traits_type;
408
409public:
410
411 typedef typename traits_type::value_type value_type;
412 typedef typename traits_type::difference_type difference_type;
413 typedef typename traits_type::reference reference;
414 typedef typename traits_type::pointer pointer;
415 typedef typename traits_type::iterator_category iterator_category;
416
417 typedef __rw_debug_iter <container_type, _MutableIterator,
418 _MutableIterator> _C_mutable_iterator;
419
420 __rw_debug_iter (): _C_cont (0) { }
421
422 __rw_debug_iter (const container_type &__cont, const iterator_type &__it)
423 : _C_iter (__it), _C_cont (&__cont) { }
424
425 // no copy ctor other than the one below is defined
426 // will use a compiler generated one if _Iterator != _MutableIterator
427 __rw_debug_iter (const _C_mutable_iterator &__rhs)
428 : _C_iter (__rhs._C_iter), _C_cont (__rhs._C_cont) { }
429
430 __rw_debug_iter& operator= (const __rw_debug_iter &__rhs) {
431 _C_iter = __rhs._C_iter;
432 _C_cont = __rhs._C_cont;
433 return *this;
434 }
435
436 reference operator* () const {
437 _RWSTD_ASSERT (_C_is_dereferenceable ());
438 return *_C_iter;
439 }
440
441 reference operator[] (difference_type __n) const {
442 _RWSTD_ASSERT ((*this + __n)._C_is_dereferenceable ());
443 return _C_iter [__n];
444 }
445
446 _RWSTD_OPERATOR_ARROW (pointer operator-> () const);
447
448 __rw_debug_iter& operator++ () {
449 _RWSTD_ASSERT (!_C_is_end ());
450 return ++_C_iter, *this;
451 }
452
453 __rw_debug_iter& operator-- () {
454 _RWSTD_ASSERT (!_C_is_begin ());
455 return --_C_iter, *this;
456 }
457
458 __rw_debug_iter operator++ (int) {
459 __rw_debug_iter __tmp = *this;
460 return ++*this, __tmp;
461 }
462
463 __rw_debug_iter operator-- (int) {
464 __rw_debug_iter __tmp = *this;
465 return --*this, __tmp;
466 }
467
468 __rw_debug_iter& operator+= (difference_type __n) {
469 _C_iter += __n;
470 _RWSTD_ASSERT ( !(_C_iter < _C_cont->begin ()._C_iter)
471 && !(_C_cont->end ()._C_iter < _C_iter));
472 return *this;
473 }
474
475 __rw_debug_iter& operator-= (difference_type __n) {
476 _C_iter -= __n;
477 _RWSTD_ASSERT ( !(_C_iter < _C_cont->begin ()._C_iter)
478 && !(_C_cont->end ()._C_iter < _C_iter));
479 return *this;
480 }
481
482 __rw_debug_iter operator+ (difference_type __n) const {
483 return __rw_debug_iter (*this) += __n;
484 }
485
486 __rw_debug_iter operator- (difference_type __n) const {
487 return __rw_debug_iter (*this) -= __n;
488 }
489
490 bool _C_is_begin () const {
491 return _C_cont && _C_cont->begin () == *this;
492 }
493
494 bool _C_is_end () const {
495 return _C_cont && _C_cont->end () == *this;
496 }
497
498 bool _C_is_dereferenceable () const {
499 return !_C_is_end ();
500 }
501
502 bool _C_valid_range (const __rw_debug_iter &__it) const {
503 return _C_cont && _C_cont == __it._C_cont;
504 }
505
506 const iterator_type& base () const {
507 return _C_iter;
508 }
509
510 iterator_type& base () {
511 return _C_iter;
512 }
513
514#if !defined (__IBMCPP__) || __IBMCPP__ > 502
515
516 // IBM xlC 5.0 fails to find these member template operators,
517 // yet it complains about ambiguity if they are defined along
518 // with the non-members below...
519
520 // operators are templatized to assure const/non-const symmetry
521
522 template <class _Iter>
523 difference_type
524 operator- (const __rw_debug_iter<container_type, _Iter,
525 _MutableIterator> &__rhs) const {
526 _RWSTD_ASSERT (_C_cont && _C_cont == __rhs._C_cont);
527 return _C_iter - __rhs._C_iter;
528 }
529
530 template <class _Iter>
531 bool
532 operator== (const __rw_debug_iter<container_type, _Iter,
533 _MutableIterator> &__rhs) const {
534 return _C_iter == __rhs._C_iter;
535 }
536
537 template <class _Iter>
538 bool
539 operator< (const __rw_debug_iter<container_type, _Iter,
540 _MutableIterator> &__rhs) const {
541 return _C_iter < __rhs._C_iter;
542 }
543
544 template <class _Iter>
545 bool
546 operator!= (const __rw_debug_iter<container_type, _Iter,
547 _MutableIterator> &__rhs) const {
548 return !(_C_iter == __rhs._C_iter);
549 }
550
551 template <class _Iter>
552 bool
553 operator<= (const __rw_debug_iter<container_type, _Iter,
554 _MutableIterator> &__rhs) const {
555 return !(__rhs._C_iter < _C_iter);
556 }
557
558 template <class _Iter>
559 bool
560 operator> (const __rw_debug_iter<container_type, _Iter,
561 _MutableIterator> &__rhs) const {
562 return __rhs._C_iter < _C_iter;
563 }
564
565 template <class _Iter>
566 bool
567 operator>= (const __rw_debug_iter<container_type, _Iter,
568 _MutableIterator> &__rhs) const {
569 return !(_C_iter < __rhs._C_iter);
570 }
571
572#endif // __IBMCPP__ > 502
573
574 iterator_type _C_iter; // wrapped iterator
575 const container_type *_C_cont; // associated container
576};
577
578
579} // namespace __rw
580
581
583
584
585#ifndef _RWSTD_NO_NONDEDUCED_CONTEXT
586# define _RWSTD_CONT_DIFF_TYPE typename _Cont::difference_type
587#else
588# define _RWSTD_CONT_DIFF_TYPE _RWSTD_PTRDIFF_T
589#endif
590
591template <class _Cont, class _Iter, class _MutIter>
592inline _RW::__rw_debug_iter<_Cont, _Iter, _MutIter>
594 const _RW::__rw_debug_iter<_Cont, _Iter, _MutIter> &__x)
595{
596 return __x + __n;
597}
598
599#undef _RWSTD_CONT_DIFF_TYPE
600
601
602#if defined (__IBMCPP__) && __IBMCPP__ <= 502
603
604// IBM xlC 5.0 fails to find the member template operators
605// defined above in the presence of namespaces...
606
607// with no support for member templates namespace-scope (non-member)
608// operators must be used - these will cause ambiguities with those
609// in std::rel_ops if the latter are found during lookup
610
611
612// _Iter1 may differ from _Iter2 if the function operands are const
613// and non-const iterators, respectively (allows symmetry)
614
615template <class _Cont, class _Iter1, class _Iter2, class _MutIter>
616inline typename _Cont::difference_type
617operator- (const _RW::__rw_debug_iter<_Cont, _Iter1, _MutIter> &__x,
618 const _RW::__rw_debug_iter<_Cont, _Iter2, _MutIter> &__y)
619{
620 _RWSTD_ASSERT (__x._C_cont && __x._C_cont == __y._C_cont);
621 return __x._C_iter - __y._C_iter;
622}
623
624template <class _Cont, class _Iter1, class _Iter2, class _MutIter>
625inline bool
626operator== (const _RW::__rw_debug_iter<_Cont, _Iter1, _MutIter> &__x,
627 const _RW::__rw_debug_iter<_Cont, _Iter2, _MutIter> &__y)
628{
629 return __x._C_iter == __y._C_iter;
630}
631
632template <class _Cont, class _Iter1, class _Iter2, class _MutIter>
633inline bool
634operator< (const _RW::__rw_debug_iter<_Cont, _Iter1, _MutIter> &__x,
635 const _RW::__rw_debug_iter<_Cont, _Iter2, _MutIter> &__y)
636{
637 _RWSTD_ASSERT (__x._C_cont && __x._C_cont == __y._C_cont);
638 return __x._C_iter < __y._C_iter;
639}
640
641template <class _Cont, class _Iter1, class _Iter2, class _MutIter>
642inline bool
643operator!= (const _RW::__rw_debug_iter<_Cont, _Iter1, _MutIter> &__x,
644 const _RW::__rw_debug_iter<_Cont, _Iter2, _MutIter> &__y)
645{
646 return !(__x == __y);
647}
648
649template <class _Cont, class _Iter1, class _Iter2, class _MutIter>
650inline bool
651operator<= (const _RW::__rw_debug_iter<_Cont, _Iter1, _MutIter> &__x,
652 const _RW::__rw_debug_iter<_Cont, _Iter2, _MutIter> &__y)
653{
654 return !(__y < __x);
655}
656
657template <class _Cont, class _Iter1, class _Iter2, class _MutIter>
658inline bool
659operator>= (const _RW::__rw_debug_iter<_Cont, _Iter1, _MutIter> &__x,
660 const _RW::__rw_debug_iter<_Cont, _Iter2, _MutIter> &__y)
661{
662 return !(__x < __y);
663}
664
665template <class _Cont, class _Iter1, class _Iter2, class _MutIter>
666inline bool
667operator> (const _RW::__rw_debug_iter<_Cont, _Iter1, _MutIter> &__x,
668 const _RW::__rw_debug_iter<_Cont, _Iter2, _MutIter> &__y)
669{
670 return __y < __x;
671}
672
673#endif // __IBMCPP__ <= 502
674
675} // namespace std
676
677
679
680
681#define _RWSTD_DEBUG_ITER(cont, it, mutit) __rw_debug_iter< cont, it, mutit >
682
683
684template <class _Cont, class _Iter, class _MutIter>
685inline bool
686__rw_valid_range (const _RWSTD_DEBUG_ITER(_Cont, _Iter, _MutIter) &__first,
687 const _RWSTD_DEBUG_ITER(_Cont, _Iter, _MutIter) &__last)
688{
689 return __first._C_cont && __first._C_cont == __last._C_cont;
690}
691
692
693template <class _Iterator>
694inline bool
695__rw_valid_range (const _Iterator &, const _Iterator &)
696{
697 return true;
698}
699
700
701template <class _Cont, class _Iter, class _MutIter>
702inline bool
703__rw_in_range (const _RWSTD_DEBUG_ITER(_Cont, _Iter, _MutIter) &__it,
704 const _RWSTD_DEBUG_ITER(_Cont, _Iter, _MutIter) &__first,
705 const _RWSTD_DEBUG_ITER(_Cont, _Iter, _MutIter) &__last)
706{
707 return __rw_valid_range (__first, __it)
708 && __rw_valid_range (__it, __last);
709}
710
711
712template <class _Iterator>
713inline bool
714__rw_in_range (const _Iterator&, const _Iterator&, const _Iterator&)
715{
716 return true;
717}
718
719
720template <class _Cont, class _Iter, class _MutIter>
721inline bool
722__rw_dereferenceable (const _RWSTD_DEBUG_ITER(_Cont, _Iter, _MutIter) &__it)
723{
724 return __it._C_is_dereferenceable ();
725}
726
727
728template <class _Iterator>
729inline bool
730__rw_dereferenceable (const _Iterator&)
731{
732 return true;
733}
734
735
736template <class _TypeT>
737inline bool
738__rw_dereferenceable (const _TypeT *__ptr)
739{
740 return 0 != __ptr;
741}
742
743} // namespace __rw
744
745#undef _RWSTD_DEBUG_ITER
746
747#endif // _RWSTD_NO_DEBUG_ITER
748
749
750#endif // _RWSTD_RW_ITERBASE_H_INCLUDED
void distance(T, T,...)
const minus< T > & operator-(const minus< T > &lhs, const minus< T > &rhs)
const plus_asgn< T > & operator*(const plus_asgn< T > &lhs, const plus_asgn< T > &rhs)
void operator+(typename A< T >::I, const A< T > &)
#define _RWSTD_NAMESPACE(name)
Definition _defs.h:567
#define _RWSTD_ASSERT(ignore)
Definition _defs.h:1108
#define _RWSTD_OPERATOR_ARROW(signature)
Definition _defs.h:965
#define _RWSTD_SPECIALIZED_FUNCTION
Definition _defs.h:556
#define _RWSTD_ITERATOR_CATEGORY(iterT, ignore)
Definition _defs.h:1055
#define _RWSTD_DEBUG_ITER(cont, it, mutit)
#define _RWSTD_CONT_DIFF_TYPE
bool operator>(const DistancePair &lhs, const DistancePair &rhs)
Definition graph.cpp:47
bool operator==(const json_pointer< RefStringTypeLhs > &lhs, const json_pointer< RefStringTypeRhs > &rhs) noexcept
Definition json.h:14737
bool operator!=(const json_pointer< RefStringTypeLhs > &lhs, const json_pointer< RefStringTypeRhs > &rhs) noexcept
Definition json.h:14762
bool operator<(const json_pointer< RefStringTypeLhs > &lhs, const json_pointer< RefStringTypeRhs > &rhs) noexcept
Definition json.h:14787
Definition json.h:5363