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(); }
391 #if __cplusplus > 201103L
392 #define __cpp_lib_make_reverse_iterator 201402
397 template<
typename _Iterator>
398 inline reverse_iterator<_Iterator>
399 make_reverse_iterator(_Iterator __i)
400 {
return reverse_iterator<_Iterator>(__i); }
414 template<
typename _Container>
416 :
public iterator<output_iterator_tag, void, void, void, void>
419 _Container* container;
440 #if __cplusplus < 201103L
442 operator=(
typename _Container::const_reference __value)
444 container->push_back(__value);
449 operator=(
const typename _Container::value_type& __value)
451 container->push_back(__value);
456 operator=(
typename _Container::value_type&& __value)
458 container->push_back(
std::move(__value));
490 template<
typename _Container>
491 inline back_insert_iterator<_Container>
505 template<
typename _Container>
507 :
public iterator<output_iterator_tag, void, void, void, void>
510 _Container* container;
530 #if __cplusplus < 201103L
532 operator=(
typename _Container::const_reference __value)
534 container->push_front(__value);
539 operator=(
const typename _Container::value_type& __value)
541 container->push_front(__value);
546 operator=(
typename _Container::value_type&& __value)
548 container->push_front(
std::move(__value));
580 template<
typename _Container>
581 inline front_insert_iterator<_Container>
599 template<
typename _Container>
601 :
public iterator<output_iterator_tag, void, void, void, void>
604 _Container* container;
605 typename _Container::iterator iter;
616 : container(&__x), iter(__i) {}
641 #if __cplusplus < 201103L
643 operator=(
typename _Container::const_reference __value)
645 iter = container->insert(iter, __value);
651 operator=(
const typename _Container::value_type& __value)
653 iter = container->insert(iter, __value);
659 operator=(
typename _Container::value_type&& __value)
661 iter = container->insert(iter,
std::move(__value));
694 template<
typename _Container,
typename _Iterator>
695 inline insert_iterator<_Container>
699 typename _Container::iterator(__i));
704 _GLIBCXX_END_NAMESPACE_VERSION
707 namespace __gnu_cxx _GLIBCXX_VISIBILITY(default)
709 _GLIBCXX_BEGIN_NAMESPACE_VERSION
718 using std::iterator_traits;
720 template<
typename _Iterator,
typename _Container>
721 class __normal_iterator
724 _Iterator _M_current;
726 typedef iterator_traits<_Iterator> __traits_type;
729 typedef _Iterator iterator_type;
730 typedef typename __traits_type::iterator_category iterator_category;
731 typedef typename __traits_type::value_type value_type;
732 typedef typename __traits_type::difference_type difference_type;
733 typedef typename __traits_type::reference reference;
734 typedef typename __traits_type::pointer pointer;
736 _GLIBCXX_CONSTEXPR __normal_iterator() _GLIBCXX_NOEXCEPT
737 : _M_current(_Iterator()) { }
740 __normal_iterator(
const _Iterator& __i) _GLIBCXX_NOEXCEPT
741 : _M_current(__i) { }
744 template<
typename _Iter>
745 __normal_iterator(
const __normal_iterator<_Iter,
746 typename __enable_if<
747 (std::__are_same<_Iter, typename _Container::pointer>::__value),
748 _Container>::__type>& __i) _GLIBCXX_NOEXCEPT
749 : _M_current(__i.base()) { }
753 operator*() const _GLIBCXX_NOEXCEPT
754 {
return *_M_current; }
757 operator->() const _GLIBCXX_NOEXCEPT
758 {
return _M_current; }
761 operator++() _GLIBCXX_NOEXCEPT
768 operator++(
int) _GLIBCXX_NOEXCEPT
769 {
return __normal_iterator(_M_current++); }
773 operator--() _GLIBCXX_NOEXCEPT
780 operator--(
int) _GLIBCXX_NOEXCEPT
781 {
return __normal_iterator(_M_current--); }
785 operator[](difference_type __n)
const _GLIBCXX_NOEXCEPT
786 {
return _M_current[__n]; }
789 operator+=(difference_type __n) _GLIBCXX_NOEXCEPT
790 { _M_current += __n;
return *
this; }
793 operator+(difference_type __n)
const _GLIBCXX_NOEXCEPT
794 {
return __normal_iterator(_M_current + __n); }
797 operator-=(difference_type __n) _GLIBCXX_NOEXCEPT
798 { _M_current -= __n;
return *
this; }
801 operator-(difference_type __n)
const _GLIBCXX_NOEXCEPT
802 {
return __normal_iterator(_M_current - __n); }
805 base() const _GLIBCXX_NOEXCEPT
806 {
return _M_current; }
818 template<
typename _IteratorL,
typename _IteratorR,
typename _Container>
820 operator==(
const __normal_iterator<_IteratorL, _Container>& __lhs,
821 const __normal_iterator<_IteratorR, _Container>& __rhs)
823 {
return __lhs.base() == __rhs.base(); }
825 template<
typename _Iterator,
typename _Container>
827 operator==(
const __normal_iterator<_Iterator, _Container>& __lhs,
828 const __normal_iterator<_Iterator, _Container>& __rhs)
830 {
return __lhs.base() == __rhs.base(); }
832 template<
typename _IteratorL,
typename _IteratorR,
typename _Container>
834 operator!=(
const __normal_iterator<_IteratorL, _Container>& __lhs,
835 const __normal_iterator<_IteratorR, _Container>& __rhs)
837 {
return __lhs.base() != __rhs.base(); }
839 template<
typename _Iterator,
typename _Container>
841 operator!=(
const __normal_iterator<_Iterator, _Container>& __lhs,
842 const __normal_iterator<_Iterator, _Container>& __rhs)
844 {
return __lhs.base() != __rhs.base(); }
847 template<
typename _IteratorL,
typename _IteratorR,
typename _Container>
849 operator<(const __normal_iterator<_IteratorL, _Container>& __lhs,
850 const __normal_iterator<_IteratorR, _Container>& __rhs)
852 {
return __lhs.base() < __rhs.base(); }
854 template<
typename _Iterator,
typename _Container>
856 operator<(const __normal_iterator<_Iterator, _Container>& __lhs,
857 const __normal_iterator<_Iterator, _Container>& __rhs)
859 {
return __lhs.base() < __rhs.base(); }
861 template<
typename _IteratorL,
typename _IteratorR,
typename _Container>
863 operator>(
const __normal_iterator<_IteratorL, _Container>& __lhs,
864 const __normal_iterator<_IteratorR, _Container>& __rhs)
866 {
return __lhs.base() > __rhs.base(); }
868 template<
typename _Iterator,
typename _Container>
870 operator>(
const __normal_iterator<_Iterator, _Container>& __lhs,
871 const __normal_iterator<_Iterator, _Container>& __rhs)
873 {
return __lhs.base() > __rhs.base(); }
875 template<
typename _IteratorL,
typename _IteratorR,
typename _Container>
877 operator<=(const __normal_iterator<_IteratorL, _Container>& __lhs,
878 const __normal_iterator<_IteratorR, _Container>& __rhs)
880 {
return __lhs.base() <= __rhs.base(); }
882 template<
typename _Iterator,
typename _Container>
884 operator<=(const __normal_iterator<_Iterator, _Container>& __lhs,
885 const __normal_iterator<_Iterator, _Container>& __rhs)
887 {
return __lhs.base() <= __rhs.base(); }
889 template<
typename _IteratorL,
typename _IteratorR,
typename _Container>
891 operator>=(
const __normal_iterator<_IteratorL, _Container>& __lhs,
892 const __normal_iterator<_IteratorR, _Container>& __rhs)
894 {
return __lhs.base() >= __rhs.base(); }
896 template<
typename _Iterator,
typename _Container>
898 operator>=(
const __normal_iterator<_Iterator, _Container>& __lhs,
899 const __normal_iterator<_Iterator, _Container>& __rhs)
901 {
return __lhs.base() >= __rhs.base(); }
907 template<
typename _IteratorL,
typename _IteratorR,
typename _Container>
908 #if __cplusplus >= 201103L
911 operator-(
const __normal_iterator<_IteratorL, _Container>& __lhs,
912 const __normal_iterator<_IteratorR, _Container>& __rhs) noexcept
913 -> decltype(__lhs.base() - __rhs.base())
915 inline typename __normal_iterator<_IteratorL, _Container>::difference_type
916 operator-(
const __normal_iterator<_IteratorL, _Container>& __lhs,
917 const __normal_iterator<_IteratorR, _Container>& __rhs)
919 {
return __lhs.base() - __rhs.base(); }
921 template<
typename _Iterator,
typename _Container>
922 inline typename __normal_iterator<_Iterator, _Container>::difference_type
923 operator-(
const __normal_iterator<_Iterator, _Container>& __lhs,
924 const __normal_iterator<_Iterator, _Container>& __rhs)
926 {
return __lhs.base() - __rhs.base(); }
928 template<
typename _Iterator,
typename _Container>
929 inline __normal_iterator<_Iterator, _Container>
930 operator+(
typename __normal_iterator<_Iterator, _Container>::difference_type
931 __n,
const __normal_iterator<_Iterator, _Container>& __i)
933 {
return __normal_iterator<_Iterator, _Container>(__i.base() + __n); }
935 _GLIBCXX_END_NAMESPACE_VERSION
938 #if __cplusplus >= 201103L
940 namespace std _GLIBCXX_VISIBILITY(default)
942 _GLIBCXX_BEGIN_NAMESPACE_VERSION
958 template<
typename _Iterator>
962 _Iterator _M_current;
964 typedef iterator_traits<_Iterator> __traits_type;
965 typedef typename __traits_type::reference __base_ref;
968 typedef _Iterator iterator_type;
969 typedef typename __traits_type::iterator_category iterator_category;
970 typedef typename __traits_type::value_type value_type;
971 typedef typename __traits_type::difference_type difference_type;
973 typedef _Iterator pointer;
976 typedef typename conditional<is_reference<__base_ref>::value,
977 typename remove_reference<__base_ref>::type&&,
978 __base_ref>::type reference;
984 move_iterator(iterator_type __i)
985 : _M_current(__i) { }
987 template<
typename _Iter>
988 move_iterator(
const move_iterator<_Iter>& __i)
989 : _M_current(__i.base()) { }
993 {
return _M_current; }
997 {
return static_cast<reference
>(*_M_current); }
1001 {
return _M_current; }
1013 move_iterator __tmp = *
this;
1028 move_iterator __tmp = *
this;
1034 operator+(difference_type __n)
const
1035 {
return move_iterator(_M_current + __n); }
1038 operator+=(difference_type __n)
1045 operator-(difference_type __n)
const
1046 {
return move_iterator(_M_current - __n); }
1049 operator-=(difference_type __n)
1056 operator[](difference_type __n)
const
1063 template<
typename _IteratorL,
typename _IteratorR>
1065 operator==(
const move_iterator<_IteratorL>& __x,
1066 const move_iterator<_IteratorR>& __y)
1067 {
return __x.base() == __y.base(); }
1069 template<
typename _Iterator>
1071 operator==(
const move_iterator<_Iterator>& __x,
1072 const move_iterator<_Iterator>& __y)
1073 {
return __x.base() == __y.base(); }
1075 template<
typename _IteratorL,
typename _IteratorR>
1077 operator!=(
const move_iterator<_IteratorL>& __x,
1078 const move_iterator<_IteratorR>& __y)
1079 {
return !(__x == __y); }
1081 template<
typename _Iterator>
1083 operator!=(
const move_iterator<_Iterator>& __x,
1084 const move_iterator<_Iterator>& __y)
1085 {
return !(__x == __y); }
1087 template<
typename _IteratorL,
typename _IteratorR>
1089 operator<(const move_iterator<_IteratorL>& __x,
1090 const move_iterator<_IteratorR>& __y)
1091 {
return __x.base() < __y.base(); }
1093 template<
typename _Iterator>
1095 operator<(const move_iterator<_Iterator>& __x,
1096 const move_iterator<_Iterator>& __y)
1097 {
return __x.base() < __y.base(); }
1099 template<
typename _IteratorL,
typename _IteratorR>
1101 operator<=(const move_iterator<_IteratorL>& __x,
1102 const move_iterator<_IteratorR>& __y)
1103 {
return !(__y < __x); }
1105 template<
typename _Iterator>
1107 operator<=(const move_iterator<_Iterator>& __x,
1108 const move_iterator<_Iterator>& __y)
1109 {
return !(__y < __x); }
1111 template<
typename _IteratorL,
typename _IteratorR>
1113 operator>(
const move_iterator<_IteratorL>& __x,
1114 const move_iterator<_IteratorR>& __y)
1115 {
return __y < __x; }
1117 template<
typename _Iterator>
1119 operator>(
const move_iterator<_Iterator>& __x,
1120 const move_iterator<_Iterator>& __y)
1121 {
return __y < __x; }
1123 template<
typename _IteratorL,
typename _IteratorR>
1125 operator>=(
const move_iterator<_IteratorL>& __x,
1126 const move_iterator<_IteratorR>& __y)
1127 {
return !(__x < __y); }
1129 template<
typename _Iterator>
1131 operator>=(
const move_iterator<_Iterator>& __x,
1132 const move_iterator<_Iterator>& __y)
1133 {
return !(__x < __y); }
1136 template<
typename _IteratorL,
typename _IteratorR>
1138 operator-(
const move_iterator<_IteratorL>& __x,
1139 const move_iterator<_IteratorR>& __y)
1140 -> decltype(__x.base() - __y.base())
1141 {
return __x.base() - __y.base(); }
1143 template<
typename _Iterator>
1145 operator-(
const move_iterator<_Iterator>& __x,
1146 const move_iterator<_Iterator>& __y)
1147 -> decltype(__x.base() - __y.base())
1148 {
return __x.base() - __y.base(); }
1150 template<
typename _Iterator>
1151 inline move_iterator<_Iterator>
1152 operator+(
typename move_iterator<_Iterator>::difference_type __n,
1153 const move_iterator<_Iterator>& __x)
1154 {
return __x + __n; }
1156 template<
typename _Iterator>
1157 inline move_iterator<_Iterator>
1158 make_move_iterator(_Iterator __i)
1159 {
return move_iterator<_Iterator>(__i); }
1161 template<
typename _Iterator,
typename _ReturnType
1162 =
typename conditional<__move_if_noexcept_cond
1163 <
typename iterator_traits<_Iterator>::value_type>::value,
1164 _Iterator, move_iterator<_Iterator>>::type>
1166 __make_move_if_noexcept_iterator(_Iterator __i)
1167 {
return _ReturnType(__i); }
1171 _GLIBCXX_END_NAMESPACE_VERSION
1174 #define _GLIBCXX_MAKE_MOVE_ITERATOR(_Iter) std::make_move_iterator(_Iter)
1175 #define _GLIBCXX_MAKE_MOVE_IF_NOEXCEPT_ITERATOR(_Iter) \
1176 std::__make_move_if_noexcept_iterator(_Iter)
1178 #define _GLIBCXX_MAKE_MOVE_ITERATOR(_Iter) (_Iter)
1179 #define _GLIBCXX_MAKE_MOVE_IF_NOEXCEPT_ITERATOR(_Iter) (_Iter)
reverse_iterator & operator++()
reverse_iterator operator-(difference_type __n) const
insert_iterator & operator=(const typename _Container::value_type &__value)
Turns assignment into insertion.
_Container container_type
A nested typedef for the type of whatever container you used.
reverse_iterator operator++(int)
reverse_iterator & operator+=(difference_type __n)
front_insert_iterator operator++(int)
Simply returns *this. (This iterator does not move.)
_Container container_type
A nested typedef for the type of whatever container you used.
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(iterator_type __x)
insert_iterator & operator*()
Simply returns *this.
back_insert_iterator operator++(int)
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.
iterator_type base() const
insert_iterator< _Container > inserter(_Container &__x, _Iterator __i)
reverse_iterator & operator--()
pointer operator->() const
reverse_iterator(const reverse_iterator< _Iter > &__x)
reverse_iterator & operator-=(difference_type __n)
bool operator>(const basic_string< _CharT, _Traits, _Alloc > &__lhs, const basic_string< _CharT, _Traits, _Alloc > &__rhs)
Test if string follows string.
reference operator[](difference_type __n) const
Turns assignment into insertion.
insert_iterator & operator++(int)
Simply returns *this. (This iterator does not move.)
reverse_iterator operator+(difference_type __n) const
GNU extensions for public use.
front_insert_iterator< _Container > front_inserter(_Container &__x)
front_insert_iterator & operator=(const typename _Container::value_type &__value)
reference operator*() const
basic_string< _CharT, _Traits, _Alloc > operator+(const basic_string< _CharT, _Traits, _Alloc > &__lhs, const basic_string< _CharT, _Traits, _Alloc > &__rhs)
Concatenate two strings.
insert_iterator & operator++()
Simply returns *this. (This iterator does not move.)
reverse_iterator(const reverse_iterator &__x)
_Container container_type
A nested typedef for the type of whatever container you used.
reverse_iterator operator--(int)
back_insert_iterator & operator++()
Simply returns *this. (This iterator does not move.)
back_insert_iterator & operator=(const typename _Container::value_type &__value)
back_insert_iterator(_Container &__x)
The only way to create this iterator is with a container.
front_insert_iterator & operator++()
Simply returns *this. (This iterator does not move.)
insert_iterator(_Container &__x, typename _Container::iterator __i)
back_insert_iterator< _Container > back_inserter(_Container &__x)
front_insert_iterator & operator*()
Simply returns *this.
back_insert_iterator & operator*()
Simply returns *this.
ISO C++ entities toplevel namespace is std.
constexpr std::remove_reference< _Tp >::type && move(_Tp &&__t) noexcept
Convert a value to an rvalue.