60 #ifndef _STL_ITERATOR_H
61 #define _STL_ITERATOR_H 1
67 namespace std _GLIBCXX_VISIBILITY(default)
69 _GLIBCXX_BEGIN_NAMESPACE_VERSION
95 template<
typename _Iterator>
97 :
public iterator<typename iterator_traits<_Iterator>::iterator_category,
98 typename iterator_traits<_Iterator>::value_type,
99 typename iterator_traits<_Iterator>::difference_type,
100 typename iterator_traits<_Iterator>::pointer,
101 typename iterator_traits<_Iterator>::reference>
106 typedef iterator_traits<_Iterator> __traits_type;
109 typedef _Iterator iterator_type;
110 typedef typename __traits_type::difference_type difference_type;
111 typedef typename __traits_type::pointer pointer;
112 typedef typename __traits_type::reference reference;
132 : current(__x.current) { }
138 template<
typename _Iter>
140 : current(__x.
base()) { }
162 _Iterator __tmp = current;
276 {
return *(*
this + __n); }
289 template<
typename _Iterator>
293 {
return __x.
base() == __y.
base(); }
295 template<
typename _Iterator>
297 operator<(const reverse_iterator<_Iterator>& __x,
298 const reverse_iterator<_Iterator>& __y)
299 {
return __y.base() < __x.base(); }
301 template<
typename _Iterator>
303 operator!=(
const reverse_iterator<_Iterator>& __x,
304 const reverse_iterator<_Iterator>& __y)
305 {
return !(__x == __y); }
307 template<
typename _Iterator>
309 operator>(
const reverse_iterator<_Iterator>& __x,
310 const reverse_iterator<_Iterator>& __y)
311 {
return __y < __x; }
313 template<
typename _Iterator>
315 operator<=(const reverse_iterator<_Iterator>& __x,
316 const reverse_iterator<_Iterator>& __y)
317 {
return !(__y < __x); }
319 template<
typename _Iterator>
321 operator>=(
const reverse_iterator<_Iterator>& __x,
322 const reverse_iterator<_Iterator>& __y)
323 {
return !(__x < __y); }
325 template<
typename _Iterator>
326 inline typename reverse_iterator<_Iterator>::difference_type
327 operator-(
const reverse_iterator<_Iterator>& __x,
328 const reverse_iterator<_Iterator>& __y)
329 {
return __y.base() - __x.base(); }
331 template<
typename _Iterator>
332 inline reverse_iterator<_Iterator>
333 operator+(
typename reverse_iterator<_Iterator>::difference_type __n,
334 const reverse_iterator<_Iterator>& __x)
335 {
return reverse_iterator<_Iterator>(__x.base() - __n); }
339 template<
typename _IteratorL,
typename _IteratorR>
341 operator==(
const reverse_iterator<_IteratorL>& __x,
342 const reverse_iterator<_IteratorR>& __y)
343 {
return __x.base() == __y.base(); }
345 template<
typename _IteratorL,
typename _IteratorR>
347 operator<(const reverse_iterator<_IteratorL>& __x,
348 const reverse_iterator<_IteratorR>& __y)
349 {
return __y.base() < __x.base(); }
351 template<
typename _IteratorL,
typename _IteratorR>
353 operator!=(
const reverse_iterator<_IteratorL>& __x,
354 const reverse_iterator<_IteratorR>& __y)
355 {
return !(__x == __y); }
357 template<
typename _IteratorL,
typename _IteratorR>
359 operator>(
const reverse_iterator<_IteratorL>& __x,
360 const reverse_iterator<_IteratorR>& __y)
361 {
return __y < __x; }
363 template<
typename _IteratorL,
typename _IteratorR>
365 operator<=(const reverse_iterator<_IteratorL>& __x,
366 const reverse_iterator<_IteratorR>& __y)
367 {
return !(__y < __x); }
369 template<
typename _IteratorL,
typename _IteratorR>
371 operator>=(
const reverse_iterator<_IteratorL>& __x,
372 const reverse_iterator<_IteratorR>& __y)
373 {
return !(__x < __y); }
375 template<
typename _IteratorL,
typename _IteratorR>
376 #if __cplusplus >= 201103L
379 operator-(
const reverse_iterator<_IteratorL>& __x,
380 const reverse_iterator<_IteratorR>& __y)
381 -> decltype(__y.base() - __x.base())
383 inline typename reverse_iterator<_IteratorL>::difference_type
384 operator-(
const reverse_iterator<_IteratorL>& __x,
385 const reverse_iterator<_IteratorR>& __y)
387 {
return __y.base() - __x.base(); }
401 template<
typename _Container>
403 :
public iterator<output_iterator_tag, void, void, void, void>
406 _Container* container;
427 #if __cplusplus < 201103L
429 operator=(
typename _Container::const_reference __value)
431 container->push_back(__value);
436 operator=(
const typename _Container::value_type& __value)
438 container->push_back(__value);
443 operator=(
typename _Container::value_type&& __value)
445 container->push_back(
std::move(__value));
477 template<
typename _Container>
478 inline back_insert_iterator<_Container>
492 template<
typename _Container>
494 :
public iterator<output_iterator_tag, void, void, void, void>
497 _Container* container;
517 #if __cplusplus < 201103L
519 operator=(
typename _Container::const_reference __value)
521 container->push_front(__value);
526 operator=(
const typename _Container::value_type& __value)
528 container->push_front(__value);
533 operator=(
typename _Container::value_type&& __value)
535 container->push_front(
std::move(__value));
567 template<
typename _Container>
568 inline front_insert_iterator<_Container>
586 template<
typename _Container>
588 :
public iterator<output_iterator_tag, void, void, void, void>
591 _Container* container;
592 typename _Container::iterator iter;
603 : container(&__x), iter(__i) {}
628 #if __cplusplus < 201103L
630 operator=(
typename _Container::const_reference __value)
632 iter = container->insert(iter, __value);
638 operator=(
const typename _Container::value_type& __value)
640 iter = container->insert(iter, __value);
646 operator=(
typename _Container::value_type&& __value)
648 iter = container->insert(iter,
std::move(__value));
681 template<
typename _Container,
typename _Iterator>
682 inline insert_iterator<_Container>
686 typename _Container::iterator(__i));
691 _GLIBCXX_END_NAMESPACE_VERSION
694 namespace __gnu_cxx _GLIBCXX_VISIBILITY(default)
696 _GLIBCXX_BEGIN_NAMESPACE_VERSION
705 using std::iterator_traits;
707 template<
typename _Iterator,
typename _Container>
708 class __normal_iterator
711 _Iterator _M_current;
713 typedef iterator_traits<_Iterator> __traits_type;
716 typedef _Iterator iterator_type;
717 typedef typename __traits_type::iterator_category iterator_category;
718 typedef typename __traits_type::value_type value_type;
719 typedef typename __traits_type::difference_type difference_type;
720 typedef typename __traits_type::reference reference;
721 typedef typename __traits_type::pointer pointer;
723 _GLIBCXX_CONSTEXPR __normal_iterator() : _M_current(_Iterator()) { }
726 __normal_iterator(
const _Iterator& __i) : _M_current(__i) { }
729 template<
typename _Iter>
730 __normal_iterator(
const __normal_iterator<_Iter,
731 typename __enable_if<
732 (std::__are_same<_Iter, typename _Container::pointer>::__value),
733 _Container>::__type>& __i)
734 : _M_current(__i.base()) { }
739 {
return *_M_current; }
743 {
return _M_current; }
754 {
return __normal_iterator(_M_current++); }
766 {
return __normal_iterator(_M_current--); }
770 operator[](
const difference_type& __n)
const
771 {
return _M_current[__n]; }
774 operator+=(
const difference_type& __n)
775 { _M_current += __n;
return *
this; }
778 operator+(
const difference_type& __n)
const
779 {
return __normal_iterator(_M_current + __n); }
782 operator-=(
const difference_type& __n)
783 { _M_current -= __n;
return *
this; }
786 operator-(
const difference_type& __n)
const
787 {
return __normal_iterator(_M_current - __n); }
791 {
return _M_current; }
803 template<
typename _IteratorL,
typename _IteratorR,
typename _Container>
805 operator==(
const __normal_iterator<_IteratorL, _Container>& __lhs,
806 const __normal_iterator<_IteratorR, _Container>& __rhs)
807 {
return __lhs.base() == __rhs.base(); }
809 template<
typename _Iterator,
typename _Container>
811 operator==(
const __normal_iterator<_Iterator, _Container>& __lhs,
812 const __normal_iterator<_Iterator, _Container>& __rhs)
813 {
return __lhs.base() == __rhs.base(); }
815 template<
typename _IteratorL,
typename _IteratorR,
typename _Container>
817 operator!=(
const __normal_iterator<_IteratorL, _Container>& __lhs,
818 const __normal_iterator<_IteratorR, _Container>& __rhs)
819 {
return __lhs.base() != __rhs.base(); }
821 template<
typename _Iterator,
typename _Container>
823 operator!=(
const __normal_iterator<_Iterator, _Container>& __lhs,
824 const __normal_iterator<_Iterator, _Container>& __rhs)
825 {
return __lhs.base() != __rhs.base(); }
828 template<
typename _IteratorL,
typename _IteratorR,
typename _Container>
830 operator<(const __normal_iterator<_IteratorL, _Container>& __lhs,
831 const __normal_iterator<_IteratorR, _Container>& __rhs)
832 {
return __lhs.base() < __rhs.base(); }
834 template<
typename _Iterator,
typename _Container>
836 operator<(const __normal_iterator<_Iterator, _Container>& __lhs,
837 const __normal_iterator<_Iterator, _Container>& __rhs)
838 {
return __lhs.base() < __rhs.base(); }
840 template<
typename _IteratorL,
typename _IteratorR,
typename _Container>
842 operator>(
const __normal_iterator<_IteratorL, _Container>& __lhs,
843 const __normal_iterator<_IteratorR, _Container>& __rhs)
844 {
return __lhs.base() > __rhs.base(); }
846 template<
typename _Iterator,
typename _Container>
848 operator>(
const __normal_iterator<_Iterator, _Container>& __lhs,
849 const __normal_iterator<_Iterator, _Container>& __rhs)
850 {
return __lhs.base() > __rhs.base(); }
852 template<
typename _IteratorL,
typename _IteratorR,
typename _Container>
854 operator<=(const __normal_iterator<_IteratorL, _Container>& __lhs,
855 const __normal_iterator<_IteratorR, _Container>& __rhs)
856 {
return __lhs.base() <= __rhs.base(); }
858 template<
typename _Iterator,
typename _Container>
860 operator<=(const __normal_iterator<_Iterator, _Container>& __lhs,
861 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)
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)
874 {
return __lhs.base() >= __rhs.base(); }
880 template<
typename _IteratorL,
typename _IteratorR,
typename _Container>
881 #if __cplusplus >= 201103L
884 operator-(
const __normal_iterator<_IteratorL, _Container>& __lhs,
885 const __normal_iterator<_IteratorR, _Container>& __rhs)
886 -> decltype(__lhs.base() - __rhs.base())
888 inline typename __normal_iterator<_IteratorL, _Container>::difference_type
889 operator-(
const __normal_iterator<_IteratorL, _Container>& __lhs,
890 const __normal_iterator<_IteratorR, _Container>& __rhs)
892 {
return __lhs.base() - __rhs.base(); }
894 template<
typename _Iterator,
typename _Container>
895 inline typename __normal_iterator<_Iterator, _Container>::difference_type
896 operator-(
const __normal_iterator<_Iterator, _Container>& __lhs,
897 const __normal_iterator<_Iterator, _Container>& __rhs)
898 {
return __lhs.base() - __rhs.base(); }
900 template<
typename _Iterator,
typename _Container>
901 inline __normal_iterator<_Iterator, _Container>
902 operator+(
typename __normal_iterator<_Iterator, _Container>::difference_type
903 __n,
const __normal_iterator<_Iterator, _Container>& __i)
904 {
return __normal_iterator<_Iterator, _Container>(__i.base() + __n); }
906 _GLIBCXX_END_NAMESPACE_VERSION
909 #if __cplusplus >= 201103L
911 namespace std _GLIBCXX_VISIBILITY(default)
913 _GLIBCXX_BEGIN_NAMESPACE_VERSION
929 template<
typename _Iterator>
933 _Iterator _M_current;
935 typedef iterator_traits<_Iterator> __traits_type;
938 typedef _Iterator iterator_type;
939 typedef typename __traits_type::iterator_category iterator_category;
940 typedef typename __traits_type::value_type value_type;
941 typedef typename __traits_type::difference_type difference_type;
943 typedef _Iterator pointer;
944 typedef value_type&& reference;
950 move_iterator(iterator_type __i)
951 : _M_current(__i) { }
953 template<
typename _Iter>
954 move_iterator(
const move_iterator<_Iter>& __i)
955 : _M_current(__i.base()) { }
959 {
return _M_current; }
967 {
return _M_current; }
979 move_iterator __tmp = *
this;
994 move_iterator __tmp = *
this;
1000 operator+(difference_type __n)
const
1001 {
return move_iterator(_M_current + __n); }
1004 operator+=(difference_type __n)
1011 operator-(difference_type __n)
const
1012 {
return move_iterator(_M_current - __n); }
1015 operator-=(difference_type __n)
1022 operator[](difference_type __n)
const
1029 template<
typename _IteratorL,
typename _IteratorR>
1031 operator==(
const move_iterator<_IteratorL>& __x,
1032 const move_iterator<_IteratorR>& __y)
1033 {
return __x.base() == __y.base(); }
1035 template<
typename _Iterator>
1037 operator==(
const move_iterator<_Iterator>& __x,
1038 const move_iterator<_Iterator>& __y)
1039 {
return __x.base() == __y.base(); }
1041 template<
typename _IteratorL,
typename _IteratorR>
1043 operator!=(
const move_iterator<_IteratorL>& __x,
1044 const move_iterator<_IteratorR>& __y)
1045 {
return !(__x == __y); }
1047 template<
typename _Iterator>
1049 operator!=(
const move_iterator<_Iterator>& __x,
1050 const move_iterator<_Iterator>& __y)
1051 {
return !(__x == __y); }
1053 template<
typename _IteratorL,
typename _IteratorR>
1055 operator<(const move_iterator<_IteratorL>& __x,
1056 const move_iterator<_IteratorR>& __y)
1057 {
return __x.base() < __y.base(); }
1059 template<
typename _Iterator>
1061 operator<(const move_iterator<_Iterator>& __x,
1062 const move_iterator<_Iterator>& __y)
1063 {
return __x.base() < __y.base(); }
1065 template<
typename _IteratorL,
typename _IteratorR>
1067 operator<=(const move_iterator<_IteratorL>& __x,
1068 const move_iterator<_IteratorR>& __y)
1069 {
return !(__y < __x); }
1071 template<
typename _Iterator>
1073 operator<=(const move_iterator<_Iterator>& __x,
1074 const move_iterator<_Iterator>& __y)
1075 {
return !(__y < __x); }
1077 template<
typename _IteratorL,
typename _IteratorR>
1079 operator>(
const move_iterator<_IteratorL>& __x,
1080 const move_iterator<_IteratorR>& __y)
1081 {
return __y < __x; }
1083 template<
typename _Iterator>
1085 operator>(
const move_iterator<_Iterator>& __x,
1086 const move_iterator<_Iterator>& __y)
1087 {
return __y < __x; }
1089 template<
typename _IteratorL,
typename _IteratorR>
1091 operator>=(
const move_iterator<_IteratorL>& __x,
1092 const move_iterator<_IteratorR>& __y)
1093 {
return !(__x < __y); }
1095 template<
typename _Iterator>
1097 operator>=(
const move_iterator<_Iterator>& __x,
1098 const move_iterator<_Iterator>& __y)
1099 {
return !(__x < __y); }
1102 template<
typename _IteratorL,
typename _IteratorR>
1104 operator-(
const move_iterator<_IteratorL>& __x,
1105 const move_iterator<_IteratorR>& __y)
1106 -> decltype(__x.base() - __y.base())
1107 {
return __x.base() - __y.base(); }
1109 template<
typename _Iterator>
1111 operator-(
const move_iterator<_Iterator>& __x,
1112 const move_iterator<_Iterator>& __y)
1113 -> decltype(__x.base() - __y.base())
1114 {
return __x.base() - __y.base(); }
1116 template<
typename _Iterator>
1117 inline move_iterator<_Iterator>
1118 operator+(
typename move_iterator<_Iterator>::difference_type __n,
1119 const move_iterator<_Iterator>& __x)
1120 {
return __x + __n; }
1122 template<
typename _Iterator>
1123 inline move_iterator<_Iterator>
1124 make_move_iterator(_Iterator __i)
1125 {
return move_iterator<_Iterator>(__i); }
1127 template<
typename _Iterator,
typename _ReturnType
1128 =
typename conditional<__move_if_noexcept_cond
1129 <
typename iterator_traits<_Iterator>::value_type>::value,
1130 _Iterator, move_iterator<_Iterator>>::type>
1132 __make_move_if_noexcept_iterator(_Iterator __i)
1133 {
return _ReturnType(__i); }
1137 _GLIBCXX_END_NAMESPACE_VERSION
1140 #define _GLIBCXX_MAKE_MOVE_ITERATOR(_Iter) std::make_move_iterator(_Iter)
1141 #define _GLIBCXX_MAKE_MOVE_IF_NOEXCEPT_ITERATOR(_Iter) \
1142 std::__make_move_if_noexcept_iterator(_Iter)
1144 #define _GLIBCXX_MAKE_MOVE_ITERATOR(_Iter) (_Iter)
1145 #define _GLIBCXX_MAKE_MOVE_IF_NOEXCEPT_ITERATOR(_Iter) (_Iter)
reverse_iterator(iterator_type __x)
front_insert_iterator & operator*()
Simply returns *this.
iterator_type base() const
reverse_iterator & operator--()
insert_iterator< _Container > inserter(_Container &__x, _Iterator __i)
insert_iterator(_Container &__x, typename _Container::iterator __i)
reverse_iterator & operator++()
reverse_iterator operator-(difference_type __n) const
reverse_iterator & operator-=(difference_type __n)
GNU extensions for public use.
insert_iterator & operator++(int)
Simply returns *this. (This iterator does not move.)
reverse_iterator operator++(int)
constexpr std::remove_reference< _Tp >::type && move(_Tp &&__t) noexcept
Convert a value to an rvalue.
back_insert_iterator(_Container &__x)
The only way to create this iterator is with a container.
bool operator>=(const basic_string< _CharT, _Traits, _Alloc > &__lhs, const basic_string< _CharT, _Traits, _Alloc > &__rhs)
Test if string doesn't precede string.
reverse_iterator operator+(difference_type __n) const
reference operator*() const
ISO C++ entities toplevel namespace is std.
_Container container_type
A nested typedef for the type of whatever container you used.
insert_iterator & operator++()
Simply returns *this. (This iterator does not move.)
front_insert_iterator(_Container &__x)
The only way to create this iterator is with a container.
Turns assignment into insertion.
back_insert_iterator & operator++()
Simply returns *this. (This iterator does not move.)
pointer operator->() const
back_insert_iterator & operator=(const typename _Container::value_type &__value)
insert_iterator & operator=(const typename _Container::value_type &__value)
reverse_iterator(const reverse_iterator< _Iter > &__x)
front_insert_iterator< _Container > front_inserter(_Container &__x)
back_insert_iterator operator++(int)
Simply returns *this. (This iterator does not move.)
back_insert_iterator & operator*()
Simply returns *this.
reverse_iterator operator--(int)
reference operator[](difference_type __n) const
front_insert_iterator & operator++()
Simply returns *this. (This iterator does not move.)
Turns assignment into insertion.
insert_iterator & operator*()
Simply returns *this.
_Container container_type
A nested typedef for the type of whatever container you used.
back_insert_iterator< _Container > back_inserter(_Container &__x)
basic_string< _CharT, _Traits, _Alloc > operator+(const basic_string< _CharT, _Traits, _Alloc > &__lhs, const basic_string< _CharT, _Traits, _Alloc > &__rhs)
Concatenate two strings.
Turns assignment into insertion.
front_insert_iterator & operator=(const typename _Container::value_type &__value)
reverse_iterator(const reverse_iterator &__x)
_Container container_type
A nested typedef for the type of whatever container you used.
reverse_iterator & operator+=(difference_type __n)
front_insert_iterator operator++(int)
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 follows string.