60 #ifndef _STL_ITERATOR_H
61 #define _STL_ITERATOR_H 1
68 namespace std _GLIBCXX_VISIBILITY(default)
70 _GLIBCXX_BEGIN_NAMESPACE_VERSION
96 template<
typename _Iterator>
98 :
public iterator<typename iterator_traits<_Iterator>::iterator_category,
99 typename iterator_traits<_Iterator>::value_type,
100 typename iterator_traits<_Iterator>::difference_type,
101 typename iterator_traits<_Iterator>::pointer,
102 typename iterator_traits<_Iterator>::reference>
107 typedef iterator_traits<_Iterator> __traits_type;
110 typedef _Iterator iterator_type;
111 typedef typename __traits_type::difference_type difference_type;
112 typedef typename __traits_type::pointer pointer;
113 typedef typename __traits_type::reference reference;
133 : current(__x.current) { }
139 template<
typename _Iter>
141 : current(__x.
base()) { }
163 _Iterator __tmp = current;
277 {
return *(*
this + __n); }
290 template<
typename _Iterator>
294 {
return __x.
base() == __y.
base(); }
296 template<
typename _Iterator>
298 operator<(const reverse_iterator<_Iterator>& __x,
299 const reverse_iterator<_Iterator>& __y)
300 {
return __y.base() < __x.base(); }
302 template<
typename _Iterator>
304 operator!=(
const reverse_iterator<_Iterator>& __x,
305 const reverse_iterator<_Iterator>& __y)
306 {
return !(__x == __y); }
308 template<
typename _Iterator>
310 operator>(
const reverse_iterator<_Iterator>& __x,
311 const reverse_iterator<_Iterator>& __y)
312 {
return __y < __x; }
314 template<
typename _Iterator>
316 operator<=(const reverse_iterator<_Iterator>& __x,
317 const reverse_iterator<_Iterator>& __y)
318 {
return !(__y < __x); }
320 template<
typename _Iterator>
322 operator>=(
const reverse_iterator<_Iterator>& __x,
323 const reverse_iterator<_Iterator>& __y)
324 {
return !(__x < __y); }
326 template<
typename _Iterator>
327 inline typename reverse_iterator<_Iterator>::difference_type
328 operator-(
const reverse_iterator<_Iterator>& __x,
329 const reverse_iterator<_Iterator>& __y)
330 {
return __y.base() - __x.base(); }
332 template<
typename _Iterator>
333 inline reverse_iterator<_Iterator>
334 operator+(
typename reverse_iterator<_Iterator>::difference_type __n,
335 const reverse_iterator<_Iterator>& __x)
336 {
return reverse_iterator<_Iterator>(__x.base() - __n); }
340 template<
typename _IteratorL,
typename _IteratorR>
342 operator==(
const reverse_iterator<_IteratorL>& __x,
343 const reverse_iterator<_IteratorR>& __y)
344 {
return __x.base() == __y.base(); }
346 template<
typename _IteratorL,
typename _IteratorR>
348 operator<(const reverse_iterator<_IteratorL>& __x,
349 const reverse_iterator<_IteratorR>& __y)
350 {
return __y.base() < __x.base(); }
352 template<
typename _IteratorL,
typename _IteratorR>
354 operator!=(
const reverse_iterator<_IteratorL>& __x,
355 const reverse_iterator<_IteratorR>& __y)
356 {
return !(__x == __y); }
358 template<
typename _IteratorL,
typename _IteratorR>
360 operator>(
const reverse_iterator<_IteratorL>& __x,
361 const reverse_iterator<_IteratorR>& __y)
362 {
return __y < __x; }
364 template<
typename _IteratorL,
typename _IteratorR>
366 operator<=(const reverse_iterator<_IteratorL>& __x,
367 const reverse_iterator<_IteratorR>& __y)
368 {
return !(__y < __x); }
370 template<
typename _IteratorL,
typename _IteratorR>
372 operator>=(
const reverse_iterator<_IteratorL>& __x,
373 const reverse_iterator<_IteratorR>& __y)
374 {
return !(__x < __y); }
376 template<
typename _IteratorL,
typename _IteratorR>
377 #if __cplusplus >= 201103L
380 operator-(
const reverse_iterator<_IteratorL>& __x,
381 const reverse_iterator<_IteratorR>& __y)
382 -> decltype(__y.base() - __x.base())
384 inline typename reverse_iterator<_IteratorL>::difference_type
385 operator-(
const reverse_iterator<_IteratorL>& __x,
386 const reverse_iterator<_IteratorR>& __y)
388 {
return __y.base() - __x.base(); }
402 template<
typename _Container>
404 :
public iterator<output_iterator_tag, void, void, void, void>
407 _Container* container;
428 #if __cplusplus < 201103L
430 operator=(
typename _Container::const_reference __value)
432 container->push_back(__value);
437 operator=(
const typename _Container::value_type& __value)
439 container->push_back(__value);
444 operator=(
typename _Container::value_type&& __value)
446 container->push_back(std::move(__value));
478 template<
typename _Container>
479 inline back_insert_iterator<_Container>
493 template<
typename _Container>
495 :
public iterator<output_iterator_tag, void, void, void, void>
498 _Container* container;
518 #if __cplusplus < 201103L
520 operator=(
typename _Container::const_reference __value)
522 container->push_front(__value);
527 operator=(
const typename _Container::value_type& __value)
529 container->push_front(__value);
534 operator=(
typename _Container::value_type&& __value)
536 container->push_front(std::move(__value));
568 template<
typename _Container>
569 inline front_insert_iterator<_Container>
587 template<
typename _Container>
589 :
public iterator<output_iterator_tag, void, void, void, void>
592 _Container* container;
593 typename _Container::iterator iter;
604 : container(&__x), iter(__i) {}
629 #if __cplusplus < 201103L
631 operator=(
typename _Container::const_reference __value)
633 iter = container->insert(iter, __value);
639 operator=(
const typename _Container::value_type& __value)
641 iter = container->insert(iter, __value);
647 operator=(
typename _Container::value_type&& __value)
649 iter = container->insert(iter, std::move(__value));
682 template<
typename _Container,
typename _Iterator>
683 inline insert_iterator<_Container>
687 typename _Container::iterator(__i));
692 _GLIBCXX_END_NAMESPACE_VERSION
695 namespace __gnu_cxx _GLIBCXX_VISIBILITY(default)
697 _GLIBCXX_BEGIN_NAMESPACE_VERSION
706 using std::iterator_traits;
708 template<
typename _Iterator,
typename _Container>
709 class __normal_iterator
712 _Iterator _M_current;
714 typedef iterator_traits<_Iterator> __traits_type;
717 typedef _Iterator iterator_type;
718 typedef typename __traits_type::iterator_category iterator_category;
719 typedef typename __traits_type::value_type value_type;
720 typedef typename __traits_type::difference_type difference_type;
721 typedef typename __traits_type::reference reference;
722 typedef typename __traits_type::pointer pointer;
724 _GLIBCXX_CONSTEXPR __normal_iterator() _GLIBCXX_NOEXCEPT
725 : _M_current(_Iterator()) { }
728 __normal_iterator(
const _Iterator& __i) _GLIBCXX_NOEXCEPT
729 : _M_current(__i) { }
732 template<
typename _Iter>
733 __normal_iterator(
const __normal_iterator<_Iter,
734 typename __enable_if<
735 (std::__are_same<_Iter, typename _Container::pointer>::__value),
736 _Container>::__type>& __i) _GLIBCXX_NOEXCEPT
737 : _M_current(__i.base()) { }
739 #if __cplusplus >= 201103L
740 __normal_iterator<typename _Container::pointer, _Container>
741 _M_const_cast() const noexcept
744 return __normal_iterator<typename _Container::pointer, _Container>
745 (_PTraits::pointer_to(const_cast<typename _PTraits::element_type&>
750 _M_const_cast()
const
756 operator*() const _GLIBCXX_NOEXCEPT
757 {
return *_M_current; }
760 operator->() const _GLIBCXX_NOEXCEPT
761 {
return _M_current; }
764 operator++() _GLIBCXX_NOEXCEPT
771 operator++(
int) _GLIBCXX_NOEXCEPT
772 {
return __normal_iterator(_M_current++); }
776 operator--() _GLIBCXX_NOEXCEPT
783 operator--(
int) _GLIBCXX_NOEXCEPT
784 {
return __normal_iterator(_M_current--); }
788 operator[](difference_type __n)
const _GLIBCXX_NOEXCEPT
789 {
return _M_current[__n]; }
792 operator+=(difference_type __n) _GLIBCXX_NOEXCEPT
793 { _M_current += __n;
return *
this; }
796 operator+(difference_type __n)
const _GLIBCXX_NOEXCEPT
797 {
return __normal_iterator(_M_current + __n); }
800 operator-=(difference_type __n) _GLIBCXX_NOEXCEPT
801 { _M_current -= __n;
return *
this; }
804 operator-(difference_type __n)
const _GLIBCXX_NOEXCEPT
805 {
return __normal_iterator(_M_current - __n); }
808 base() const _GLIBCXX_NOEXCEPT
809 {
return _M_current; }
821 template<
typename _IteratorL,
typename _IteratorR,
typename _Container>
823 operator==(
const __normal_iterator<_IteratorL, _Container>& __lhs,
824 const __normal_iterator<_IteratorR, _Container>& __rhs)
826 {
return __lhs.base() == __rhs.base(); }
828 template<
typename _Iterator,
typename _Container>
830 operator==(
const __normal_iterator<_Iterator, _Container>& __lhs,
831 const __normal_iterator<_Iterator, _Container>& __rhs)
833 {
return __lhs.base() == __rhs.base(); }
835 template<
typename _IteratorL,
typename _IteratorR,
typename _Container>
837 operator!=(
const __normal_iterator<_IteratorL, _Container>& __lhs,
838 const __normal_iterator<_IteratorR, _Container>& __rhs)
840 {
return __lhs.base() != __rhs.base(); }
842 template<
typename _Iterator,
typename _Container>
844 operator!=(
const __normal_iterator<_Iterator, _Container>& __lhs,
845 const __normal_iterator<_Iterator, _Container>& __rhs)
847 {
return __lhs.base() != __rhs.base(); }
850 template<
typename _IteratorL,
typename _IteratorR,
typename _Container>
852 operator<(const __normal_iterator<_IteratorL, _Container>& __lhs,
853 const __normal_iterator<_IteratorR, _Container>& __rhs)
855 {
return __lhs.base() < __rhs.base(); }
857 template<
typename _Iterator,
typename _Container>
859 operator<(const __normal_iterator<_Iterator, _Container>& __lhs,
860 const __normal_iterator<_Iterator, _Container>& __rhs)
862 {
return __lhs.base() < __rhs.base(); }
864 template<
typename _IteratorL,
typename _IteratorR,
typename _Container>
866 operator>(
const __normal_iterator<_IteratorL, _Container>& __lhs,
867 const __normal_iterator<_IteratorR, _Container>& __rhs)
869 {
return __lhs.base() > __rhs.base(); }
871 template<
typename _Iterator,
typename _Container>
873 operator>(
const __normal_iterator<_Iterator, _Container>& __lhs,
874 const __normal_iterator<_Iterator, _Container>& __rhs)
876 {
return __lhs.base() > __rhs.base(); }
878 template<
typename _IteratorL,
typename _IteratorR,
typename _Container>
880 operator<=(const __normal_iterator<_IteratorL, _Container>& __lhs,
881 const __normal_iterator<_IteratorR, _Container>& __rhs)
883 {
return __lhs.base() <= __rhs.base(); }
885 template<
typename _Iterator,
typename _Container>
887 operator<=(const __normal_iterator<_Iterator, _Container>& __lhs,
888 const __normal_iterator<_Iterator, _Container>& __rhs)
890 {
return __lhs.base() <= __rhs.base(); }
892 template<
typename _IteratorL,
typename _IteratorR,
typename _Container>
894 operator>=(
const __normal_iterator<_IteratorL, _Container>& __lhs,
895 const __normal_iterator<_IteratorR, _Container>& __rhs)
897 {
return __lhs.base() >= __rhs.base(); }
899 template<
typename _Iterator,
typename _Container>
901 operator>=(
const __normal_iterator<_Iterator, _Container>& __lhs,
902 const __normal_iterator<_Iterator, _Container>& __rhs)
904 {
return __lhs.base() >= __rhs.base(); }
910 template<
typename _IteratorL,
typename _IteratorR,
typename _Container>
911 #if __cplusplus >= 201103L
914 operator-(
const __normal_iterator<_IteratorL, _Container>& __lhs,
915 const __normal_iterator<_IteratorR, _Container>& __rhs) noexcept
916 -> decltype(__lhs.base() - __rhs.base())
918 inline typename __normal_iterator<_IteratorL, _Container>::difference_type
919 operator-(
const __normal_iterator<_IteratorL, _Container>& __lhs,
920 const __normal_iterator<_IteratorR, _Container>& __rhs)
922 {
return __lhs.base() - __rhs.base(); }
924 template<
typename _Iterator,
typename _Container>
925 inline typename __normal_iterator<_Iterator, _Container>::difference_type
926 operator-(
const __normal_iterator<_Iterator, _Container>& __lhs,
927 const __normal_iterator<_Iterator, _Container>& __rhs)
929 {
return __lhs.base() - __rhs.base(); }
931 template<
typename _Iterator,
typename _Container>
932 inline __normal_iterator<_Iterator, _Container>
933 operator+(
typename __normal_iterator<_Iterator, _Container>::difference_type
934 __n,
const __normal_iterator<_Iterator, _Container>& __i)
936 {
return __normal_iterator<_Iterator, _Container>(__i.base() + __n); }
938 _GLIBCXX_END_NAMESPACE_VERSION
941 #if __cplusplus >= 201103L
943 namespace std _GLIBCXX_VISIBILITY(default)
945 _GLIBCXX_BEGIN_NAMESPACE_VERSION
961 template<
typename _Iterator>
965 _Iterator _M_current;
967 typedef iterator_traits<_Iterator> __traits_type;
970 typedef _Iterator iterator_type;
971 typedef typename __traits_type::iterator_category iterator_category;
972 typedef typename __traits_type::value_type value_type;
973 typedef typename __traits_type::difference_type difference_type;
975 typedef _Iterator pointer;
976 typedef value_type&& reference;
982 move_iterator(iterator_type __i)
983 : _M_current(__i) { }
985 template<
typename _Iter>
986 move_iterator(
const move_iterator<_Iter>& __i)
987 : _M_current(__i.base()) { }
991 {
return _M_current; }
995 {
return std::move(*_M_current); }
999 {
return _M_current; }
1011 move_iterator __tmp = *
this;
1026 move_iterator __tmp = *
this;
1032 operator+(difference_type __n)
const
1033 {
return move_iterator(_M_current + __n); }
1036 operator+=(difference_type __n)
1043 operator-(difference_type __n)
const
1044 {
return move_iterator(_M_current - __n); }
1047 operator-=(difference_type __n)
1054 operator[](difference_type __n)
const
1055 {
return std::move(_M_current[__n]); }
1061 template<
typename _IteratorL,
typename _IteratorR>
1063 operator==(
const move_iterator<_IteratorL>& __x,
1064 const move_iterator<_IteratorR>& __y)
1065 {
return __x.base() == __y.base(); }
1067 template<
typename _Iterator>
1069 operator==(
const move_iterator<_Iterator>& __x,
1070 const move_iterator<_Iterator>& __y)
1071 {
return __x.base() == __y.base(); }
1073 template<
typename _IteratorL,
typename _IteratorR>
1075 operator!=(
const move_iterator<_IteratorL>& __x,
1076 const move_iterator<_IteratorR>& __y)
1077 {
return !(__x == __y); }
1079 template<
typename _Iterator>
1081 operator!=(
const move_iterator<_Iterator>& __x,
1082 const move_iterator<_Iterator>& __y)
1083 {
return !(__x == __y); }
1085 template<
typename _IteratorL,
typename _IteratorR>
1087 operator<(const move_iterator<_IteratorL>& __x,
1088 const move_iterator<_IteratorR>& __y)
1089 {
return __x.base() < __y.base(); }
1091 template<
typename _Iterator>
1093 operator<(const move_iterator<_Iterator>& __x,
1094 const move_iterator<_Iterator>& __y)
1095 {
return __x.base() < __y.base(); }
1097 template<
typename _IteratorL,
typename _IteratorR>
1099 operator<=(const move_iterator<_IteratorL>& __x,
1100 const move_iterator<_IteratorR>& __y)
1101 {
return !(__y < __x); }
1103 template<
typename _Iterator>
1105 operator<=(const move_iterator<_Iterator>& __x,
1106 const move_iterator<_Iterator>& __y)
1107 {
return !(__y < __x); }
1109 template<
typename _IteratorL,
typename _IteratorR>
1111 operator>(
const move_iterator<_IteratorL>& __x,
1112 const move_iterator<_IteratorR>& __y)
1113 {
return __y < __x; }
1115 template<
typename _Iterator>
1117 operator>(
const move_iterator<_Iterator>& __x,
1118 const move_iterator<_Iterator>& __y)
1119 {
return __y < __x; }
1121 template<
typename _IteratorL,
typename _IteratorR>
1123 operator>=(
const move_iterator<_IteratorL>& __x,
1124 const move_iterator<_IteratorR>& __y)
1125 {
return !(__x < __y); }
1127 template<
typename _Iterator>
1129 operator>=(
const move_iterator<_Iterator>& __x,
1130 const move_iterator<_Iterator>& __y)
1131 {
return !(__x < __y); }
1134 template<
typename _IteratorL,
typename _IteratorR>
1136 operator-(
const move_iterator<_IteratorL>& __x,
1137 const move_iterator<_IteratorR>& __y)
1138 -> decltype(__x.base() - __y.base())
1139 {
return __x.base() - __y.base(); }
1141 template<
typename _Iterator>
1143 operator-(
const move_iterator<_Iterator>& __x,
1144 const move_iterator<_Iterator>& __y)
1145 -> decltype(__x.base() - __y.base())
1146 {
return __x.base() - __y.base(); }
1148 template<
typename _Iterator>
1149 inline move_iterator<_Iterator>
1150 operator+(
typename move_iterator<_Iterator>::difference_type __n,
1151 const move_iterator<_Iterator>& __x)
1152 {
return __x + __n; }
1154 template<
typename _Iterator>
1155 inline move_iterator<_Iterator>
1156 make_move_iterator(_Iterator __i)
1157 {
return move_iterator<_Iterator>(__i); }
1159 template<
typename _Iterator,
typename _ReturnType
1160 =
typename conditional<__move_if_noexcept_cond
1161 <
typename iterator_traits<_Iterator>::value_type>::value,
1162 _Iterator, move_iterator<_Iterator>>::type>
1164 __make_move_if_noexcept_iterator(_Iterator __i)
1165 {
return _ReturnType(__i); }
1169 _GLIBCXX_END_NAMESPACE_VERSION
1172 #define _GLIBCXX_MAKE_MOVE_ITERATOR(_Iter) std::make_move_iterator(_Iter)
1173 #define _GLIBCXX_MAKE_MOVE_IF_NOEXCEPT_ITERATOR(_Iter) \
1174 std::__make_move_if_noexcept_iterator(_Iter)
1176 #define _GLIBCXX_MAKE_MOVE_ITERATOR(_Iter) (_Iter)
1177 #define _GLIBCXX_MAKE_MOVE_IF_NOEXCEPT_ITERATOR(_Iter) (_Iter)
iterator_type base() const
complex< _Tp > operator+(const complex< _Tp > &__x, const complex< _Tp > &__y)
Return new complex value x plus y.
Uniform interface to all pointer-like types.
front_insert_iterator< _Container > front_inserter(_Container &__x)
reference operator[](difference_type __n) const
front_insert_iterator operator++(int)
Simply returns *this. (This iterator does not move.)
reverse_iterator operator+(difference_type __n) const
Turns assignment into insertion.
_Container container_type
A nested typedef for the type of whatever container you used.
pointer operator->() const
reverse_iterator(const reverse_iterator &__x)
reverse_iterator & operator++()
back_insert_iterator & operator=(const typename _Container::value_type &__value)
front_insert_iterator(_Container &__x)
The only way to create this iterator is with a container.
Turns assignment into insertion.
reverse_iterator(const reverse_iterator< _Iter > &__x)
Turns assignment into insertion.
reverse_iterator & operator--()
_Container container_type
A nested typedef for the type of whatever container you used.
front_insert_iterator & operator++()
Simply returns *this. (This iterator does not move.)
insert_iterator & operator=(const typename _Container::value_type &__value)
_Container container_type
A nested typedef for the type of whatever container you used.
back_insert_iterator & operator++()
Simply returns *this. (This iterator does not move.)
insert_iterator & operator++(int)
Simply returns *this. (This iterator does not move.)
insert_iterator & operator*()
Simply returns *this.
back_insert_iterator operator++(int)
Simply returns *this. (This iterator does not move.)
reverse_iterator(iterator_type __x)
reverse_iterator operator-(difference_type __n) const
reverse_iterator & operator+=(difference_type __n)
back_insert_iterator(_Container &__x)
The only way to create this iterator is with a container.
insert_iterator & operator++()
Simply returns *this. (This iterator does not move.)
reverse_iterator operator++(int)
front_insert_iterator & operator=(const typename _Container::value_type &__value)
reference operator*() const
front_insert_iterator & operator*()
Simply returns *this.
complex< _Tp > operator-(const complex< _Tp > &__x, const complex< _Tp > &__y)
Return new complex value x minus y.
reverse_iterator operator--(int)
insert_iterator< _Container > inserter(_Container &__x, _Iterator __i)
back_insert_iterator< _Container > back_inserter(_Container &__x)
insert_iterator(_Container &__x, typename _Container::iterator __i)
back_insert_iterator & operator*()
Simply returns *this.
reference operator[](size_t __position)
Array-indexing support.
reverse_iterator & operator-=(difference_type __n)