30 #ifndef _GLIBCXX_DEBUG_SAFE_ITERATOR_H
31 #define _GLIBCXX_DEBUG_SAFE_ITERATOR_H 1
46 template <
typename _Sequence>
49 typedef typename _Sequence::const_iterator _It;
50 typedef typename _It::iterator_type _BaseIt;
53 _M_Is(_BaseIt __it,
const _Sequence* __seq)
76 template<
typename _Iterator,
typename _Sequence>
77 class _Safe_iterator :
public _Safe_iterator_base
84 enum _Distance_precision
98 typedef typename _Sequence::const_iterator const_iterator;
99 return std::__are_same<const_iterator, _Safe_iterator>::__value;
102 typedef std::iterator_traits<_Iterator> _Traits;
105 typedef _Iterator iterator_type;
106 typedef typename _Traits::iterator_category iterator_category;
107 typedef typename _Traits::value_type value_type;
108 typedef typename _Traits::difference_type difference_type;
109 typedef typename _Traits::reference reference;
110 typedef typename _Traits::pointer pointer;
126 _M_message(__msg_init_singular)
127 ._M_iterator(*
this,
"this"));
139 || __x._M_current == _Iterator(),
140 _M_message(__msg_init_copy_singular)
141 ._M_iterator(*
this,
"this")
142 ._M_iterator(__x,
"other"));
145 #ifdef __GXX_EXPERIMENTAL_CXX0X__
153 || __x._M_current == _Iterator(),
154 _M_message(__msg_init_copy_singular)
155 ._M_iterator(*
this,
"this")
156 ._M_iterator(__x,
"other"));
157 std::swap(_M_current, __x._M_current);
167 template<
typename _MutableIterator>
170 typename __gnu_cxx::__enable_if<(std::__are_same<_MutableIterator,
171 typename _Sequence::iterator::iterator_type>::__value),
172 _Sequence>::__type>& __x)
178 || __x.base() == _Iterator(),
179 _M_message(__msg_init_const_singular)
180 ._M_iterator(*
this,
"this")
181 ._M_iterator(__x,
"other"));
193 || __x._M_current == _Iterator(),
194 _M_message(__msg_copy_singular)
195 ._M_iterator(*
this,
"this")
196 ._M_iterator(__x,
"other"));
197 _M_current = __x._M_current;
202 #ifdef __GXX_EXPERIMENTAL_CXX0X__
211 || __x._M_current == _Iterator(),
212 _M_message(__msg_copy_singular)
213 ._M_iterator(*
this,
"this")
214 ._M_iterator(__x,
"other"));
215 _M_current = __x._M_current;
218 __x._M_current = _Iterator();
231 _M_message(__msg_bad_deref)
232 ._M_iterator(*
this,
"this"));
246 _M_message(__msg_bad_deref)
247 ._M_iterator(*
this,
"this"));
260 _M_message(__msg_bad_inc)
261 ._M_iterator(*
this,
"this"));
274 _M_message(__msg_bad_inc)
275 ._M_iterator(*
this,
"this"));
290 _M_message(__msg_bad_dec)
291 ._M_iterator(*
this,
"this"));
304 _M_message(__msg_bad_dec)
305 ._M_iterator(*
this,
"this"));
313 operator[](
const difference_type& __n)
const
316 && this->_M_can_advance(__n+1),
317 _M_message(__msg_iter_subscript_oob)
318 ._M_iterator(*this)._M_integer(__n));
320 return _M_current[__n];
324 operator+=(
const difference_type& __n)
327 _M_message(__msg_advance_oob)
328 ._M_iterator(*this)._M_integer(__n));
334 operator+(
const difference_type& __n)
const
342 operator-=(
const difference_type& __n)
345 _M_message(__msg_retreat_oob)
346 ._M_iterator(*this)._M_integer(__n));
352 operator-(
const difference_type& __n)
const
364 base()
const {
return _M_current; }
370 operator _Iterator()
const {
return _M_current; }
410 _M_can_advance(
const difference_type& __n)
const;
413 template<
typename _Other>
415 _M_valid_range(
const _Safe_iterator<_Other, _Sequence>& __rhs)
const;
419 _M_get_sequence()
const
420 {
return static_cast<const _Sequence*
>(
_M_sequence); }
425 template<
typename _Iterator1,
typename _Iterator2>
429 typedef typename std::iterator_traits<_Iterator1>::iterator_category
434 template<
typename _Iterator1,
typename _Iterator2>
440 template<
typename _Iterator1,
typename _Iterator2>
448 {
return base() == _M_get_sequence()->_M_base().begin(); }
452 {
return base() == _M_get_sequence()->_M_base().end(); }
462 template<
typename _IteratorL,
typename _IteratorR,
typename _Sequence>
464 operator==(
const _Safe_iterator<_IteratorL, _Sequence>& __lhs,
465 const _Safe_iterator<_IteratorR, _Sequence>& __rhs)
468 _M_message(__msg_iter_compare_bad)
469 ._M_iterator(__lhs,
"lhs")
470 ._M_iterator(__rhs,
"rhs"));
472 _M_message(__msg_compare_different)
473 ._M_iterator(__lhs,
"lhs")
474 ._M_iterator(__rhs,
"rhs"));
475 return __lhs.base() == __rhs.base();
478 template<
typename _Iterator,
typename _Sequence>
480 operator==(
const _Safe_iterator<_Iterator, _Sequence>& __lhs,
481 const _Safe_iterator<_Iterator, _Sequence>& __rhs)
484 _M_message(__msg_iter_compare_bad)
485 ._M_iterator(__lhs,
"lhs")
486 ._M_iterator(__rhs,
"rhs"));
488 _M_message(__msg_compare_different)
489 ._M_iterator(__lhs,
"lhs")
490 ._M_iterator(__rhs,
"rhs"));
491 return __lhs.base() == __rhs.base();
494 template<
typename _IteratorL,
typename _IteratorR,
typename _Sequence>
496 operator!=(
const _Safe_iterator<_IteratorL, _Sequence>& __lhs,
497 const _Safe_iterator<_IteratorR, _Sequence>& __rhs)
500 _M_message(__msg_iter_compare_bad)
501 ._M_iterator(__lhs,
"lhs")
502 ._M_iterator(__rhs,
"rhs"));
504 _M_message(__msg_compare_different)
505 ._M_iterator(__lhs,
"lhs")
506 ._M_iterator(__rhs,
"rhs"));
507 return __lhs.base() != __rhs.base();
510 template<
typename _Iterator,
typename _Sequence>
512 operator!=(
const _Safe_iterator<_Iterator, _Sequence>& __lhs,
513 const _Safe_iterator<_Iterator, _Sequence>& __rhs)
516 _M_message(__msg_iter_compare_bad)
517 ._M_iterator(__lhs,
"lhs")
518 ._M_iterator(__rhs,
"rhs"));
520 _M_message(__msg_compare_different)
521 ._M_iterator(__lhs,
"lhs")
522 ._M_iterator(__rhs,
"rhs"));
523 return __lhs.base() != __rhs.base();
526 template<
typename _IteratorL,
typename _IteratorR,
typename _Sequence>
528 operator<(const _Safe_iterator<_IteratorL, _Sequence>& __lhs,
529 const _Safe_iterator<_IteratorR, _Sequence>& __rhs)
532 _M_message(__msg_iter_order_bad)
533 ._M_iterator(__lhs,
"lhs")
534 ._M_iterator(__rhs,
"rhs"));
536 _M_message(__msg_order_different)
537 ._M_iterator(__lhs,
"lhs")
538 ._M_iterator(__rhs,
"rhs"));
539 return __lhs.base() < __rhs.base();
542 template<
typename _Iterator,
typename _Sequence>
544 operator<(const _Safe_iterator<_Iterator, _Sequence>& __lhs,
545 const _Safe_iterator<_Iterator, _Sequence>& __rhs)
548 _M_message(__msg_iter_order_bad)
549 ._M_iterator(__lhs,
"lhs")
550 ._M_iterator(__rhs,
"rhs"));
552 _M_message(__msg_order_different)
553 ._M_iterator(__lhs,
"lhs")
554 ._M_iterator(__rhs,
"rhs"));
555 return __lhs.base() < __rhs.base();
558 template<
typename _IteratorL,
typename _IteratorR,
typename _Sequence>
560 operator<=(const _Safe_iterator<_IteratorL, _Sequence>& __lhs,
561 const _Safe_iterator<_IteratorR, _Sequence>& __rhs)
564 _M_message(__msg_iter_order_bad)
565 ._M_iterator(__lhs,
"lhs")
566 ._M_iterator(__rhs,
"rhs"));
568 _M_message(__msg_order_different)
569 ._M_iterator(__lhs,
"lhs")
570 ._M_iterator(__rhs,
"rhs"));
571 return __lhs.base() <= __rhs.base();
574 template<
typename _Iterator,
typename _Sequence>
576 operator<=(const _Safe_iterator<_Iterator, _Sequence>& __lhs,
577 const _Safe_iterator<_Iterator, _Sequence>& __rhs)
580 _M_message(__msg_iter_order_bad)
581 ._M_iterator(__lhs,
"lhs")
582 ._M_iterator(__rhs,
"rhs"));
584 _M_message(__msg_order_different)
585 ._M_iterator(__lhs,
"lhs")
586 ._M_iterator(__rhs,
"rhs"));
587 return __lhs.base() <= __rhs.base();
590 template<
typename _IteratorL,
typename _IteratorR,
typename _Sequence>
592 operator>(
const _Safe_iterator<_IteratorL, _Sequence>& __lhs,
593 const _Safe_iterator<_IteratorR, _Sequence>& __rhs)
596 _M_message(__msg_iter_order_bad)
597 ._M_iterator(__lhs,
"lhs")
598 ._M_iterator(__rhs,
"rhs"));
600 _M_message(__msg_order_different)
601 ._M_iterator(__lhs,
"lhs")
602 ._M_iterator(__rhs,
"rhs"));
603 return __lhs.base() > __rhs.base();
606 template<
typename _Iterator,
typename _Sequence>
608 operator>(
const _Safe_iterator<_Iterator, _Sequence>& __lhs,
609 const _Safe_iterator<_Iterator, _Sequence>& __rhs)
612 _M_message(__msg_iter_order_bad)
613 ._M_iterator(__lhs,
"lhs")
614 ._M_iterator(__rhs,
"rhs"));
616 _M_message(__msg_order_different)
617 ._M_iterator(__lhs,
"lhs")
618 ._M_iterator(__rhs,
"rhs"));
619 return __lhs.base() > __rhs.base();
622 template<
typename _IteratorL,
typename _IteratorR,
typename _Sequence>
624 operator>=(
const _Safe_iterator<_IteratorL, _Sequence>& __lhs,
625 const _Safe_iterator<_IteratorR, _Sequence>& __rhs)
628 _M_message(__msg_iter_order_bad)
629 ._M_iterator(__lhs,
"lhs")
630 ._M_iterator(__rhs,
"rhs"));
632 _M_message(__msg_order_different)
633 ._M_iterator(__lhs,
"lhs")
634 ._M_iterator(__rhs,
"rhs"));
635 return __lhs.base() >= __rhs.base();
638 template<
typename _Iterator,
typename _Sequence>
640 operator>=(
const _Safe_iterator<_Iterator, _Sequence>& __lhs,
641 const _Safe_iterator<_Iterator, _Sequence>& __rhs)
644 _M_message(__msg_iter_order_bad)
645 ._M_iterator(__lhs,
"lhs")
646 ._M_iterator(__rhs,
"rhs"));
648 _M_message(__msg_order_different)
649 ._M_iterator(__lhs,
"lhs")
650 ._M_iterator(__rhs,
"rhs"));
651 return __lhs.base() >= __rhs.base();
658 template<
typename _IteratorL,
typename _IteratorR,
typename _Sequence>
659 inline typename _Safe_iterator<_IteratorL, _Sequence>::difference_type
660 operator-(
const _Safe_iterator<_IteratorL, _Sequence>& __lhs,
661 const _Safe_iterator<_IteratorR, _Sequence>& __rhs)
664 _M_message(__msg_distance_bad)
665 ._M_iterator(__lhs,
"lhs")
666 ._M_iterator(__rhs,
"rhs"));
668 _M_message(__msg_distance_different)
669 ._M_iterator(__lhs,
"lhs")
670 ._M_iterator(__rhs,
"rhs"));
671 return __lhs.base() - __rhs.base();
674 template<
typename _Iterator,
typename _Sequence>
675 inline typename _Safe_iterator<_Iterator, _Sequence>::difference_type
676 operator-(
const _Safe_iterator<_Iterator, _Sequence>& __lhs,
677 const _Safe_iterator<_Iterator, _Sequence>& __rhs)
680 _M_message(__msg_distance_bad)
681 ._M_iterator(__lhs,
"lhs")
682 ._M_iterator(__rhs,
"rhs"));
684 _M_message(__msg_distance_different)
685 ._M_iterator(__lhs,
"lhs")
686 ._M_iterator(__rhs,
"rhs"));
687 return __lhs.base() - __rhs.base();
690 template<
typename _Iterator,
typename _Sequence>
691 inline _Safe_iterator<_Iterator, _Sequence>
692 operator+(
typename _Safe_iterator<_Iterator,_Sequence>::difference_type __n,
693 const _Safe_iterator<_Iterator, _Sequence>& __i)
694 {
return __i + __n; }
697 template<
typename _Iterator>
698 struct __is_safe_random_iterator
700 enum { __value = 0 };
701 typedef std::__false_type __type;
704 template<
typename _Iterator,
typename _Sequence>
705 struct __is_safe_random_iterator<_Safe_iterator<_Iterator, _Sequence> >
706 : std::__are_same<std::random_access_iterator_tag,
707 typename std::iterator_traits<_Iterator>::
711 template<
typename _Iterator>
713 : std::_Iter_base<_Iterator, __is_safe_random_iterator<_Iterator>::__value>
722 template<
typename _Iterator>
723 inline typename _Siter_base<_Iterator>::iterator_type
725 {
return _Siter_base<_Iterator>::_S_base(__it); }