60 #ifndef _STL_ITERATOR_H 61 #define _STL_ITERATOR_H 1 68 #if __cplusplus >= 201103L 72 #if __cplusplus > 201703L 73 # define __cpp_lib_array_constexpr 201811L 74 # define __cpp_lib_constexpr_iterator 201811L 75 #elif __cplusplus == 201703L 76 # define __cpp_lib_array_constexpr 201803L 79 #if __cplusplus > 201703L 85 namespace std _GLIBCXX_VISIBILITY(default)
87 _GLIBCXX_BEGIN_NAMESPACE_VERSION
94 #if __cplusplus > 201703L && __cpp_lib_concepts 99 template<
typename _Cat,
typename _Limit,
typename _Otherwise = _Cat>
100 using __clamp_iter_cat
101 = conditional_t<derived_from<_Cat, _Limit>, _Limit, _Otherwise>;
124 template<
typename _Iterator>
126 :
public iterator<typename iterator_traits<_Iterator>::iterator_category,
127 typename iterator_traits<_Iterator>::value_type,
128 typename iterator_traits<_Iterator>::difference_type,
129 typename iterator_traits<_Iterator>::pointer,
130 typename iterator_traits<_Iterator>::reference>
138 typedef _Iterator iterator_type;
139 typedef typename __traits_type::difference_type difference_type;
140 typedef typename __traits_type::pointer pointer;
141 typedef typename __traits_type::reference reference;
143 #if __cplusplus > 201703L && __cpp_lib_concepts 144 using iterator_concept
149 = __detail::__clamp_iter_cat<
typename __traits_type::iterator_category,
150 random_access_iterator_tag>;
166 explicit _GLIBCXX17_CONSTEXPR
174 : current(__x.current) { }
176 #if __cplusplus >= 201103L 184 template<
typename _Iter>
187 : current(__x.base()) { }
192 _GLIBCXX17_CONSTEXPR iterator_type
206 _GLIBCXX17_CONSTEXPR reference
209 _Iterator __tmp = current;
218 _GLIBCXX17_CONSTEXPR pointer
220 #if __cplusplus > 201703L && __cpp_concepts >= 201907L 221 requires is_pointer_v<_Iterator>
222 || requires(
const _Iterator __i) { __i.operator->(); }
227 _Iterator __tmp = current;
229 return _S_to_pointer(__tmp);
331 _GLIBCXX17_CONSTEXPR reference
333 {
return *(*
this + __n); }
335 #if __cplusplus > 201703L && __cpp_lib_concepts 336 friend constexpr iter_rvalue_reference_t<_Iterator>
338 noexcept(is_nothrow_copy_constructible_v<_Iterator>
339 && noexcept(ranges::iter_move(--std::declval<_Iterator&>())))
341 auto __tmp = __i.
base();
342 return ranges::iter_move(--__tmp);
345 template<indirectly_swappable<_Iterator> _Iter2>
346 friend constexpr
void 349 noexcept(is_nothrow_copy_constructible_v<_Iterator>
350 && is_nothrow_copy_constructible_v<_Iter2>
351 && noexcept(ranges::iter_swap(--std::declval<_Iterator&>(),
352 --std::declval<_Iter2&>())))
354 auto __xtmp = __x.
base();
355 auto __ytmp = __y.
base();
356 ranges::iter_swap(--__xtmp, --__ytmp);
361 template<
typename _Tp>
362 static _GLIBCXX17_CONSTEXPR _Tp*
363 _S_to_pointer(_Tp* __p)
366 template<
typename _Tp>
367 static _GLIBCXX17_CONSTEXPR pointer
368 _S_to_pointer(_Tp __t)
369 {
return __t.operator->(); }
382 #if __cplusplus <= 201703L || ! defined __cpp_lib_concepts 383 template<
typename _Iterator>
384 inline _GLIBCXX17_CONSTEXPR
bool 387 {
return __x.
base() == __y.
base(); }
389 template<
typename _Iterator>
390 inline _GLIBCXX17_CONSTEXPR
bool 391 operator<(const reverse_iterator<_Iterator>& __x,
393 {
return __y.
base() < __x.base(); }
395 template<
typename _Iterator>
396 inline _GLIBCXX17_CONSTEXPR
bool 399 {
return !(__x == __y); }
401 template<
typename _Iterator>
402 inline _GLIBCXX17_CONSTEXPR
bool 405 {
return __y < __x; }
407 template<
typename _Iterator>
408 inline _GLIBCXX17_CONSTEXPR
bool 409 operator<=(const reverse_iterator<_Iterator>& __x,
411 {
return !(__y < __x); }
413 template<
typename _Iterator>
414 inline _GLIBCXX17_CONSTEXPR
bool 417 {
return !(__x < __y); }
421 template<
typename _IteratorL,
typename _IteratorR>
422 inline _GLIBCXX17_CONSTEXPR
bool 425 {
return __x.
base() == __y.
base(); }
427 template<
typename _IteratorL,
typename _IteratorR>
428 inline _GLIBCXX17_CONSTEXPR
bool 429 operator<(const reverse_iterator<_IteratorL>& __x,
431 {
return __y.
base() < __x.base(); }
433 template<
typename _IteratorL,
typename _IteratorR>
434 inline _GLIBCXX17_CONSTEXPR
bool 437 {
return !(__x == __y); }
439 template<
typename _IteratorL,
typename _IteratorR>
440 inline _GLIBCXX17_CONSTEXPR
bool 443 {
return __y < __x; }
445 template<
typename _IteratorL,
typename _IteratorR>
446 inline _GLIBCXX17_CONSTEXPR
bool 447 operator<=(const reverse_iterator<_IteratorL>& __x,
449 {
return !(__y < __x); }
451 template<
typename _IteratorL,
typename _IteratorR>
452 inline _GLIBCXX17_CONSTEXPR
bool 455 {
return !(__x < __y); }
457 template<
typename _IteratorL,
typename _IteratorR>
461 requires requires { { __x.
base() == __y.
base() } -> convertible_to<bool>; }
462 {
return __x.
base() == __y.
base(); }
464 template<
typename _IteratorL,
typename _IteratorR>
468 requires requires { { __x.
base() != __y.
base() } -> convertible_to<bool>; }
469 {
return __x.
base() != __y.
base(); }
471 template<
typename _IteratorL,
typename _IteratorR>
473 operator<(const reverse_iterator<_IteratorL>& __x,
475 requires requires { { __x.
base() > __y.
base() } -> convertible_to<bool>; }
476 {
return __x.base() > __y.
base(); }
478 template<
typename _IteratorL,
typename _IteratorR>
482 requires requires { { __x.
base() < __y.
base() } -> convertible_to<bool>; }
485 template<
typename _IteratorL,
typename _IteratorR>
487 operator<=(const reverse_iterator<_IteratorL>& __x,
489 requires requires { { __x.
base() >= __y.
base() } -> convertible_to<bool>; }
490 {
return __x.base() >= __y.
base(); }
492 template<
typename _IteratorL,
typename _IteratorR>
496 requires requires { { __x.
base() <= __y.
base() } -> convertible_to<bool>; }
497 {
return __x.
base() <= __y.
base(); }
499 template<
typename _IteratorL,
500 three_way_comparable_with<_IteratorL> _IteratorR>
501 constexpr compare_three_way_result_t<_IteratorL, _IteratorR>
504 {
return __y.
base() <=> __x.
base(); }
508 #if __cplusplus < 201103L 509 template<
typename _Iterator>
510 inline typename reverse_iterator<_Iterator>::difference_type
515 template<
typename _IteratorL,
typename _IteratorR>
516 inline typename reverse_iterator<_IteratorL>::difference_type
523 template<
typename _IteratorL,
typename _IteratorR>
524 inline _GLIBCXX17_CONSTEXPR
auto 527 -> decltype(__y.
base() - __x.
base())
531 template<
typename _Iterator>
533 operator+(
typename reverse_iterator<_Iterator>::difference_type __n,
537 #if __cplusplus >= 201103L 539 template<
typename _Iterator>
541 __make_reverse_iterator(_Iterator __i)
544 # if __cplusplus >= 201402L 545 # define __cpp_lib_make_reverse_iterator 201402 550 template<
typename _Iterator>
555 # if __cplusplus > 201703L && defined __cpp_lib_concepts 556 template<
typename _Iterator1,
typename _Iterator2>
557 requires (!sized_sentinel_for<_Iterator1, _Iterator2>)
558 inline constexpr
bool 559 disable_sized_sentinel_for<reverse_iterator<_Iterator1>,
564 template<
typename _Iterator>
568 -> decltype(__make_reverse_iterator(__niter_base(__it.
base())))
569 {
return __make_reverse_iterator(__niter_base(__it.
base())); }
571 template<
typename _Iterator>
572 struct __is_move_iterator<reverse_iterator<_Iterator> >
573 : __is_move_iterator<_Iterator>
576 template<
typename _Iterator>
580 -> decltype(__make_reverse_iterator(__miter_base(__it.
base())))
581 {
return __make_reverse_iterator(__miter_base(__it.
base())); }
595 template<
typename _Container>
597 :
public iterator<output_iterator_tag, void, void, void, void>
600 _Container* container;
605 #if __cplusplus > 201703L 606 using difference_type = ptrdiff_t;
612 explicit _GLIBCXX20_CONSTEXPR
627 #if __cplusplus < 201103L 629 operator=(
typename _Container::const_reference __value)
631 container->push_back(__value);
637 operator=(
const typename _Container::value_type& __value)
639 container->push_back(__value);
645 operator=(
typename _Container::value_type&& __value)
647 container->push_back(
std::move(__value));
682 template<
typename _Container>
698 template<
typename _Container>
700 :
public iterator<output_iterator_tag, void, void, void, void>
703 _Container* container;
708 #if __cplusplus > 201703L 709 using difference_type = ptrdiff_t;
715 explicit _GLIBCXX20_CONSTEXPR
730 #if __cplusplus < 201103L 732 operator=(
typename _Container::const_reference __value)
734 container->push_front(__value);
740 operator=(
const typename _Container::value_type& __value)
742 container->push_front(__value);
748 operator=(
typename _Container::value_type&& __value)
750 container->push_front(
std::move(__value));
785 template<
typename _Container>
805 template<
typename _Container>
807 :
public iterator<output_iterator_tag, void, void, void, void>
809 #if __cplusplus > 201703L && defined __cpp_lib_concepts 810 using _Iter = std::__detail::__range_iter_t<_Container>;
813 _Container* container =
nullptr;
814 _Iter iter = _Iter();
816 typedef typename _Container::iterator _Iter;
819 _Container* container;
827 #if __cplusplus > 201703L && defined __cpp_lib_concepts 828 using difference_type = ptrdiff_t;
864 #if __cplusplus < 201103L 866 operator=(
typename _Container::const_reference __value)
868 iter = container->insert(iter, __value);
875 operator=(
const typename _Container::value_type& __value)
877 iter = container->insert(iter, __value);
884 operator=(
typename _Container::value_type&& __value)
886 iter = container->insert(iter,
std::move(__value));
923 #if __cplusplus > 201703L && defined __cpp_lib_concepts 924 template<
typename _Container>
926 inserter(_Container& __x, std::__detail::__range_iter_t<_Container> __i)
929 template<
typename _Container,
typename _Iterator>
934 typename _Container::iterator(__i));
940 _GLIBCXX_END_NAMESPACE_VERSION
943 namespace __gnu_cxx _GLIBCXX_VISIBILITY(default)
945 _GLIBCXX_BEGIN_NAMESPACE_VERSION
954 template<
typename _Iterator,
typename _Container>
955 class __normal_iterator
958 _Iterator _M_current;
963 typedef _Iterator iterator_type;
964 typedef typename __traits_type::iterator_category iterator_category;
965 typedef typename __traits_type::value_type value_type;
966 typedef typename __traits_type::difference_type difference_type;
967 typedef typename __traits_type::reference reference;
968 typedef typename __traits_type::pointer pointer;
970 #if __cplusplus > 201703L && __cpp_lib_concepts 971 using iterator_concept = std::__detail::__iter_concept<_Iterator>;
974 _GLIBCXX_CONSTEXPR __normal_iterator() _GLIBCXX_NOEXCEPT
975 : _M_current(_Iterator()) { }
977 explicit _GLIBCXX20_CONSTEXPR
978 __normal_iterator(
const _Iterator& __i) _GLIBCXX_NOEXCEPT
979 : _M_current(__i) { }
982 template<
typename _Iter>
984 __normal_iterator(
const __normal_iterator<_Iter,
985 typename __enable_if<
986 (std::__are_same<_Iter, typename _Container::pointer>::__value),
987 _Container>::__type>& __i) _GLIBCXX_NOEXCEPT
988 : _M_current(__i.base()) { }
994 {
return *_M_current; }
998 operator->()
const _GLIBCXX_NOEXCEPT
999 {
return _M_current; }
1001 _GLIBCXX20_CONSTEXPR
1003 operator++() _GLIBCXX_NOEXCEPT
1009 _GLIBCXX20_CONSTEXPR
1011 operator++(
int) _GLIBCXX_NOEXCEPT
1012 {
return __normal_iterator(_M_current++); }
1015 _GLIBCXX20_CONSTEXPR
1017 operator--() _GLIBCXX_NOEXCEPT
1023 _GLIBCXX20_CONSTEXPR
1025 operator--(
int) _GLIBCXX_NOEXCEPT
1026 {
return __normal_iterator(_M_current--); }
1029 _GLIBCXX20_CONSTEXPR
1031 operator[](difference_type __n)
const _GLIBCXX_NOEXCEPT
1032 {
return _M_current[__n]; }
1034 _GLIBCXX20_CONSTEXPR
1036 operator+=(difference_type __n) _GLIBCXX_NOEXCEPT
1037 { _M_current += __n;
return *
this; }
1039 _GLIBCXX20_CONSTEXPR
1041 operator+(difference_type __n)
const _GLIBCXX_NOEXCEPT
1042 {
return __normal_iterator(_M_current + __n); }
1044 _GLIBCXX20_CONSTEXPR
1046 operator-=(difference_type __n) _GLIBCXX_NOEXCEPT
1047 { _M_current -= __n;
return *
this; }
1049 _GLIBCXX20_CONSTEXPR
1051 operator-(difference_type __n)
const _GLIBCXX_NOEXCEPT
1052 {
return __normal_iterator(_M_current - __n); }
1054 _GLIBCXX20_CONSTEXPR
1056 base()
const _GLIBCXX_NOEXCEPT
1057 {
return _M_current; }
1068 #if __cpp_lib_three_way_comparison 1069 template<
typename _IteratorL,
typename _IteratorR,
typename _Container>
1070 requires requires (_IteratorL __lhs, _IteratorR __rhs)
1071 { { __lhs == __rhs } -> std::convertible_to<bool>; }
1073 operator==(
const __normal_iterator<_IteratorL, _Container>& __lhs,
1074 const __normal_iterator<_IteratorR, _Container>& __rhs)
1075 noexcept(noexcept(__lhs.base() == __rhs.base()))
1076 {
return __lhs.base() == __rhs.base(); }
1078 template<
typename _IteratorL,
typename _IteratorR,
typename _Container>
1079 constexpr std::__detail::__synth3way_t<_IteratorR, _IteratorL>
1080 operator<=>(
const __normal_iterator<_IteratorL, _Container>& __lhs,
1081 const __normal_iterator<_IteratorR, _Container>& __rhs)
1082 noexcept(noexcept(std::__detail::__synth3way(__lhs.base(), __rhs.base())))
1083 {
return std::__detail::__synth3way(__lhs.base(), __rhs.base()); }
1086 template<
typename _IteratorL,
typename _IteratorR,
typename _Container>
1087 _GLIBCXX20_CONSTEXPR
1089 operator==(
const __normal_iterator<_IteratorL, _Container>& __lhs,
1090 const __normal_iterator<_IteratorR, _Container>& __rhs)
1092 {
return __lhs.base() == __rhs.base(); }
1094 template<
typename _Iterator,
typename _Container>
1095 _GLIBCXX20_CONSTEXPR
1097 operator==(
const __normal_iterator<_Iterator, _Container>& __lhs,
1098 const __normal_iterator<_Iterator, _Container>& __rhs)
1100 {
return __lhs.base() == __rhs.base(); }
1102 template<
typename _IteratorL,
typename _IteratorR,
typename _Container>
1103 _GLIBCXX20_CONSTEXPR
1105 operator!=(
const __normal_iterator<_IteratorL, _Container>& __lhs,
1106 const __normal_iterator<_IteratorR, _Container>& __rhs)
1108 {
return __lhs.base() != __rhs.base(); }
1110 template<
typename _Iterator,
typename _Container>
1111 _GLIBCXX20_CONSTEXPR
1113 operator!=(
const __normal_iterator<_Iterator, _Container>& __lhs,
1114 const __normal_iterator<_Iterator, _Container>& __rhs)
1116 {
return __lhs.base() != __rhs.base(); }
1119 template<
typename _IteratorL,
typename _IteratorR,
typename _Container>
1121 operator<(const __normal_iterator<_IteratorL, _Container>& __lhs,
1122 const __normal_iterator<_IteratorR, _Container>& __rhs)
1124 {
return __lhs.base() < __rhs.base(); }
1126 template<
typename _Iterator,
typename _Container>
1127 _GLIBCXX20_CONSTEXPR
1129 operator<(const __normal_iterator<_Iterator, _Container>& __lhs,
1130 const __normal_iterator<_Iterator, _Container>& __rhs)
1132 {
return __lhs.base() < __rhs.base(); }
1134 template<
typename _IteratorL,
typename _IteratorR,
typename _Container>
1136 operator>(
const __normal_iterator<_IteratorL, _Container>& __lhs,
1137 const __normal_iterator<_IteratorR, _Container>& __rhs)
1139 {
return __lhs.base() > __rhs.base(); }
1141 template<
typename _Iterator,
typename _Container>
1142 _GLIBCXX20_CONSTEXPR
1144 operator>(
const __normal_iterator<_Iterator, _Container>& __lhs,
1145 const __normal_iterator<_Iterator, _Container>& __rhs)
1147 {
return __lhs.base() > __rhs.base(); }
1149 template<
typename _IteratorL,
typename _IteratorR,
typename _Container>
1151 operator<=(const __normal_iterator<_IteratorL, _Container>& __lhs,
1152 const __normal_iterator<_IteratorR, _Container>& __rhs)
1154 {
return __lhs.base() <= __rhs.base(); }
1156 template<
typename _Iterator,
typename _Container>
1157 _GLIBCXX20_CONSTEXPR
1159 operator<=(const __normal_iterator<_Iterator, _Container>& __lhs,
1160 const __normal_iterator<_Iterator, _Container>& __rhs)
1162 {
return __lhs.base() <= __rhs.base(); }
1164 template<
typename _IteratorL,
typename _IteratorR,
typename _Container>
1166 operator>=(
const __normal_iterator<_IteratorL, _Container>& __lhs,
1167 const __normal_iterator<_IteratorR, _Container>& __rhs)
1169 {
return __lhs.base() >= __rhs.base(); }
1171 template<
typename _Iterator,
typename _Container>
1172 _GLIBCXX20_CONSTEXPR
1174 operator>=(
const __normal_iterator<_Iterator, _Container>& __lhs,
1175 const __normal_iterator<_Iterator, _Container>& __rhs)
1177 {
return __lhs.base() >= __rhs.base(); }
1178 #endif // three-way comparison 1184 template<
typename _IteratorL,
typename _IteratorR,
typename _Container>
1185 #if __cplusplus >= 201103L 1187 _GLIBCXX20_CONSTEXPR
1189 operator-(
const __normal_iterator<_IteratorL, _Container>& __lhs,
1190 const __normal_iterator<_IteratorR, _Container>& __rhs) noexcept
1191 -> decltype(__lhs.base() - __rhs.base())
1193 inline typename __normal_iterator<_IteratorL, _Container>::difference_type
1194 operator-(
const __normal_iterator<_IteratorL, _Container>& __lhs,
1195 const __normal_iterator<_IteratorR, _Container>& __rhs)
1197 {
return __lhs.base() - __rhs.base(); }
1199 template<
typename _Iterator,
typename _Container>
1200 _GLIBCXX20_CONSTEXPR
1201 inline typename __normal_iterator<_Iterator, _Container>::difference_type
1202 operator-(
const __normal_iterator<_Iterator, _Container>& __lhs,
1203 const __normal_iterator<_Iterator, _Container>& __rhs)
1205 {
return __lhs.base() - __rhs.base(); }
1207 template<
typename _Iterator,
typename _Container>
1208 _GLIBCXX20_CONSTEXPR
1209 inline __normal_iterator<_Iterator, _Container>
1210 operator+(
typename __normal_iterator<_Iterator, _Container>::difference_type
1211 __n,
const __normal_iterator<_Iterator, _Container>& __i)
1213 {
return __normal_iterator<_Iterator, _Container>(__i.base() + __n); }
1215 _GLIBCXX_END_NAMESPACE_VERSION
1218 namespace std _GLIBCXX_VISIBILITY(default)
1220 _GLIBCXX_BEGIN_NAMESPACE_VERSION
1222 template<
typename _Iterator,
typename _Container>
1223 _GLIBCXX20_CONSTEXPR
1225 __niter_base(__gnu_cxx::__normal_iterator<_Iterator, _Container> __it)
1227 {
return __it.base(); }
1229 #if __cplusplus >= 201103L 1235 #if __cplusplus > 201703L && __cpp_lib_concepts 1236 template<semiregular _Sent>
1242 noexcept(is_nothrow_default_constructible_v<_Sent>)
1246 move_sentinel(_Sent __s)
1247 noexcept(is_nothrow_move_constructible_v<_Sent>)
1250 template<
typename _S2> requires convertible_to<const _S2&, _Sent>
1252 move_sentinel(
const move_sentinel<_S2>& __s)
1253 noexcept(is_nothrow_constructible_v<_Sent, const _S2&>)
1254 : _M_last(__s.base())
1257 template<
typename _S2> requires assignable_from<_Sent&, const _S2&>
1258 constexpr move_sentinel&
1259 operator=(
const move_sentinel<_S2>& __s)
1260 noexcept(is_nothrow_assignable_v<_Sent, const _S2&>)
1262 _M_last = __s.base();
1268 noexcept(is_nothrow_copy_constructible_v<_Sent>)
1285 template<
typename _Iterator>
1288 _Iterator _M_current;
1291 #if __cplusplus > 201703L && __cpp_lib_concepts 1292 using __base_cat =
typename __traits_type::iterator_category;
1294 using __base_ref =
typename __traits_type::reference;
1298 using iterator_type = _Iterator;
1300 #if __cplusplus > 201703L && __cpp_lib_concepts 1302 using iterator_category
1303 = __detail::__clamp_iter_cat<__base_cat, random_access_iterator_tag>;
1304 using value_type = iter_value_t<_Iterator>;
1305 using difference_type = iter_difference_t<_Iterator>;
1306 using pointer = _Iterator;
1307 using reference = iter_rvalue_reference_t<_Iterator>;
1309 typedef typename __traits_type::iterator_category iterator_category;
1310 typedef typename __traits_type::value_type value_type;
1311 typedef typename __traits_type::difference_type difference_type;
1313 typedef _Iterator pointer;
1317 typename remove_reference<__base_ref>::type&&,
1318 __base_ref>::type reference;
1321 _GLIBCXX17_CONSTEXPR
1325 explicit _GLIBCXX17_CONSTEXPR
1326 move_iterator(iterator_type __i)
1329 template<
typename _Iter>
1330 _GLIBCXX17_CONSTEXPR
1332 : _M_current(__i.base()) { }
1334 #if __cplusplus <= 201703L 1335 _GLIBCXX17_CONSTEXPR iterator_type
1337 {
return _M_current; }
1339 constexpr iterator_type
1341 #if __cpp_lib_concepts 1342 requires copy_constructible<iterator_type>
1344 {
return _M_current; }
1346 constexpr iterator_type
1351 _GLIBCXX17_CONSTEXPR reference
1353 #if __cplusplus > 201703L && __cpp_lib_concepts 1354 {
return ranges::iter_move(_M_current); }
1356 {
return static_cast<reference
>(*_M_current); }
1359 _GLIBCXX17_CONSTEXPR pointer
1361 {
return _M_current; }
1363 _GLIBCXX17_CONSTEXPR move_iterator&
1370 _GLIBCXX17_CONSTEXPR move_iterator
1373 move_iterator __tmp = *
this;
1378 #if __cpp_lib_concepts 1380 operator++(
int) requires (!forward_iterator<_Iterator>)
1384 _GLIBCXX17_CONSTEXPR move_iterator&
1391 _GLIBCXX17_CONSTEXPR move_iterator
1394 move_iterator __tmp = *
this;
1399 _GLIBCXX17_CONSTEXPR move_iterator
1401 {
return move_iterator(_M_current + __n); }
1403 _GLIBCXX17_CONSTEXPR move_iterator&
1404 operator+=(difference_type __n)
1410 _GLIBCXX17_CONSTEXPR move_iterator
1412 {
return move_iterator(_M_current - __n); }
1414 _GLIBCXX17_CONSTEXPR move_iterator&
1415 operator-=(difference_type __n)
1421 _GLIBCXX17_CONSTEXPR reference
1422 operator[](difference_type __n)
const 1423 #if __cplusplus > 201703L && __cpp_lib_concepts 1424 {
return ranges::iter_move(_M_current + __n); }
1429 #if __cplusplus > 201703L && __cpp_lib_concepts 1430 template<sentinel_for<_Iterator> _Sent>
1431 friend constexpr
bool 1432 operator==(
const move_iterator& __x,
const move_sentinel<_Sent>& __y)
1433 {
return __x.base() == __y.base(); }
1435 template<sized_sentinel_for<_Iterator> _Sent>
1436 friend constexpr iter_difference_t<_Iterator>
1437 operator-(
const move_sentinel<_Sent>& __x,
const move_iterator& __y)
1438 {
return __x.base() - __y.base(); }
1440 template<sized_sentinel_for<_Iterator> _Sent>
1441 friend constexpr iter_difference_t<_Iterator>
1442 operator-(
const move_iterator& __x,
const move_sentinel<_Sent>& __y)
1443 {
return __x.base() - __y.base(); }
1445 friend constexpr iter_rvalue_reference_t<_Iterator>
1446 iter_move(
const move_iterator& __i)
1447 noexcept(noexcept(ranges::iter_move(__i._M_current)))
1448 {
return ranges::iter_move(__i._M_current); }
1450 template<indirectly_swappable<_Iterator> _Iter2>
1451 friend constexpr
void 1453 noexcept(noexcept(ranges::iter_swap(__x._M_current, __y._M_current)))
1454 {
return ranges::iter_swap(__x._M_current, __y._M_current); }
1458 template<
typename _IteratorL,
typename _IteratorR>
1459 inline _GLIBCXX17_CONSTEXPR
bool 1462 #if __cplusplus > 201703L && __cpp_lib_concepts 1463 requires requires { { __x.base() == __y.base() } -> convertible_to<bool>; }
1465 {
return __x.base() == __y.base(); }
1467 #if __cpp_lib_three_way_comparison 1468 template<
typename _IteratorL,
1469 three_way_comparable_with<_IteratorL> _IteratorR>
1470 constexpr compare_three_way_result_t<_IteratorL, _IteratorR>
1473 {
return __x.base() <=> __y.base(); }
1475 template<
typename _IteratorL,
typename _IteratorR>
1476 inline _GLIBCXX17_CONSTEXPR
bool 1479 {
return !(__x == __y); }
1482 template<
typename _IteratorL,
typename _IteratorR>
1483 inline _GLIBCXX17_CONSTEXPR
bool 1484 operator<(const move_iterator<_IteratorL>& __x,
1486 #
if __cplusplus > 201703L && __cpp_lib_concepts
1487 requires requires { { __x.base() < __y.base() } -> convertible_to<bool>; }
1489 {
return __x.base() < __y.base(); }
1491 template<
typename _IteratorL,
typename _IteratorR>
1492 inline _GLIBCXX17_CONSTEXPR
bool 1493 operator<=(const move_iterator<_IteratorL>& __x,
1495 #
if __cplusplus > 201703L && __cpp_lib_concepts
1496 requires requires { { __y.base() < __x.base() } -> convertible_to<bool>; }
1498 {
return !(__y < __x); }
1500 template<
typename _IteratorL,
typename _IteratorR>
1501 inline _GLIBCXX17_CONSTEXPR
bool 1504 #if __cplusplus > 201703L && __cpp_lib_concepts 1505 requires requires { { __y.base() < __x.base() } -> convertible_to<bool>; }
1507 {
return __y < __x; }
1509 template<
typename _IteratorL,
typename _IteratorR>
1510 inline _GLIBCXX17_CONSTEXPR
bool 1513 #if __cplusplus > 201703L && __cpp_lib_concepts 1514 requires requires { { __x.base() < __y.base() } -> convertible_to<bool>; }
1516 {
return !(__x < __y); }
1518 #if ! (__cplusplus > 201703L && __cpp_lib_concepts) 1526 template<
typename _Iterator>
1527 inline _GLIBCXX17_CONSTEXPR
bool 1530 {
return __x.base() == __y.base(); }
1532 template<
typename _Iterator>
1533 inline _GLIBCXX17_CONSTEXPR
bool 1536 {
return !(__x == __y); }
1538 template<
typename _Iterator>
1539 inline _GLIBCXX17_CONSTEXPR
bool 1540 operator<(const move_iterator<_Iterator>& __x,
1542 {
return __x.base() < __y.base(); }
1544 template<
typename _Iterator>
1545 inline _GLIBCXX17_CONSTEXPR
bool 1546 operator<=(const move_iterator<_Iterator>& __x,
1548 {
return !(__y < __x); }
1550 template<
typename _Iterator>
1551 inline _GLIBCXX17_CONSTEXPR
bool 1554 {
return __y < __x; }
1556 template<
typename _Iterator>
1557 inline _GLIBCXX17_CONSTEXPR
bool 1560 {
return !(__x < __y); }
1564 template<
typename _IteratorL,
typename _IteratorR>
1565 inline _GLIBCXX17_CONSTEXPR
auto 1568 -> decltype(__x.base() - __y.base())
1569 {
return __x.base() - __y.base(); }
1571 template<
typename _Iterator>
1573 operator+(
typename move_iterator<_Iterator>::difference_type __n,
1575 {
return __x + __n; }
1577 template<
typename _Iterator>
1579 make_move_iterator(_Iterator __i)
1582 template<
typename _Iterator,
typename _ReturnType
1586 inline _GLIBCXX17_CONSTEXPR _ReturnType
1587 __make_move_if_noexcept_iterator(_Iterator __i)
1588 {
return _ReturnType(__i); }
1592 template<
typename _Tp,
typename _ReturnType
1595 inline _GLIBCXX17_CONSTEXPR _ReturnType
1596 __make_move_if_noexcept_iterator(_Tp* __i)
1597 {
return _ReturnType(__i); }
1599 #if __cplusplus > 201703L && __cpp_lib_concepts 1604 template<
typename _It>
1605 concept __common_iter_has_arrow = indirectly_readable<const _It>
1606 && (requires(
const _It& __it) { __it.operator->(); }
1607 || is_reference_v<iter_reference_t<_It>>
1608 || constructible_from<iter_value_t<_It>, iter_reference_t<_It>>);
1613 template<input_or_output_iterator _It, sentinel_for<_It> _Sent>
1614 requires (!same_as<_It, _Sent>) && copyable<_It>
1615 class common_iterator
1617 template<
typename _Tp,
typename _Up>
1618 static constexpr
bool 1621 if constexpr (is_trivially_default_constructible_v<_Tp>)
1622 return is_nothrow_assignable_v<_Tp, _Up>;
1624 return is_nothrow_constructible_v<_Tp, _Up>;
1627 template<
typename _It2,
typename _Sent2>
1628 static constexpr
bool 1630 {
return _S_noexcept1<_It, _It2>() && _S_noexcept1<_Sent, _Sent2>(); }
1634 iter_value_t<_It> _M_keep;
1636 _Proxy(iter_reference_t<_It>&& __x)
1639 friend class common_iterator;
1642 const iter_value_t<_It>*
1650 noexcept(is_nothrow_default_constructible_v<_It>)
1651 : _M_it(), _M_index(0)
1655 common_iterator(_It __i)
1656 noexcept(is_nothrow_move_constructible_v<_It>)
1661 common_iterator(_Sent __s)
1662 noexcept(is_nothrow_move_constructible_v<_Sent>)
1666 template<
typename _It2,
typename _Sent2>
1667 requires convertible_to<const _It2&, _It>
1668 && convertible_to<const _Sent2&, _Sent>
1670 common_iterator(
const common_iterator<_It2, _Sent2>& __x)
1671 noexcept(_S_noexcept<const _It2&, const _Sent2&>())
1672 : _M_valueless(), _M_index(__x._M_index)
1676 if constexpr (is_trivially_default_constructible_v<_It>)
1681 else if (_M_index == 1)
1683 if constexpr (is_trivially_default_constructible_v<_Sent>)
1691 common_iterator(
const common_iterator& __x)
1692 noexcept(_S_noexcept<const _It&, const _Sent&>())
1693 : _M_valueless(), _M_index(__x._M_index)
1697 if constexpr (is_trivially_default_constructible_v<_It>)
1702 else if (_M_index == 1)
1704 if constexpr (is_trivially_default_constructible_v<_Sent>)
1712 operator=(
const common_iterator& __x)
1713 noexcept(is_nothrow_copy_assignable_v<_It>
1714 && is_nothrow_copy_assignable_v<_Sent>
1715 && is_nothrow_copy_constructible_v<_It>
1716 && is_nothrow_copy_constructible_v<_Sent>)
1718 return this->
operator=<_It, _Sent>(__x);
1721 template<
typename _It2,
typename _Sent2>
1722 requires convertible_to<const _It2&, _It>
1723 && convertible_to<const _Sent2&, _Sent>
1724 && assignable_from<_It&, const _It2&>
1725 && assignable_from<_Sent&, const _Sent2&>
1727 operator=(
const common_iterator<_It2, _Sent2>& __x)
1728 noexcept(is_nothrow_constructible_v<_It, const _It2&>
1729 && is_nothrow_constructible_v<_Sent, const _Sent2&>
1730 && is_nothrow_assignable_v<_It, const _It2&>
1731 && is_nothrow_assignable_v<_Sent, const _Sent2&>)
1733 switch(_M_index << 2 | __x._M_index)
1739 _M_sent = __x._M_sent;
1758 __glibcxx_assert(__x._M_has_value());
1759 __builtin_unreachable();
1780 __glibcxx_assert(_M_index == 0);
1785 operator*()
const requires __detail::__dereferenceable<const _It>
1787 __glibcxx_assert(_M_index == 0);
1792 operator->()
const requires __detail::__common_iter_has_arrow<_It>
1794 __glibcxx_assert(_M_index == 0);
1795 if constexpr (is_pointer_v<_It> || requires { _M_it.operator->(); })
1797 else if constexpr (is_reference_v<iter_reference_t<_It>>)
1799 auto&& __tmp = *_M_it;
1803 return _Proxy{*_M_it};
1809 __glibcxx_assert(_M_index == 0);
1817 __glibcxx_assert(_M_index == 0);
1818 if constexpr (forward_iterator<_It>)
1820 common_iterator __tmp = *
this;
1828 template<
typename _It2, sentinel_for<_It> _Sent2>
1829 requires sentinel_for<_Sent, _It2>
1831 operator==(
const common_iterator& __x,
1832 const common_iterator<_It2, _Sent2>& __y)
1834 switch(__x._M_index << 2 | __y._M_index)
1840 return __x._M_it == __y._M_sent;
1842 return __x._M_sent == __y._M_it;
1844 __glibcxx_assert(__x._M_has_value());
1845 __glibcxx_assert(__y._M_has_value());
1846 __builtin_unreachable();
1850 template<
typename _It2, sentinel_for<_It> _Sent2>
1851 requires sentinel_for<_Sent, _It2> && equality_comparable_with<_It, _It2>
1853 operator==(
const common_iterator& __x,
1854 const common_iterator<_It2, _Sent2>& __y)
1856 switch(__x._M_index << 2 | __y._M_index)
1861 return __x._M_it == __y._M_it;
1863 return __x._M_it == __y._M_sent;
1865 return __x._M_sent == __y._M_it;
1867 __glibcxx_assert(__x._M_has_value());
1868 __glibcxx_assert(__y._M_has_value());
1869 __builtin_unreachable();
1873 template<sized_sentinel_for<_It> _It2, sized_sentinel_for<_It> _Sent2>
1874 requires sized_sentinel_for<_Sent, _It2>
1875 friend iter_difference_t<_It2>
1877 const common_iterator<_It2, _Sent2>& __y)
1879 switch(__x._M_index << 2 | __y._M_index)
1884 return __x._M_it - __y._M_it;
1886 return __x._M_it - __y._M_sent;
1888 return __x._M_sent - __y._M_it;
1890 __glibcxx_assert(__x._M_has_value());
1891 __glibcxx_assert(__y._M_has_value());
1892 __builtin_unreachable();
1896 friend iter_rvalue_reference_t<_It>
1897 iter_move(
const common_iterator& __i)
1898 noexcept(noexcept(ranges::iter_move(std::declval<const _It&>())))
1899 requires input_iterator<_It>
1901 __glibcxx_assert(__i._M_index == 0);
1902 return ranges::iter_move(__i._M_it);
1905 template<indirectly_swappable<_It> _It2,
typename _Sent2>
1907 iter_swap(
const common_iterator& __x,
1908 const common_iterator<_It2, _Sent2>& __y)
1909 noexcept(noexcept(ranges::iter_swap(std::declval<const _It&>(),
1910 std::declval<const _It2&>())))
1912 __glibcxx_assert(__x._M_index == 0);
1913 __glibcxx_assert(__y._M_index == 0);
1914 return ranges::iter_swap(__x._M_it, __y._M_it);
1918 template<input_or_output_iterator _It2, sentinel_for<_It2> _Sent2>
1919 friend class common_iterator;
1921 bool _M_has_value()
const noexcept {
return _M_index < 2; }
1927 unsigned char _M_valueless;
1929 unsigned char _M_index;
1932 template<
typename _It,
typename _Sent>
1933 struct incrementable_traits<common_iterator<_It, _Sent>>
1935 using difference_type = iter_difference_t<_It>;
1938 template<input_iterator _It,
typename _Sent>
1942 template<
typename _Iter>
1948 template<
typename _Iter>
1949 requires __detail::__common_iter_has_arrow<_Iter>
1952 using _CIter = common_iterator<_Iter, _Sent>;
1953 using type = decltype(std::declval<const _CIter&>().operator->());
1959 using iterator_category = __detail::__clamp_iter_cat<
1961 forward_iterator_tag, input_iterator_tag>;
1962 using value_type = iter_value_t<_It>;
1963 using difference_type = iter_difference_t<_It>;
1964 using pointer =
typename __ptr<_It>::type;
1965 using reference = iter_reference_t<_It>;
1971 template<input_or_output_iterator _It>
1972 class counted_iterator
1975 using iterator_type = _It;
1977 constexpr counted_iterator() =
default;
1980 counted_iterator(_It __i, iter_difference_t<_It> __n)
1981 : _M_current(
std::move(__i)), _M_length(__n)
1982 { __glibcxx_assert(__n >= 0); }
1984 template<
typename _It2>
1985 requires convertible_to<const _It2&, _It>
1987 counted_iterator(
const counted_iterator<_It2>& __x)
1988 : _M_current(__x._M_current), _M_length(__x._M_length)
1991 template<
typename _It2>
1992 requires assignable_from<_It&, const _It2&>
1993 constexpr counted_iterator&
1994 operator=(
const counted_iterator<_It2>& __x)
1996 _M_current = __x._M_current;
1997 _M_length = __x._M_length;
2003 noexcept(is_nothrow_copy_constructible_v<_It>)
2004 requires copy_constructible<_It>
2005 {
return _M_current; }
2009 noexcept(is_nothrow_move_constructible_v<_It>)
2012 constexpr iter_difference_t<_It>
2013 count()
const noexcept {
return _M_length; }
2015 constexpr decltype(
auto)
2017 noexcept(noexcept(*_M_current))
2018 {
return *_M_current; }
2020 constexpr decltype(
auto)
2022 noexcept(noexcept(*_M_current))
2023 requires __detail::__dereferenceable<const _It>
2024 {
return *_M_current; }
2026 constexpr counted_iterator&
2029 __glibcxx_assert(_M_length > 0);
2038 __glibcxx_assert(_M_length > 0);
2042 return _M_current++;
2045 __throw_exception_again;
2050 constexpr counted_iterator
2051 operator++(
int) requires forward_iterator<_It>
2058 constexpr counted_iterator&
2059 operator--() requires bidirectional_iterator<_It>
2066 constexpr counted_iterator
2067 operator--(
int) requires bidirectional_iterator<_It>
2074 constexpr counted_iterator
2075 operator+(iter_difference_t<_It> __n)
const 2076 requires random_access_iterator<_It>
2077 {
return counted_iterator(_M_current + __n, _M_length - __n); }
2079 friend constexpr counted_iterator
2080 operator+(iter_difference_t<_It> __n,
const counted_iterator& __x)
2081 requires random_access_iterator<_It>
2082 {
return __x + __n; }
2084 constexpr counted_iterator&
2085 operator+=(iter_difference_t<_It> __n)
2086 requires random_access_iterator<_It>
2088 __glibcxx_assert(__n <= _M_length);
2094 constexpr counted_iterator
2095 operator-(iter_difference_t<_It> __n)
const 2096 requires random_access_iterator<_It>
2097 {
return counted_iterator(_M_current - __n, _M_length + __n); }
2099 template<common_with<_It> _It2>
2100 friend constexpr iter_difference_t<_It2>
2102 const counted_iterator<_It2>& __y)
2103 {
return __y._M_length - __x._M_length; }
2105 friend constexpr iter_difference_t<_It>
2106 operator-(
const counted_iterator& __x, default_sentinel_t)
2107 {
return -__x._M_length; }
2109 friend constexpr iter_difference_t<_It>
2110 operator-(default_sentinel_t,
const counted_iterator& __y)
2111 {
return __y._M_length; }
2113 constexpr counted_iterator&
2114 operator-=(iter_difference_t<_It> __n)
2115 requires random_access_iterator<_It>
2117 __glibcxx_assert(-__n <= _M_length);
2123 constexpr decltype(
auto)
2124 operator[](iter_difference_t<_It> __n)
const 2125 noexcept(noexcept(_M_current[__n]))
2126 requires random_access_iterator<_It>
2128 __glibcxx_assert(__n < _M_length);
2129 return _M_current[__n];
2132 template<common_with<_It> _It2>
2133 friend constexpr
bool 2134 operator==(
const counted_iterator& __x,
2135 const counted_iterator<_It2>& __y)
2136 {
return __x._M_length == __y._M_length; }
2138 friend constexpr
bool 2139 operator==(
const counted_iterator& __x, default_sentinel_t)
2140 {
return __x._M_length == 0; }
2142 template<common_with<_It> _It2>
2143 friend constexpr strong_ordering
2144 operator<=>(
const counted_iterator& __x,
2145 const counted_iterator<_It2>& __y)
2146 {
return __y._M_length <=> __x._M_length; }
2148 friend constexpr iter_rvalue_reference_t<_It>
2149 iter_move(
const counted_iterator& __i)
2150 noexcept(noexcept(ranges::iter_move(__i._M_current)))
2151 requires input_iterator<_It>
2152 {
return ranges::iter_move(__i._M_current); }
2154 template<indirectly_swappable<_It> _It2>
2155 friend constexpr
void 2156 iter_swap(
const counted_iterator& __x,
2157 const counted_iterator<_It2>& __y)
2158 noexcept(noexcept(ranges::iter_swap(__x._M_current, __y._M_current)))
2159 { ranges::iter_swap(__x._M_current, __y._M_current); }
2162 template<input_or_output_iterator _It2>
friend class counted_iterator;
2164 _It _M_current = _It();
2165 iter_difference_t<_It> _M_length = 0;
2168 template<
typename _It>
2169 struct incrementable_traits<counted_iterator<_It>>
2171 using difference_type = iter_difference_t<_It>;
2174 template<input_iterator _It>
2177 using pointer = void;
2183 template<
typename _Iterator>
2186 -> decltype(make_move_iterator(__niter_base(__it.base())))
2187 {
return make_move_iterator(__niter_base(__it.base())); }
2189 template<
typename _Iterator>
2190 struct __is_move_iterator<move_iterator<_Iterator> >
2192 enum { __value = 1 };
2193 typedef __true_type __type;
2196 template<
typename _Iterator>
2199 -> decltype(__miter_base(__it.base()))
2200 {
return __miter_base(__it.base()); }
2202 #define _GLIBCXX_MAKE_MOVE_ITERATOR(_Iter) std::make_move_iterator(_Iter) 2203 #define _GLIBCXX_MAKE_MOVE_IF_NOEXCEPT_ITERATOR(_Iter) \ 2204 std::__make_move_if_noexcept_iterator(_Iter) 2206 #define _GLIBCXX_MAKE_MOVE_ITERATOR(_Iter) (_Iter) 2207 #define _GLIBCXX_MAKE_MOVE_IF_NOEXCEPT_ITERATOR(_Iter) (_Iter) 2210 #if __cpp_deduction_guides >= 201606 2213 template<
typename _InputIterator>
2217 template<
typename _InputIterator>
2218 using __iter_val_t =
2221 template<
typename _T1,
typename _T2>
2224 template<
typename _InputIterator>
2225 using __iter_to_alloc_t =
2227 __iter_val_t<_InputIterator>>;
2228 #endif // __cpp_deduction_guides 2230 _GLIBCXX_END_NAMESPACE_VERSION
2233 #ifdef _GLIBCXX_DEBUG constexpr reverse_iterator operator++(int)
constexpr front_insert_iterator(_Container &__x)
The only way to create this iterator is with a container.
constexpr front_insert_iterator & operator*()
Simply returns *this.
_Container container_type
A nested typedef for the type of whatever container you used.
typename conditional< _Cond, _Iftrue, _Iffalse >::type conditional_t
Alias template for conditional.
constexpr reverse_iterator()
Bidirectional iterators support a superset of forward iterator operations.
insert_iterator< _Container > inserter(_Container &__x, _Iterator __i)
constexpr complex< _Tp > operator*(const complex< _Tp > &__x, const complex< _Tp > &__y)
Return new complex value x times y.
Turns assignment into insertion.
constexpr back_insert_iterator & operator=(const typename _Container::value_type &__value)
constexpr complex< _Tp > operator-(const complex< _Tp > &__x, const complex< _Tp > &__y)
Return new complex value x minus y.
constexpr reverse_iterator(iterator_type __x)
constexpr insert_iterator & operator*()
Simply returns *this.
constexpr _Tp * __addressof(_Tp &__r) noexcept
Same as C++11 std::addressof.
constexpr back_insert_iterator & operator++()
Simply returns *this. (This iterator does not move.)
constexpr insert_iterator & operator++(int)
Simply returns *this. (This iterator does not move.)
constexpr reverse_iterator & operator++()
constexpr front_insert_iterator & operator++()
Simply returns *this. (This iterator does not move.)
constexpr back_insert_iterator & operator*()
Simply returns *this.
constexpr complex< _Tp > operator+(const complex< _Tp > &__x, const complex< _Tp > &__y)
Return new complex value x plus y.
constexpr reverse_iterator(const reverse_iterator< _Iter > &__x)
constexpr insert_iterator & operator++()
Simply returns *this. (This iterator does not move.)
constexpr reverse_iterator operator+(difference_type __n) const
constexpr reference operator[](difference_type __n) const
_Container container_type
A nested typedef for the type of whatever container you used.
constexpr front_insert_iterator operator++(int)
Simply returns *this. (This iterator does not move.)
Define a member typedef type to one of two argument types.
constexpr reference operator*() const
typename remove_const< _Tp >::type remove_const_t
Alias template for remove_const.
constexpr reverse_iterator(const reverse_iterator &__x)
constexpr front_insert_iterator< _Container > front_inserter(_Container &__x)
_Container container_type
A nested typedef for the type of whatever container you used.
is_nothrow_copy_constructible
constexpr back_insert_iterator operator++(int)
Simply returns *this. (This iterator does not move.)
iterator_traits< _Iterator >::iterator_category iterator_category
One of the tag types.
constexpr back_insert_iterator(_Container &__x)
The only way to create this iterator is with a container.
constexpr reverse_iterator operator--(int)
ISO C++ entities toplevel namespace is std.
constexpr reverse_iterator & operator-=(difference_type __n)
constexpr insert_iterator & operator=(const typename _Container::value_type &__value)
constexpr reverse_iterator & operator--()
Turns assignment into insertion.
constexpr std::remove_reference< _Tp >::type && move(_Tp &&__t) noexcept
Convert a value to an rvalue.
constexpr reverse_iterator operator-(difference_type __n) const
GNU extensions for public use.
Forward iterators support a superset of input iterator operations.
Struct holding two objects of arbitrary type.
constexpr front_insert_iterator & operator=(const typename _Container::value_type &__value)
constexpr iterator_type base() const
Turns assignment into insertion.
constexpr insert_iterator(_Container &__x, _Iter __i)
Traits class for iterators.
constexpr reverse_iterator & operator+=(difference_type __n)
constexpr back_insert_iterator< _Container > back_inserter(_Container &__x)
Random-access iterators support a superset of bidirectional iterator operations.
constexpr reverse_iterator< _Iterator > make_reverse_iterator(_Iterator __i)
Generator function for reverse_iterator.
constexpr pointer operator->() const