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()) { }
741 operator*() const _GLIBCXX_NOEXCEPT
742 {
return *_M_current; }
745 operator->() const _GLIBCXX_NOEXCEPT
746 {
return _M_current; }
749 operator++() _GLIBCXX_NOEXCEPT
756 operator++(
int) _GLIBCXX_NOEXCEPT
757 {
return __normal_iterator(_M_current++); }
761 operator--() _GLIBCXX_NOEXCEPT
768 operator--(
int) _GLIBCXX_NOEXCEPT
769 {
return __normal_iterator(_M_current--); }
773 operator[](difference_type __n)
const _GLIBCXX_NOEXCEPT
774 {
return _M_current[__n]; }
777 operator+=(difference_type __n) _GLIBCXX_NOEXCEPT
778 { _M_current += __n;
return *
this; }
781 operator+(difference_type __n)
const _GLIBCXX_NOEXCEPT
782 {
return __normal_iterator(_M_current + __n); }
785 operator-=(difference_type __n) _GLIBCXX_NOEXCEPT
786 { _M_current -= __n;
return *
this; }
789 operator-(difference_type __n)
const _GLIBCXX_NOEXCEPT
790 {
return __normal_iterator(_M_current - __n); }
793 base() const _GLIBCXX_NOEXCEPT
794 {
return _M_current; }
806 template<
typename _IteratorL,
typename _IteratorR,
typename _Container>
808 operator==(
const __normal_iterator<_IteratorL, _Container>& __lhs,
809 const __normal_iterator<_IteratorR, _Container>& __rhs)
811 {
return __lhs.base() == __rhs.base(); }
813 template<
typename _Iterator,
typename _Container>
815 operator==(
const __normal_iterator<_Iterator, _Container>& __lhs,
816 const __normal_iterator<_Iterator, _Container>& __rhs)
818 {
return __lhs.base() == __rhs.base(); }
820 template<
typename _IteratorL,
typename _IteratorR,
typename _Container>
822 operator!=(
const __normal_iterator<_IteratorL, _Container>& __lhs,
823 const __normal_iterator<_IteratorR, _Container>& __rhs)
825 {
return __lhs.base() != __rhs.base(); }
827 template<
typename _Iterator,
typename _Container>
829 operator!=(
const __normal_iterator<_Iterator, _Container>& __lhs,
830 const __normal_iterator<_Iterator, _Container>& __rhs)
832 {
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(); }
849 template<
typename _IteratorL,
typename _IteratorR,
typename _Container>
851 operator>(
const __normal_iterator<_IteratorL, _Container>& __lhs,
852 const __normal_iterator<_IteratorR, _Container>& __rhs)
854 {
return __lhs.base() > __rhs.base(); }
856 template<
typename _Iterator,
typename _Container>
858 operator>(
const __normal_iterator<_Iterator, _Container>& __lhs,
859 const __normal_iterator<_Iterator, _Container>& __rhs)
861 {
return __lhs.base() > __rhs.base(); }
863 template<
typename _IteratorL,
typename _IteratorR,
typename _Container>
865 operator<=(const __normal_iterator<_IteratorL, _Container>& __lhs,
866 const __normal_iterator<_IteratorR, _Container>& __rhs)
868 {
return __lhs.base() <= __rhs.base(); }
870 template<
typename _Iterator,
typename _Container>
872 operator<=(const __normal_iterator<_Iterator, _Container>& __lhs,
873 const __normal_iterator<_Iterator, _Container>& __rhs)
875 {
return __lhs.base() <= __rhs.base(); }
877 template<
typename _IteratorL,
typename _IteratorR,
typename _Container>
879 operator>=(
const __normal_iterator<_IteratorL, _Container>& __lhs,
880 const __normal_iterator<_IteratorR, _Container>& __rhs)
882 {
return __lhs.base() >= __rhs.base(); }
884 template<
typename _Iterator,
typename _Container>
886 operator>=(
const __normal_iterator<_Iterator, _Container>& __lhs,
887 const __normal_iterator<_Iterator, _Container>& __rhs)
889 {
return __lhs.base() >= __rhs.base(); }
895 template<
typename _IteratorL,
typename _IteratorR,
typename _Container>
896 #if __cplusplus >= 201103L
899 operator-(
const __normal_iterator<_IteratorL, _Container>& __lhs,
900 const __normal_iterator<_IteratorR, _Container>& __rhs) noexcept
901 -> decltype(__lhs.base() - __rhs.base())
903 inline typename __normal_iterator<_IteratorL, _Container>::difference_type
904 operator-(
const __normal_iterator<_IteratorL, _Container>& __lhs,
905 const __normal_iterator<_IteratorR, _Container>& __rhs)
907 {
return __lhs.base() - __rhs.base(); }
909 template<
typename _Iterator,
typename _Container>
910 inline typename __normal_iterator<_Iterator, _Container>::difference_type
911 operator-(
const __normal_iterator<_Iterator, _Container>& __lhs,
912 const __normal_iterator<_Iterator, _Container>& __rhs)
914 {
return __lhs.base() - __rhs.base(); }
916 template<
typename _Iterator,
typename _Container>
917 inline __normal_iterator<_Iterator, _Container>
918 operator+(
typename __normal_iterator<_Iterator, _Container>::difference_type
919 __n,
const __normal_iterator<_Iterator, _Container>& __i)
921 {
return __normal_iterator<_Iterator, _Container>(__i.base() + __n); }
923 _GLIBCXX_END_NAMESPACE_VERSION
926 #if __cplusplus >= 201103L
928 namespace std _GLIBCXX_VISIBILITY(default)
930 _GLIBCXX_BEGIN_NAMESPACE_VERSION
946 template<
typename _Iterator>
950 _Iterator _M_current;
952 typedef iterator_traits<_Iterator> __traits_type;
955 typedef _Iterator iterator_type;
956 typedef typename __traits_type::iterator_category iterator_category;
957 typedef typename __traits_type::value_type value_type;
958 typedef typename __traits_type::difference_type difference_type;
960 typedef _Iterator pointer;
961 typedef value_type&& reference;
967 move_iterator(iterator_type __i)
968 : _M_current(__i) { }
970 template<
typename _Iter>
971 move_iterator(
const move_iterator<_Iter>& __i)
972 : _M_current(__i.base()) { }
976 {
return _M_current; }
984 {
return _M_current; }
996 move_iterator __tmp = *
this;
1011 move_iterator __tmp = *
this;
1017 operator+(difference_type __n)
const
1018 {
return move_iterator(_M_current + __n); }
1021 operator+=(difference_type __n)
1028 operator-(difference_type __n)
const
1029 {
return move_iterator(_M_current - __n); }
1032 operator-=(difference_type __n)
1039 operator[](difference_type __n)
const
1046 template<
typename _IteratorL,
typename _IteratorR>
1048 operator==(
const move_iterator<_IteratorL>& __x,
1049 const move_iterator<_IteratorR>& __y)
1050 {
return __x.base() == __y.base(); }
1052 template<
typename _Iterator>
1054 operator==(
const move_iterator<_Iterator>& __x,
1055 const move_iterator<_Iterator>& __y)
1056 {
return __x.base() == __y.base(); }
1058 template<
typename _IteratorL,
typename _IteratorR>
1060 operator!=(
const move_iterator<_IteratorL>& __x,
1061 const move_iterator<_IteratorR>& __y)
1062 {
return !(__x == __y); }
1064 template<
typename _Iterator>
1066 operator!=(
const move_iterator<_Iterator>& __x,
1067 const move_iterator<_Iterator>& __y)
1068 {
return !(__x == __y); }
1070 template<
typename _IteratorL,
typename _IteratorR>
1072 operator<(const move_iterator<_IteratorL>& __x,
1073 const move_iterator<_IteratorR>& __y)
1074 {
return __x.base() < __y.base(); }
1076 template<
typename _Iterator>
1078 operator<(const move_iterator<_Iterator>& __x,
1079 const move_iterator<_Iterator>& __y)
1080 {
return __x.base() < __y.base(); }
1082 template<
typename _IteratorL,
typename _IteratorR>
1084 operator<=(const move_iterator<_IteratorL>& __x,
1085 const move_iterator<_IteratorR>& __y)
1086 {
return !(__y < __x); }
1088 template<
typename _Iterator>
1090 operator<=(const move_iterator<_Iterator>& __x,
1091 const move_iterator<_Iterator>& __y)
1092 {
return !(__y < __x); }
1094 template<
typename _IteratorL,
typename _IteratorR>
1096 operator>(
const move_iterator<_IteratorL>& __x,
1097 const move_iterator<_IteratorR>& __y)
1098 {
return __y < __x; }
1100 template<
typename _Iterator>
1102 operator>(
const move_iterator<_Iterator>& __x,
1103 const move_iterator<_Iterator>& __y)
1104 {
return __y < __x; }
1106 template<
typename _IteratorL,
typename _IteratorR>
1108 operator>=(
const move_iterator<_IteratorL>& __x,
1109 const move_iterator<_IteratorR>& __y)
1110 {
return !(__x < __y); }
1112 template<
typename _Iterator>
1114 operator>=(
const move_iterator<_Iterator>& __x,
1115 const move_iterator<_Iterator>& __y)
1116 {
return !(__x < __y); }
1119 template<
typename _IteratorL,
typename _IteratorR>
1121 operator-(
const move_iterator<_IteratorL>& __x,
1122 const move_iterator<_IteratorR>& __y)
1123 -> decltype(__x.base() - __y.base())
1124 {
return __x.base() - __y.base(); }
1126 template<
typename _Iterator>
1128 operator-(
const move_iterator<_Iterator>& __x,
1129 const move_iterator<_Iterator>& __y)
1130 -> decltype(__x.base() - __y.base())
1131 {
return __x.base() - __y.base(); }
1133 template<
typename _Iterator>
1134 inline move_iterator<_Iterator>
1135 operator+(
typename move_iterator<_Iterator>::difference_type __n,
1136 const move_iterator<_Iterator>& __x)
1137 {
return __x + __n; }
1139 template<
typename _Iterator>
1140 inline move_iterator<_Iterator>
1141 make_move_iterator(_Iterator __i)
1142 {
return move_iterator<_Iterator>(__i); }
1144 template<
typename _Iterator,
typename _ReturnType
1145 =
typename conditional<__move_if_noexcept_cond
1146 <
typename iterator_traits<_Iterator>::value_type>::value,
1147 _Iterator, move_iterator<_Iterator>>::type>
1149 __make_move_if_noexcept_iterator(_Iterator __i)
1150 {
return _ReturnType(__i); }
1154 _GLIBCXX_END_NAMESPACE_VERSION
1157 #define _GLIBCXX_MAKE_MOVE_ITERATOR(_Iter) std::make_move_iterator(_Iter)
1158 #define _GLIBCXX_MAKE_MOVE_IF_NOEXCEPT_ITERATOR(_Iter) \
1159 std::__make_move_if_noexcept_iterator(_Iter)
1161 #define _GLIBCXX_MAKE_MOVE_ITERATOR(_Iter) (_Iter)
1162 #define _GLIBCXX_MAKE_MOVE_IF_NOEXCEPT_ITERATOR(_Iter) (_Iter)
constexpr std::remove_reference< _Tp >::type && move(_Tp &&__t) noexcept
Convert a value to an rvalue.
reverse_iterator & operator++()
reverse_iterator operator-(difference_type __n) const
front_insert_iterator< _Container > front_inserter(_Container &__x)
front_insert_iterator operator++(int)
Simply returns *this. (This iterator does not move.)
back_insert_iterator operator++(int)
Simply returns *this. (This iterator does not move.)
back_insert_iterator(_Container &__x)
The only way to create this iterator is with a container.
front_insert_iterator(_Container &__x)
The only way to create this iterator is with a container.
iterator_type base() const
reverse_iterator & operator+=(difference_type __n)
reverse_iterator & operator--()
GNU extensions for public use.
pointer operator->() const
reverse_iterator(iterator_type __x)
reference operator[](difference_type __n) const
back_insert_iterator & operator++()
Simply returns *this. (This iterator does not move.)
back_insert_iterator & operator*()
Simply returns *this.
back_insert_iterator< _Container > back_inserter(_Container &__x)
ISO C++ entities toplevel namespace is std.
reverse_iterator(const reverse_iterator< _Iter > &__x)
reference operator*() const
reverse_iterator & operator-=(difference_type __n)
insert_iterator & operator++(int)
Simply returns *this. (This iterator does not move.)
Turns assignment into insertion.
reverse_iterator(const reverse_iterator &__x)
_Container container_type
A nested typedef for the type of whatever container you used.
_Container container_type
A nested typedef for the type of whatever container you used.
reverse_iterator operator+(difference_type __n) const
insert_iterator & operator*()
Simply returns *this.
front_insert_iterator & operator++()
Simply returns *this. (This iterator does not move.)
bool operator>=(const basic_string< _CharT, _Traits, _Alloc > &__lhs, const basic_string< _CharT, _Traits, _Alloc > &__rhs)
Test if string doesn't precede string.
insert_iterator(_Container &__x, typename _Container::iterator __i)
basic_string< _CharT, _Traits, _Alloc > operator+(const basic_string< _CharT, _Traits, _Alloc > &__lhs, const basic_string< _CharT, _Traits, _Alloc > &__rhs)
Concatenate two strings.
front_insert_iterator & operator=(const typename _Container::value_type &__value)
bool operator>(const basic_string< _CharT, _Traits, _Alloc > &__lhs, const basic_string< _CharT, _Traits, _Alloc > &__rhs)
Test if string follows string.
front_insert_iterator & operator*()
Simply returns *this.
insert_iterator & operator=(const typename _Container::value_type &__value)
insert_iterator< _Container > inserter(_Container &__x, _Iterator __i)
Turns assignment into insertion.
reverse_iterator operator--(int)
insert_iterator & operator++()
Simply returns *this. (This iterator does not move.)
Turns assignment into insertion.
back_insert_iterator & operator=(const typename _Container::value_type &__value)
reverse_iterator operator++(int)
_Container container_type
A nested typedef for the type of whatever container you used.