60#ifndef _STL_ITERATOR_H
61#define _STL_ITERATOR_H 1
69#if __cplusplus >= 201103L
73#if __cplusplus > 201703L
74# define __cpp_lib_array_constexpr 201811L
75# define __cpp_lib_constexpr_iterator 201811L
76#elif __cplusplus == 201703L
77# define __cpp_lib_array_constexpr 201803L
80#if __cplusplus >= 202002L
88namespace std _GLIBCXX_VISIBILITY(default)
90_GLIBCXX_BEGIN_NAMESPACE_VERSION
102 template<
typename _Cat,
typename _Limit,
typename _Otherwise = _Cat>
103 using __clamp_iter_cat
104 = conditional_t<derived_from<_Cat, _Limit>, _Limit, _Otherwise>;
127 template<
typename _Iterator>
129 :
public iterator<typename iterator_traits<_Iterator>::iterator_category,
130 typename iterator_traits<_Iterator>::value_type,
131 typename iterator_traits<_Iterator>::difference_type,
132 typename iterator_traits<_Iterator>::pointer,
133 typename iterator_traits<_Iterator>::reference>
135 template<
typename _Iter>
138#if __cpp_lib_concepts
141 template<
typename _Iter>
142 static constexpr bool __convertible = !is_same_v<_Iter, _Iterator>
143 && convertible_to<const _Iter&, _Iterator>;
152 typedef _Iterator iterator_type;
153 typedef typename __traits_type::pointer pointer;
154#if ! __cpp_lib_concepts
155 typedef typename __traits_type::difference_type difference_type;
156 typedef typename __traits_type::reference reference;
158 using iterator_concept
163 = __detail::__clamp_iter_cat<
typename __traits_type::iterator_category,
166 using difference_type = iter_difference_t<_Iterator>;
167 using reference = iter_reference_t<_Iterator>;
183 explicit _GLIBCXX17_CONSTEXPR
191 : current(__x.current) { }
193#if __cplusplus >= 201103L
201 template<
typename _Iter>
202#if __cpp_lib_concepts
203 requires __convertible<_Iter>
207 : current(__x.current) { }
209#if __cplusplus >= 201103L
210 template<
typename _Iter>
211#if __cpp_lib_concepts
212 requires __convertible<_Iter>
213 && assignable_from<_Iterator&, const _Iter&>
219 current = __x.current;
227 _GLIBCXX17_CONSTEXPR iterator_type
241 _GLIBCXX17_CONSTEXPR reference
244 _Iterator __tmp = current;
253 _GLIBCXX17_CONSTEXPR pointer
255#if __cplusplus > 201703L && __cpp_concepts >= 201907L
256 requires is_pointer_v<_Iterator>
257 ||
requires(
const _Iterator __i) { __i.operator->(); }
262 _Iterator __tmp = current;
264 return _S_to_pointer(__tmp);
272 _GLIBCXX17_CONSTEXPR reverse_iterator&
366 _GLIBCXX17_CONSTEXPR reference
368 {
return *(*
this + __n); }
370#if __cplusplus > 201703L && __cpp_lib_concepts
371 friend constexpr iter_rvalue_reference_t<_Iterator>
373 noexcept(is_nothrow_copy_constructible_v<_Iterator>
374 &&
noexcept(ranges::iter_move(--std::declval<_Iterator&>())))
376 auto __tmp = __i.base();
377 return ranges::iter_move(--__tmp);
380 template<indirectly_swappable<_Iterator> _Iter2>
381 friend constexpr void
382 iter_swap(
const reverse_iterator& __x,
383 const reverse_iterator<_Iter2>& __y)
384 noexcept(is_nothrow_copy_constructible_v<_Iterator>
385 && is_nothrow_copy_constructible_v<_Iter2>
386 &&
noexcept(ranges::iter_swap(--std::declval<_Iterator&>(),
387 --std::declval<_Iter2&>())))
389 auto __xtmp = __x.base();
390 auto __ytmp = __y.base();
391 ranges::iter_swap(--__xtmp, --__ytmp);
396 template<
typename _Tp>
397 static _GLIBCXX17_CONSTEXPR _Tp*
398 _S_to_pointer(_Tp* __p)
401 template<
typename _Tp>
402 static _GLIBCXX17_CONSTEXPR pointer
403 _S_to_pointer(_Tp __t)
404 {
return __t.operator->(); }
417#if __cplusplus <= 201703L || ! defined __cpp_lib_concepts
418 template<
typename _Iterator>
419 inline _GLIBCXX17_CONSTEXPR
bool
422 {
return __x.
base() == __y.
base(); }
424 template<
typename _Iterator>
425 inline _GLIBCXX17_CONSTEXPR
bool
426 operator<(
const reverse_iterator<_Iterator>& __x,
427 const reverse_iterator<_Iterator>& __y)
428 {
return __y.base() < __x.base(); }
430 template<
typename _Iterator>
431 inline _GLIBCXX17_CONSTEXPR
bool
432 operator!=(
const reverse_iterator<_Iterator>& __x,
433 const reverse_iterator<_Iterator>& __y)
434 {
return !(__x == __y); }
436 template<
typename _Iterator>
437 inline _GLIBCXX17_CONSTEXPR
bool
438 operator>(
const reverse_iterator<_Iterator>& __x,
439 const reverse_iterator<_Iterator>& __y)
440 {
return __y < __x; }
442 template<
typename _Iterator>
443 inline _GLIBCXX17_CONSTEXPR
bool
444 operator<=(
const reverse_iterator<_Iterator>& __x,
445 const reverse_iterator<_Iterator>& __y)
446 {
return !(__y < __x); }
448 template<
typename _Iterator>
449 inline _GLIBCXX17_CONSTEXPR
bool
450 operator>=(
const reverse_iterator<_Iterator>& __x,
451 const reverse_iterator<_Iterator>& __y)
452 {
return !(__x < __y); }
457 template<
typename _IteratorL,
typename _IteratorR>
458 inline _GLIBCXX17_CONSTEXPR
bool
459 operator==(
const reverse_iterator<_IteratorL>& __x,
460 const reverse_iterator<_IteratorR>& __y)
461 {
return __x.base() == __y.base(); }
463 template<
typename _IteratorL,
typename _IteratorR>
464 inline _GLIBCXX17_CONSTEXPR
bool
465 operator<(
const reverse_iterator<_IteratorL>& __x,
466 const reverse_iterator<_IteratorR>& __y)
467 {
return __x.base() > __y.base(); }
469 template<
typename _IteratorL,
typename _IteratorR>
470 inline _GLIBCXX17_CONSTEXPR
bool
471 operator!=(
const reverse_iterator<_IteratorL>& __x,
472 const reverse_iterator<_IteratorR>& __y)
473 {
return __x.base() != __y.base(); }
475 template<
typename _IteratorL,
typename _IteratorR>
476 inline _GLIBCXX17_CONSTEXPR
bool
477 operator>(
const reverse_iterator<_IteratorL>& __x,
478 const reverse_iterator<_IteratorR>& __y)
479 {
return __x.base() < __y.base(); }
481 template<
typename _IteratorL,
typename _IteratorR>
482 inline _GLIBCXX17_CONSTEXPR
bool
483 operator<=(
const reverse_iterator<_IteratorL>& __x,
484 const reverse_iterator<_IteratorR>& __y)
485 {
return __x.base() >= __y.base(); }
487 template<
typename _IteratorL,
typename _IteratorR>
488 inline _GLIBCXX17_CONSTEXPR
bool
489 operator>=(
const reverse_iterator<_IteratorL>& __x,
490 const reverse_iterator<_IteratorR>& __y)
491 {
return __x.base() <= __y.base(); }
493 template<
typename _IteratorL,
typename _IteratorR>
495 operator==(
const reverse_iterator<_IteratorL>& __x,
496 const reverse_iterator<_IteratorR>& __y)
497 requires requires { { __x.base() == __y.base() } -> convertible_to<bool>; }
498 {
return __x.base() == __y.base(); }
500 template<
typename _IteratorL,
typename _IteratorR>
502 operator!=(
const reverse_iterator<_IteratorL>& __x,
503 const reverse_iterator<_IteratorR>& __y)
504 requires requires { { __x.base() != __y.base() } -> convertible_to<bool>; }
505 {
return __x.base() != __y.base(); }
507 template<
typename _IteratorL,
typename _IteratorR>
509 operator<(
const reverse_iterator<_IteratorL>& __x,
510 const reverse_iterator<_IteratorR>& __y)
511 requires requires { { __x.base() > __y.base() } -> convertible_to<bool>; }
512 {
return __x.base() > __y.base(); }
514 template<
typename _IteratorL,
typename _IteratorR>
516 operator>(
const reverse_iterator<_IteratorL>& __x,
517 const reverse_iterator<_IteratorR>& __y)
518 requires requires { { __x.base() < __y.base() } -> convertible_to<bool>; }
519 {
return __x.base() < __y.base(); }
521 template<
typename _IteratorL,
typename _IteratorR>
523 operator<=(
const reverse_iterator<_IteratorL>& __x,
524 const reverse_iterator<_IteratorR>& __y)
525 requires requires { { __x.base() >= __y.base() } -> convertible_to<bool>; }
526 {
return __x.base() >= __y.base(); }
528 template<
typename _IteratorL,
typename _IteratorR>
530 operator>=(
const reverse_iterator<_IteratorL>& __x,
531 const reverse_iterator<_IteratorR>& __y)
532 requires requires { { __x.base() <= __y.base() } -> convertible_to<bool>; }
533 {
return __x.base() <= __y.base(); }
535 template<
typename _IteratorL,
536 three_way_comparable_with<_IteratorL> _IteratorR>
537 constexpr compare_three_way_result_t<_IteratorL, _IteratorR>
538 operator<=>(
const reverse_iterator<_IteratorL>& __x,
539 const reverse_iterator<_IteratorR>& __y)
540 {
return __y.base() <=> __x.base(); }
545 template<
typename _Iterator>
547 operator==(
const reverse_iterator<_Iterator>& __x,
548 const reverse_iterator<_Iterator>& __y)
549 requires requires { { __x.base() == __y.base() } -> convertible_to<bool>; }
550 {
return __x.base() == __y.base(); }
552 template<three_way_comparable _Iterator>
553 constexpr compare_three_way_result_t<_Iterator, _Iterator>
554 operator<=>(
const reverse_iterator<_Iterator>& __x,
555 const reverse_iterator<_Iterator>& __y)
556 {
return __y.base() <=> __x.base(); }
560#if __cplusplus < 201103L
561 template<
typename _Iterator>
562 inline typename reverse_iterator<_Iterator>::difference_type
563 operator-(
const reverse_iterator<_Iterator>& __x,
564 const reverse_iterator<_Iterator>& __y)
565 {
return __y.base() - __x.base(); }
567 template<
typename _IteratorL,
typename _IteratorR>
568 inline typename reverse_iterator<_IteratorL>::difference_type
569 operator-(
const reverse_iterator<_IteratorL>& __x,
570 const reverse_iterator<_IteratorR>& __y)
571 {
return __y.base() - __x.base(); }
575 template<
typename _IteratorL,
typename _IteratorR>
576 inline _GLIBCXX17_CONSTEXPR
auto
577 operator-(
const reverse_iterator<_IteratorL>& __x,
578 const reverse_iterator<_IteratorR>& __y)
579 ->
decltype(__y.base() - __x.base())
580 {
return __y.base() - __x.base(); }
583 template<
typename _Iterator>
584 inline _GLIBCXX17_CONSTEXPR reverse_iterator<_Iterator>
585 operator+(
typename reverse_iterator<_Iterator>::difference_type __n,
586 const reverse_iterator<_Iterator>& __x)
587 {
return reverse_iterator<_Iterator>(__x.base() - __n); }
589#if __cplusplus >= 201103L
591 template<
typename _Iterator>
592 inline _GLIBCXX17_CONSTEXPR reverse_iterator<_Iterator>
593 __make_reverse_iterator(_Iterator __i)
594 {
return reverse_iterator<_Iterator>(__i); }
596# if __cplusplus >= 201402L
597# define __cpp_lib_make_reverse_iterator 201402
602 template<
typename _Iterator>
603 inline _GLIBCXX17_CONSTEXPR reverse_iterator<_Iterator>
607# if __cplusplus > 201703L && defined __cpp_lib_concepts
608 template<
typename _Iterator1,
typename _Iterator2>
609 requires (!sized_sentinel_for<_Iterator1, _Iterator2>)
610 inline constexpr bool
611 disable_sized_sentinel_for<reverse_iterator<_Iterator1>,
612 reverse_iterator<_Iterator2>> =
true;
616 template<
typename _Iterator>
619 __niter_base(reverse_iterator<_Iterator> __it)
620 ->
decltype(__make_reverse_iterator(__niter_base(__it.base())))
621 {
return __make_reverse_iterator(__niter_base(__it.base())); }
623 template<
typename _Iterator>
624 struct __is_move_iterator<reverse_iterator<_Iterator> >
625 : __is_move_iterator<_Iterator>
628 template<
typename _Iterator>
631 __miter_base(reverse_iterator<_Iterator> __it)
632 ->
decltype(__make_reverse_iterator(__miter_base(__it.base())))
633 {
return __make_reverse_iterator(__miter_base(__it.base())); }
647 template<
typename _Container>
649 :
public iterator<output_iterator_tag, void, void, void, void>
652 _Container* container;
657#if __cplusplus > 201703L
664 explicit _GLIBCXX20_CONSTEXPR
679#if __cplusplus < 201103L
681 operator=(
typename _Container::const_reference __value)
683 container->push_back(__value);
688 back_insert_iterator&
689 operator=(
const typename _Container::value_type& __value)
691 container->push_back(__value);
697 operator=(
typename _Container::value_type&& __value)
699 container->push_back(
std::move(__value));
706 back_insert_iterator&
734 template<
typename _Container>
736 inline back_insert_iterator<_Container>
750 template<
typename _Container>
752 :
public iterator<output_iterator_tag, void, void, void, void>
755 _Container* container;
760#if __cplusplus > 201703L
767 explicit _GLIBCXX20_CONSTEXPR
782#if __cplusplus < 201103L
784 operator=(
typename _Container::const_reference __value)
786 container->push_front(__value);
791 front_insert_iterator&
792 operator=(
const typename _Container::value_type& __value)
794 container->push_front(__value);
800 operator=(
typename _Container::value_type&& __value)
802 container->push_front(
std::move(__value));
809 front_insert_iterator&
837 template<
typename _Container>
839 inline front_insert_iterator<_Container>
857 template<
typename _Container>
859 :
public iterator<output_iterator_tag, void, void, void, void>
861#if __cplusplus > 201703L && defined __cpp_lib_concepts
862 using _Iter = std::__detail::__range_iter_t<_Container>;
865 _Container* container =
nullptr;
866 _Iter iter = _Iter();
868 typedef typename _Container::iterator _Iter;
871 _Container* container;
879#if __cplusplus > 201703L && defined __cpp_lib_concepts
916#if __cplusplus < 201103L
918 operator=(
typename _Container::const_reference __value)
920 iter = container->insert(iter, __value);
927 operator=(
const typename _Container::value_type& __value)
929 iter = container->insert(iter, __value);
936 operator=(
typename _Container::value_type&& __value)
938 iter = container->insert(iter,
std::move(__value));
975#if __cplusplus > 201703L && defined __cpp_lib_concepts
976 template<
typename _Container>
977 constexpr insert_iterator<_Container>
978 inserter(_Container& __x, std::__detail::__range_iter_t<_Container> __i)
979 {
return insert_iterator<_Container>(__x, __i); }
981 template<
typename _Container>
982 inline insert_iterator<_Container>
983 inserter(_Container& __x,
typename _Container::iterator __i)
989_GLIBCXX_END_NAMESPACE_VERSION
992namespace __gnu_cxx _GLIBCXX_VISIBILITY(default)
994_GLIBCXX_BEGIN_NAMESPACE_VERSION
1003 template<
typename _Iterator,
typename _Container>
1004 class __normal_iterator
1007 _Iterator _M_current;
1012 typedef _Iterator iterator_type;
1013 typedef typename __traits_type::iterator_category iterator_category;
1014 typedef typename __traits_type::value_type value_type;
1015 typedef typename __traits_type::difference_type difference_type;
1016 typedef typename __traits_type::reference reference;
1017 typedef typename __traits_type::pointer pointer;
1019#if __cplusplus > 201703L && __cpp_lib_concepts
1020 using iterator_concept = std::__detail::__iter_concept<_Iterator>;
1023 _GLIBCXX_CONSTEXPR __normal_iterator() _GLIBCXX_NOEXCEPT
1024 : _M_current(_Iterator()) { }
1026 explicit _GLIBCXX20_CONSTEXPR
1027 __normal_iterator(
const _Iterator& __i) _GLIBCXX_NOEXCEPT
1028 : _M_current(__i) { }
1031 template<
typename _Iter>
1032 _GLIBCXX20_CONSTEXPR
1033 __normal_iterator(
const __normal_iterator<_Iter,
1034 typename __enable_if<
1035 (std::__are_same<_Iter, typename _Container::pointer>::__value),
1036 _Container>::__type>& __i) _GLIBCXX_NOEXCEPT
1037 : _M_current(__i.base()) { }
1040 _GLIBCXX20_CONSTEXPR
1043 {
return *_M_current; }
1045 _GLIBCXX20_CONSTEXPR
1047 operator->() const _GLIBCXX_NOEXCEPT
1048 {
return _M_current; }
1050 _GLIBCXX20_CONSTEXPR
1052 operator++() _GLIBCXX_NOEXCEPT
1058 _GLIBCXX20_CONSTEXPR
1060 operator++(
int) _GLIBCXX_NOEXCEPT
1061 {
return __normal_iterator(_M_current++); }
1064 _GLIBCXX20_CONSTEXPR
1066 operator--() _GLIBCXX_NOEXCEPT
1072 _GLIBCXX20_CONSTEXPR
1074 operator--(
int) _GLIBCXX_NOEXCEPT
1075 {
return __normal_iterator(_M_current--); }
1078 _GLIBCXX20_CONSTEXPR
1080 operator[](difference_type __n)
const _GLIBCXX_NOEXCEPT
1081 {
return _M_current[__n]; }
1083 _GLIBCXX20_CONSTEXPR
1085 operator+=(difference_type __n) _GLIBCXX_NOEXCEPT
1086 { _M_current += __n;
return *
this; }
1088 _GLIBCXX20_CONSTEXPR
1090 operator+(difference_type __n)
const _GLIBCXX_NOEXCEPT
1091 {
return __normal_iterator(_M_current + __n); }
1093 _GLIBCXX20_CONSTEXPR
1095 operator-=(difference_type __n) _GLIBCXX_NOEXCEPT
1096 { _M_current -= __n;
return *
this; }
1098 _GLIBCXX20_CONSTEXPR
1100 operator-(difference_type __n)
const _GLIBCXX_NOEXCEPT
1101 {
return __normal_iterator(_M_current - __n); }
1103 _GLIBCXX20_CONSTEXPR
1105 base() const _GLIBCXX_NOEXCEPT
1106 {
return _M_current; }
1117#if __cpp_lib_three_way_comparison
1118 template<
typename _IteratorL,
typename _IteratorR,
typename _Container>
1119 requires requires (_IteratorL __lhs, _IteratorR __rhs)
1120 { { __lhs == __rhs } -> std::convertible_to<bool>; }
1122 operator==(
const __normal_iterator<_IteratorL, _Container>& __lhs,
1123 const __normal_iterator<_IteratorR, _Container>& __rhs)
1124 noexcept(
noexcept(__lhs.base() == __rhs.base()))
1125 {
return __lhs.base() == __rhs.base(); }
1127 template<
typename _IteratorL,
typename _IteratorR,
typename _Container>
1128 constexpr std::__detail::__synth3way_t<_IteratorR, _IteratorL>
1129 operator<=>(
const __normal_iterator<_IteratorL, _Container>& __lhs,
1130 const __normal_iterator<_IteratorR, _Container>& __rhs)
1131 noexcept(
noexcept(std::__detail::__synth3way(__lhs.base(), __rhs.base())))
1132 {
return std::__detail::__synth3way(__lhs.base(), __rhs.base()); }
1134 template<
typename _Iterator,
typename _Container>
1136 operator==(
const __normal_iterator<_Iterator, _Container>& __lhs,
1137 const __normal_iterator<_Iterator, _Container>& __rhs)
1138 noexcept(
noexcept(__lhs.base() == __rhs.base()))
1140 { __lhs.base() == __rhs.base() } -> std::convertible_to<bool>;
1142 {
return __lhs.base() == __rhs.base(); }
1144 template<
typename _Iterator,
typename _Container>
1145 constexpr std::__detail::__synth3way_t<_Iterator>
1146 operator<=>(
const __normal_iterator<_Iterator, _Container>& __lhs,
1147 const __normal_iterator<_Iterator, _Container>& __rhs)
1148 noexcept(
noexcept(std::__detail::__synth3way(__lhs.base(), __rhs.base())))
1149 {
return std::__detail::__synth3way(__lhs.base(), __rhs.base()); }
1152 template<
typename _IteratorL,
typename _IteratorR,
typename _Container>
1153 _GLIBCXX20_CONSTEXPR
1155 operator==(
const __normal_iterator<_IteratorL, _Container>& __lhs,
1156 const __normal_iterator<_IteratorR, _Container>& __rhs)
1158 {
return __lhs.base() == __rhs.base(); }
1160 template<
typename _Iterator,
typename _Container>
1161 _GLIBCXX20_CONSTEXPR
1163 operator==(
const __normal_iterator<_Iterator, _Container>& __lhs,
1164 const __normal_iterator<_Iterator, _Container>& __rhs)
1166 {
return __lhs.base() == __rhs.base(); }
1168 template<
typename _IteratorL,
typename _IteratorR,
typename _Container>
1169 _GLIBCXX20_CONSTEXPR
1171 operator!=(
const __normal_iterator<_IteratorL, _Container>& __lhs,
1172 const __normal_iterator<_IteratorR, _Container>& __rhs)
1174 {
return __lhs.base() != __rhs.base(); }
1176 template<
typename _Iterator,
typename _Container>
1177 _GLIBCXX20_CONSTEXPR
1179 operator!=(
const __normal_iterator<_Iterator, _Container>& __lhs,
1180 const __normal_iterator<_Iterator, _Container>& __rhs)
1182 {
return __lhs.base() != __rhs.base(); }
1185 template<
typename _IteratorL,
typename _IteratorR,
typename _Container>
1187 operator<(
const __normal_iterator<_IteratorL, _Container>& __lhs,
1188 const __normal_iterator<_IteratorR, _Container>& __rhs)
1190 {
return __lhs.base() < __rhs.base(); }
1192 template<
typename _Iterator,
typename _Container>
1193 _GLIBCXX20_CONSTEXPR
1195 operator<(
const __normal_iterator<_Iterator, _Container>& __lhs,
1196 const __normal_iterator<_Iterator, _Container>& __rhs)
1198 {
return __lhs.base() < __rhs.base(); }
1200 template<
typename _IteratorL,
typename _IteratorR,
typename _Container>
1202 operator>(
const __normal_iterator<_IteratorL, _Container>& __lhs,
1203 const __normal_iterator<_IteratorR, _Container>& __rhs)
1205 {
return __lhs.base() > __rhs.base(); }
1207 template<
typename _Iterator,
typename _Container>
1208 _GLIBCXX20_CONSTEXPR
1210 operator>(
const __normal_iterator<_Iterator, _Container>& __lhs,
1211 const __normal_iterator<_Iterator, _Container>& __rhs)
1213 {
return __lhs.base() > __rhs.base(); }
1215 template<
typename _IteratorL,
typename _IteratorR,
typename _Container>
1217 operator<=(
const __normal_iterator<_IteratorL, _Container>& __lhs,
1218 const __normal_iterator<_IteratorR, _Container>& __rhs)
1220 {
return __lhs.base() <= __rhs.base(); }
1222 template<
typename _Iterator,
typename _Container>
1223 _GLIBCXX20_CONSTEXPR
1225 operator<=(
const __normal_iterator<_Iterator, _Container>& __lhs,
1226 const __normal_iterator<_Iterator, _Container>& __rhs)
1228 {
return __lhs.base() <= __rhs.base(); }
1230 template<
typename _IteratorL,
typename _IteratorR,
typename _Container>
1232 operator>=(
const __normal_iterator<_IteratorL, _Container>& __lhs,
1233 const __normal_iterator<_IteratorR, _Container>& __rhs)
1235 {
return __lhs.base() >= __rhs.base(); }
1237 template<
typename _Iterator,
typename _Container>
1238 _GLIBCXX20_CONSTEXPR
1240 operator>=(
const __normal_iterator<_Iterator, _Container>& __lhs,
1241 const __normal_iterator<_Iterator, _Container>& __rhs)
1243 {
return __lhs.base() >= __rhs.base(); }
1250 template<
typename _IteratorL,
typename _IteratorR,
typename _Container>
1251#if __cplusplus >= 201103L
1253 _GLIBCXX20_CONSTEXPR
1255 operator-(
const __normal_iterator<_IteratorL, _Container>& __lhs,
1256 const __normal_iterator<_IteratorR, _Container>& __rhs)
noexcept
1257 ->
decltype(__lhs.base() - __rhs.base())
1259 inline typename __normal_iterator<_IteratorL, _Container>::difference_type
1260 operator-(
const __normal_iterator<_IteratorL, _Container>& __lhs,
1261 const __normal_iterator<_IteratorR, _Container>& __rhs)
1263 {
return __lhs.base() - __rhs.base(); }
1265 template<
typename _Iterator,
typename _Container>
1266 _GLIBCXX20_CONSTEXPR
1267 inline typename __normal_iterator<_Iterator, _Container>::difference_type
1268 operator-(
const __normal_iterator<_Iterator, _Container>& __lhs,
1269 const __normal_iterator<_Iterator, _Container>& __rhs)
1271 {
return __lhs.base() - __rhs.base(); }
1273 template<
typename _Iterator,
typename _Container>
1274 _GLIBCXX20_CONSTEXPR
1275 inline __normal_iterator<_Iterator, _Container>
1276 operator+(
typename __normal_iterator<_Iterator, _Container>::difference_type
1277 __n,
const __normal_iterator<_Iterator, _Container>& __i)
1279 {
return __normal_iterator<_Iterator, _Container>(__i.base() + __n); }
1281_GLIBCXX_END_NAMESPACE_VERSION
1284namespace std _GLIBCXX_VISIBILITY(default)
1286_GLIBCXX_BEGIN_NAMESPACE_VERSION
1288 template<
typename _Iterator,
typename _Container>
1289 _GLIBCXX20_CONSTEXPR
1291 __niter_base(__gnu_cxx::__normal_iterator<_Iterator, _Container> __it)
1293 {
return __it.base(); }
1295#if __cplusplus >= 201103L
1301#if __cplusplus > 201703L && __cpp_lib_concepts
1302 template<semiregular _Sent>
1308 noexcept(is_nothrow_default_constructible_v<_Sent>)
1312 move_sentinel(_Sent __s)
1313 noexcept(is_nothrow_move_constructible_v<_Sent>)
1316 template<
typename _S2>
requires convertible_to<const _S2&, _Sent>
1318 move_sentinel(
const move_sentinel<_S2>& __s)
1319 noexcept(is_nothrow_constructible_v<_Sent, const _S2&>)
1320 : _M_last(__s.base())
1323 template<
typename _S2>
requires assignable_from<_Sent&, const _S2&>
1324 constexpr move_sentinel&
1325 operator=(
const move_sentinel<_S2>& __s)
1326 noexcept(is_nothrow_assignable_v<_Sent, const _S2&>)
1328 _M_last = __s.base();
1334 noexcept(is_nothrow_copy_constructible_v<_Sent>)
1344#if __cplusplus > 201703L && __cpp_lib_concepts
1345 template<
typename _Iterator>
1346 struct __move_iter_cat
1349 template<
typename _Iterator>
1350 requires requires {
typename iterator_traits<_Iterator>::iterator_category; }
1351 struct __move_iter_cat<_Iterator>
1353 using iterator_category
1354 = __clamp_iter_cat<typename iterator_traits<_Iterator>::iterator_category,
1355 random_access_iterator_tag>;
1369 template<
typename _Iterator>
1371#if __cplusplus > 201703L && __cpp_lib_concepts
1372 :
public __detail::__move_iter_cat<_Iterator>
1375 _Iterator _M_current;
1378#if ! (__cplusplus > 201703L && __cpp_lib_concepts)
1379 using __base_ref =
typename __traits_type::reference;
1382 template<
typename _Iter2>
1385#if __cpp_lib_concepts
1388 template<
typename _Iter2>
1389 static constexpr bool __convertible = !is_same_v<_Iter2, _Iterator>
1390 && convertible_to<const _Iter2&, _Iterator>;
1393#if __cplusplus > 201703L && __cpp_lib_concepts
1397 if constexpr (random_access_iterator<_Iterator>)
1399 else if constexpr (bidirectional_iterator<_Iterator>)
1401 else if constexpr (forward_iterator<_Iterator>)
1409 using iterator_type = _Iterator;
1411#if __cplusplus > 201703L && __cpp_lib_concepts
1413# define __cpp_lib_move_iterator_concept 202207L
1414 using iterator_concept =
decltype(_S_iter_concept());
1417 using value_type = iter_value_t<_Iterator>;
1418 using difference_type = iter_difference_t<_Iterator>;
1419 using pointer = _Iterator;
1420 using reference = iter_rvalue_reference_t<_Iterator>;
1422 typedef typename __traits_type::iterator_category iterator_category;
1423 typedef typename __traits_type::value_type value_type;
1424 typedef typename __traits_type::difference_type difference_type;
1426 typedef _Iterator pointer;
1430 typename remove_reference<__base_ref>::type&&,
1434 _GLIBCXX17_CONSTEXPR
1438 explicit _GLIBCXX17_CONSTEXPR
1442 template<
typename _Iter>
1443#if __cpp_lib_concepts
1444 requires __convertible<_Iter>
1446 _GLIBCXX17_CONSTEXPR
1448 : _M_current(__i._M_current) { }
1450 template<
typename _Iter>
1451#if __cpp_lib_concepts
1452 requires __convertible<_Iter>
1453 && assignable_from<_Iterator&, const _Iter&>
1455 _GLIBCXX17_CONSTEXPR
1458 _M_current = __i._M_current;
1462#if __cplusplus <= 201703L
1463 _GLIBCXX17_CONSTEXPR iterator_type
1465 {
return _M_current; }
1467 constexpr const iterator_type&
1468 base()
const &
noexcept
1469 {
return _M_current; }
1471 constexpr iterator_type
1478#if __cplusplus > 201703L && __cpp_lib_concepts
1479 {
return ranges::iter_move(_M_current); }
1481 {
return static_cast<reference>(*_M_current); }
1484 _GLIBCXX17_CONSTEXPR pointer
1486 {
return _M_current; }
1503#if __cpp_lib_concepts
1505 operator++(
int)
requires (!forward_iterator<_Iterator>)
1529 operator+=(difference_type __n)
1540 operator-=(difference_type __n)
1547 operator[](difference_type __n)
const
1548#if __cplusplus > 201703L && __cpp_lib_concepts
1549 {
return ranges::iter_move(_M_current + __n); }
1554#if __cplusplus > 201703L && __cpp_lib_concepts
1555 template<sentinel_for<_Iterator> _Sent>
1556 friend constexpr bool
1557 operator==(
const move_iterator& __x,
const move_sentinel<_Sent>& __y)
1558 {
return __x.base() == __y.base(); }
1560 template<sized_sentinel_for<_Iterator> _Sent>
1561 friend constexpr iter_difference_t<_Iterator>
1563 {
return __x.base() - __y.base(); }
1565 template<sized_sentinel_for<_Iterator> _Sent>
1566 friend constexpr iter_difference_t<_Iterator>
1568 {
return __x.base() - __y.base(); }
1570 friend constexpr iter_rvalue_reference_t<_Iterator>
1572 noexcept(
noexcept(ranges::iter_move(__i._M_current)))
1573 {
return ranges::iter_move(__i._M_current); }
1575 template<indirectly_swappable<_Iterator> _Iter2>
1576 friend constexpr void
1578 noexcept(
noexcept(ranges::iter_swap(__x._M_current, __y._M_current)))
1579 {
return ranges::iter_swap(__x._M_current, __y._M_current); }
1583 template<
typename _IteratorL,
typename _IteratorR>
1584 inline _GLIBCXX17_CONSTEXPR
bool
1587#if __cplusplus > 201703L && __cpp_lib_concepts
1588 requires requires { { __x.base() == __y.base() } -> convertible_to<bool>; }
1590 {
return __x.base() == __y.base(); }
1592#if __cpp_lib_three_way_comparison
1593 template<
typename _IteratorL,
1594 three_way_comparable_with<_IteratorL> _IteratorR>
1595 constexpr compare_three_way_result_t<_IteratorL, _IteratorR>
1596 operator<=>(
const move_iterator<_IteratorL>& __x,
1597 const move_iterator<_IteratorR>& __y)
1598 {
return __x.base() <=> __y.base(); }
1600 template<
typename _IteratorL,
typename _IteratorR>
1601 inline _GLIBCXX17_CONSTEXPR
bool
1602 operator!=(
const move_iterator<_IteratorL>& __x,
1603 const move_iterator<_IteratorR>& __y)
1604 {
return !(__x == __y); }
1607 template<
typename _IteratorL,
typename _IteratorR>
1608 inline _GLIBCXX17_CONSTEXPR
bool
1609 operator<(
const move_iterator<_IteratorL>& __x,
1610 const move_iterator<_IteratorR>& __y)
1611#if __cplusplus > 201703L && __cpp_lib_concepts
1612 requires requires { { __x.base() < __y.base() } -> convertible_to<bool>; }
1614 {
return __x.base() < __y.base(); }
1616 template<
typename _IteratorL,
typename _IteratorR>
1617 inline _GLIBCXX17_CONSTEXPR
bool
1618 operator<=(
const move_iterator<_IteratorL>& __x,
1619 const move_iterator<_IteratorR>& __y)
1620#if __cplusplus > 201703L && __cpp_lib_concepts
1621 requires requires { { __y.base() < __x.base() } -> convertible_to<bool>; }
1623 {
return !(__y < __x); }
1625 template<
typename _IteratorL,
typename _IteratorR>
1626 inline _GLIBCXX17_CONSTEXPR
bool
1627 operator>(
const move_iterator<_IteratorL>& __x,
1628 const move_iterator<_IteratorR>& __y)
1629#if __cplusplus > 201703L && __cpp_lib_concepts
1630 requires requires { { __y.base() < __x.base() } -> convertible_to<bool>; }
1632 {
return __y < __x; }
1634 template<
typename _IteratorL,
typename _IteratorR>
1635 inline _GLIBCXX17_CONSTEXPR
bool
1636 operator>=(
const move_iterator<_IteratorL>& __x,
1637 const move_iterator<_IteratorR>& __y)
1638#if __cplusplus > 201703L && __cpp_lib_concepts
1639 requires requires { { __x.base() < __y.base() } -> convertible_to<bool>; }
1641 {
return !(__x < __y); }
1646 template<
typename _Iterator>
1647 inline _GLIBCXX17_CONSTEXPR
bool
1648 operator==(
const move_iterator<_Iterator>& __x,
1649 const move_iterator<_Iterator>& __y)
1650 {
return __x.base() == __y.base(); }
1652#if __cpp_lib_three_way_comparison
1653 template<three_way_comparable _Iterator>
1654 constexpr compare_three_way_result_t<_Iterator>
1655 operator<=>(
const move_iterator<_Iterator>& __x,
1656 const move_iterator<_Iterator>& __y)
1657 {
return __x.base() <=> __y.base(); }
1659 template<
typename _Iterator>
1660 inline _GLIBCXX17_CONSTEXPR
bool
1661 operator!=(
const move_iterator<_Iterator>& __x,
1662 const move_iterator<_Iterator>& __y)
1663 {
return !(__x == __y); }
1665 template<
typename _Iterator>
1666 inline _GLIBCXX17_CONSTEXPR
bool
1667 operator<(
const move_iterator<_Iterator>& __x,
1668 const move_iterator<_Iterator>& __y)
1669 {
return __x.base() < __y.base(); }
1671 template<
typename _Iterator>
1672 inline _GLIBCXX17_CONSTEXPR
bool
1673 operator<=(
const move_iterator<_Iterator>& __x,
1674 const move_iterator<_Iterator>& __y)
1675 {
return !(__y < __x); }
1677 template<
typename _Iterator>
1678 inline _GLIBCXX17_CONSTEXPR
bool
1679 operator>(
const move_iterator<_Iterator>& __x,
1680 const move_iterator<_Iterator>& __y)
1681 {
return __y < __x; }
1683 template<
typename _Iterator>
1684 inline _GLIBCXX17_CONSTEXPR
bool
1685 operator>=(
const move_iterator<_Iterator>& __x,
1686 const move_iterator<_Iterator>& __y)
1687 {
return !(__x < __y); }
1691 template<
typename _IteratorL,
typename _IteratorR>
1692 inline _GLIBCXX17_CONSTEXPR
auto
1693 operator-(
const move_iterator<_IteratorL>& __x,
1694 const move_iterator<_IteratorR>& __y)
1695 ->
decltype(__x.base() - __y.base())
1696 {
return __x.base() - __y.base(); }
1698 template<
typename _Iterator>
1699 inline _GLIBCXX17_CONSTEXPR move_iterator<_Iterator>
1700 operator+(
typename move_iterator<_Iterator>::difference_type __n,
1701 const move_iterator<_Iterator>& __x)
1702 {
return __x + __n; }
1704 template<
typename _Iterator>
1705 inline _GLIBCXX17_CONSTEXPR move_iterator<_Iterator>
1706 make_move_iterator(_Iterator __i)
1707 {
return move_iterator<_Iterator>(
std::move(__i)); }
1709 template<
typename _Iterator,
typename _ReturnType
1710 =
typename conditional<__move_if_noexcept_cond
1711 <
typename iterator_traits<_Iterator>::value_type>::value,
1712 _Iterator, move_iterator<_Iterator>>::type>
1713 inline _GLIBCXX17_CONSTEXPR _ReturnType
1714 __make_move_if_noexcept_iterator(_Iterator __i)
1715 {
return _ReturnType(__i); }
1719 template<
typename _Tp,
typename _ReturnType
1720 =
typename conditional<__move_if_noexcept_cond<_Tp>::value,
1721 const _Tp*, move_iterator<_Tp*>>::type>
1722 inline _GLIBCXX17_CONSTEXPR _ReturnType
1723 __make_move_if_noexcept_iterator(_Tp* __i)
1724 {
return _ReturnType(__i); }
1726#if __cplusplus > 201703L && __cpp_lib_concepts
1731 template<
typename _It>
1732 concept __common_iter_has_arrow = indirectly_readable<const _It>
1733 && (
requires(
const _It& __it) { __it.operator->(); }
1734 || is_reference_v<iter_reference_t<_It>>
1735 || constructible_from<iter_value_t<_It>, iter_reference_t<_It>>);
1737 template<
typename _It>
1738 concept __common_iter_use_postfix_proxy
1739 = (!
requires (_It& __i) { { *__i++ } -> __can_reference; })
1740 && constructible_from<iter_value_t<_It>, iter_reference_t<_It>>
1741 && move_constructible<iter_value_t<_It>>;
1745 template<input_or_output_iterator _It, sentinel_for<_It> _Sent>
1746 requires (!same_as<_It, _Sent>) && copyable<_It>
1747 class common_iterator
1749 template<
typename _Tp,
typename _Up>
1750 static constexpr bool
1753 if constexpr (is_trivially_default_constructible_v<_Tp>)
1754 return is_nothrow_assignable_v<_Tp&, _Up>;
1756 return is_nothrow_constructible_v<_Tp, _Up>;
1759 template<
typename _It2,
typename _Sent2>
1760 static constexpr bool
1762 {
return _S_noexcept1<_It, _It2>() && _S_noexcept1<_Sent, _Sent2>(); }
1766 iter_value_t<_It> _M_keep;
1769 __arrow_proxy(iter_reference_t<_It>&& __x)
1772 friend class common_iterator;
1775 constexpr const iter_value_t<_It>*
1776 operator->() const noexcept
1780 class __postfix_proxy
1782 iter_value_t<_It> _M_keep;
1785 __postfix_proxy(iter_reference_t<_It>&& __x)
1786 : _M_keep(
std::
forward<iter_reference_t<_It>>(__x)) { }
1788 friend class common_iterator;
1791 constexpr const iter_value_t<_It>&
1799 noexcept(is_nothrow_default_constructible_v<_It>)
1800 requires default_initializable<_It>
1801 : _M_it(), _M_index(0)
1805 common_iterator(_It __i)
1806 noexcept(is_nothrow_move_constructible_v<_It>)
1807 : _M_it(
std::
move(__i)), _M_index(0)
1811 common_iterator(_Sent __s)
1812 noexcept(is_nothrow_move_constructible_v<_Sent>)
1813 : _M_sent(
std::
move(__s)), _M_index(1)
1816 template<
typename _It2,
typename _Sent2>
1817 requires convertible_to<const _It2&, _It>
1818 && convertible_to<const _Sent2&, _Sent>
1820 common_iterator(
const common_iterator<_It2, _Sent2>& __x)
1821 noexcept(_S_noexcept<const _It2&, const _Sent2&>())
1822 : _M_valueless(), _M_index(__x._M_index)
1824 __glibcxx_assert(__x._M_has_value());
1827 if constexpr (is_trivially_default_constructible_v<_It>)
1832 else if (_M_index == 1)
1834 if constexpr (is_trivially_default_constructible_v<_Sent>)
1842 common_iterator(
const common_iterator& __x)
1843 noexcept(_S_noexcept<const _It&, const _Sent&>())
1844 : _M_valueless(), _M_index(__x._M_index)
1848 if constexpr (is_trivially_default_constructible_v<_It>)
1853 else if (_M_index == 1)
1855 if constexpr (is_trivially_default_constructible_v<_Sent>)
1856 _M_sent = __x._M_sent;
1863 common_iterator(common_iterator&& __x)
1864 noexcept(_S_noexcept<_It, _Sent>())
1865 : _M_valueless(), _M_index(__x._M_index)
1869 if constexpr (is_trivially_default_constructible_v<_It>)
1874 else if (_M_index == 1)
1876 if constexpr (is_trivially_default_constructible_v<_Sent>)
1884 constexpr common_iterator&
1885 operator=(
const common_iterator&) =
default;
1887 constexpr common_iterator&
1888 operator=(
const common_iterator& __x)
1889 noexcept(is_nothrow_copy_assignable_v<_It>
1890 && is_nothrow_copy_assignable_v<_Sent>
1891 && is_nothrow_copy_constructible_v<_It>
1892 && is_nothrow_copy_constructible_v<_Sent>)
1893 requires (!is_trivially_copy_assignable_v<_It>
1894 || !is_trivially_copy_assignable_v<_Sent>)
1900 constexpr common_iterator&
1901 operator=(common_iterator&&) =
default;
1903 constexpr common_iterator&
1904 operator=(common_iterator&& __x)
1905 noexcept(is_nothrow_move_assignable_v<_It>
1906 && is_nothrow_move_assignable_v<_Sent>
1907 && is_nothrow_move_constructible_v<_It>
1908 && is_nothrow_move_constructible_v<_Sent>)
1909 requires (!is_trivially_move_assignable_v<_It>
1910 || !is_trivially_move_assignable_v<_Sent>)
1916 template<
typename _It2,
typename _Sent2>
1917 requires convertible_to<const _It2&, _It>
1918 && convertible_to<const _Sent2&, _Sent>
1919 && assignable_from<_It&, const _It2&>
1920 && assignable_from<_Sent&, const _Sent2&>
1921 constexpr common_iterator&
1922 operator=(
const common_iterator<_It2, _Sent2>& __x)
1923 noexcept(is_nothrow_constructible_v<_It, const _It2&>
1924 && is_nothrow_constructible_v<_Sent, const _Sent2&>
1925 && is_nothrow_assignable_v<_It&, const _It2&>
1926 && is_nothrow_assignable_v<_Sent&, const _Sent2&>)
1928 __glibcxx_assert(__x._M_has_value());
1938 else if (_M_index == 1)
1943 constexpr decltype(
auto)
1946 __glibcxx_assert(_M_index == 0);
1951 constexpr decltype(
auto)
1952 operator*()
const requires __detail::__dereferenceable<const _It>
1954 __glibcxx_assert(_M_index == 0);
1960 operator->() const requires __detail::__common_iter_has_arrow<_It>
1962 __glibcxx_assert(_M_index == 0);
1963 if constexpr (is_pointer_v<_It> ||
requires { _M_it.operator->(); })
1965 else if constexpr (is_reference_v<iter_reference_t<_It>>)
1967 auto&& __tmp = *_M_it;
1971 return __arrow_proxy{*_M_it};
1974 constexpr common_iterator&
1977 __glibcxx_assert(_M_index == 0);
1982 constexpr decltype(
auto)
1985 __glibcxx_assert(_M_index == 0);
1986 if constexpr (forward_iterator<_It>)
1988 common_iterator __tmp = *
this;
1992 else if constexpr (!__detail::__common_iter_use_postfix_proxy<_It>)
1996 __postfix_proxy __p(**
this);
2002 template<
typename _It2, sentinel_for<_It> _Sent2>
2003 requires sentinel_for<_Sent, _It2>
2004 friend constexpr bool
2005 operator== [[nodiscard]] (
const common_iterator& __x,
2006 const common_iterator<_It2, _Sent2>& __y)
2008 switch(__x._M_index << 2 | __y._M_index)
2014 return __x._M_it == __y._M_sent;
2016 return __x._M_sent == __y._M_it;
2018 __glibcxx_assert(__x._M_has_value());
2019 __glibcxx_assert(__y._M_has_value());
2020 __builtin_unreachable();
2024 template<
typename _It2, sentinel_for<_It> _Sent2>
2025 requires sentinel_for<_Sent, _It2> && equality_comparable_with<_It, _It2>
2026 friend constexpr bool
2027 operator== [[nodiscard]] (
const common_iterator& __x,
2028 const common_iterator<_It2, _Sent2>& __y)
2030 switch(__x._M_index << 2 | __y._M_index)
2035 return __x._M_it == __y._M_it;
2037 return __x._M_it == __y._M_sent;
2039 return __x._M_sent == __y._M_it;
2041 __glibcxx_assert(__x._M_has_value());
2042 __glibcxx_assert(__y._M_has_value());
2043 __builtin_unreachable();
2047 template<sized_sentinel_for<_It> _It2, sized_sentinel_for<_It> _Sent2>
2048 requires sized_sentinel_for<_Sent, _It2>
2049 friend constexpr iter_difference_t<_It2>
2050 operator- [[nodiscard]] (
const common_iterator& __x,
2051 const common_iterator<_It2, _Sent2>& __y)
2053 switch(__x._M_index << 2 | __y._M_index)
2058 return __x._M_it - __y._M_it;
2060 return __x._M_it - __y._M_sent;
2062 return __x._M_sent - __y._M_it;
2064 __glibcxx_assert(__x._M_has_value());
2065 __glibcxx_assert(__y._M_has_value());
2066 __builtin_unreachable();
2071 friend constexpr iter_rvalue_reference_t<_It>
2072 iter_move(
const common_iterator& __i)
2073 noexcept(
noexcept(ranges::iter_move(std::declval<const _It&>())))
2074 requires input_iterator<_It>
2076 __glibcxx_assert(__i._M_index == 0);
2077 return ranges::iter_move(__i._M_it);
2080 template<indirectly_swappable<_It> _It2,
typename _Sent2>
2081 friend constexpr void
2082 iter_swap(
const common_iterator& __x,
2083 const common_iterator<_It2, _Sent2>& __y)
2084 noexcept(
noexcept(ranges::iter_swap(std::declval<const _It&>(),
2085 std::declval<const _It2&>())))
2087 __glibcxx_assert(__x._M_index == 0);
2088 __glibcxx_assert(__y._M_index == 0);
2089 return ranges::iter_swap(__x._M_it, __y._M_it);
2093 template<input_or_output_iterator _It2, sentinel_for<_It2> _Sent2>
2094 requires (!same_as<_It2, _Sent2>) && copyable<_It2>
2095 friend class common_iterator;
2098 _M_has_value() const noexcept {
return _M_index != _S_valueless; }
2100 template<
typename _CIt>
2102 _M_assign(_CIt&& __x)
2104 if (_M_index == __x._M_index)
2107 _M_it = std::forward<_CIt>(__x)._M_it;
2108 else if (_M_index == 1)
2109 _M_sent = std::forward<_CIt>(__x)._M_sent;
2115 else if (_M_index == 1)
2117 _M_index = _S_valueless;
2119 if (__x._M_index == 0)
2121 std::forward<_CIt>(__x)._M_it);
2122 else if (__x._M_index == 1)
2124 std::forward<_CIt>(__x)._M_sent);
2125 _M_index = __x._M_index;
2133 unsigned char _M_valueless;
2135 unsigned char _M_index;
2137 static constexpr unsigned char _S_valueless{2};
2140 template<
typename _It,
typename _Sent>
2141 struct incrementable_traits<common_iterator<_It, _Sent>>
2143 using difference_type = iter_difference_t<_It>;
2146 template<input_iterator _It,
typename _Sent>
2147 struct iterator_traits<common_iterator<_It, _Sent>>
2150 template<
typename _Iter>
2156 template<
typename _Iter>
2157 requires __detail::__common_iter_has_arrow<_Iter>
2160 using _CIter = common_iterator<_Iter, _Sent>;
2161 using type =
decltype(std::declval<const _CIter&>().operator->());
2167 using _Traits = iterator_traits<_It>;
2168 if constexpr (
requires {
requires derived_from<
typename _Traits::iterator_category,
2169 forward_iterator_tag>; })
2170 return forward_iterator_tag{};
2172 return input_iterator_tag{};
2176 using iterator_concept = conditional_t<forward_iterator<_It>,
2177 forward_iterator_tag, input_iterator_tag>;
2178 using iterator_category =
decltype(_S_iter_cat());
2179 using value_type = iter_value_t<_It>;
2180 using difference_type = iter_difference_t<_It>;
2181 using pointer =
typename __ptr<_It>::type;
2182 using reference = iter_reference_t<_It>;
2189 template<
typename _It>
2190 struct __counted_iter_value_type
2193 template<indirectly_readable _It>
2194 struct __counted_iter_value_type<_It>
2195 {
using value_type = iter_value_t<_It>; };
2197 template<
typename _It>
2198 struct __counted_iter_concept
2201 template<
typename _It>
2202 requires requires {
typename _It::iterator_concept; }
2203 struct __counted_iter_concept<_It>
2204 {
using iterator_concept =
typename _It::iterator_concept; };
2206 template<
typename _It>
2207 struct __counted_iter_cat
2210 template<
typename _It>
2211 requires requires {
typename _It::iterator_category; }
2212 struct __counted_iter_cat<_It>
2213 {
using iterator_category =
typename _It::iterator_category; };
2217 template<input_or_output_iterator _It>
2218 class counted_iterator
2219 :
public __detail::__counted_iter_value_type<_It>,
2220 public __detail::__counted_iter_concept<_It>,
2221 public __detail::__counted_iter_cat<_It>
2224 using iterator_type = _It;
2226 using difference_type = iter_difference_t<_It>;
2230 constexpr counted_iterator()
requires default_initializable<_It> = default;
2233 counted_iterator(_It __i, iter_difference_t<_It> __n)
2234 : _M_current(
std::move(__i)), _M_length(__n)
2235 { __glibcxx_assert(__n >= 0); }
2237 template<
typename _It2>
2238 requires convertible_to<const _It2&, _It>
2240 counted_iterator(
const counted_iterator<_It2>& __x)
2241 : _M_current(__x._M_current), _M_length(__x._M_length)
2244 template<
typename _It2>
2245 requires assignable_from<_It&, const _It2&>
2246 constexpr counted_iterator&
2247 operator=(
const counted_iterator<_It2>& __x)
2249 _M_current = __x._M_current;
2250 _M_length = __x._M_length;
2254 constexpr const _It&
2255 base() const & noexcept
2256 {
return _M_current; }
2260 noexcept(is_nothrow_move_constructible_v<_It>)
2263 constexpr iter_difference_t<_It>
2264 count() const noexcept {
return _M_length; }
2266 constexpr decltype(
auto)
2268 noexcept(
noexcept(*_M_current))
2270 __glibcxx_assert( _M_length > 0 );
2274 constexpr decltype(
auto)
2276 noexcept(
noexcept(*_M_current))
2277 requires __detail::__dereferenceable<const _It>
2279 __glibcxx_assert( _M_length > 0 );
2284 operator->() const noexcept
2285 requires contiguous_iterator<_It>
2286 {
return std::to_address(_M_current); }
2288 constexpr counted_iterator&
2291 __glibcxx_assert(_M_length > 0);
2297 constexpr decltype(
auto)
2300 __glibcxx_assert(_M_length > 0);
2304 return _M_current++;
2307 __throw_exception_again;
2311 constexpr counted_iterator
2312 operator++(
int)
requires forward_iterator<_It>
2319 constexpr counted_iterator&
2320 operator--()
requires bidirectional_iterator<_It>
2327 constexpr counted_iterator
2328 operator--(
int)
requires bidirectional_iterator<_It>
2335 constexpr counted_iterator
2336 operator+(iter_difference_t<_It> __n)
const
2337 requires random_access_iterator<_It>
2338 {
return counted_iterator(_M_current + __n, _M_length - __n); }
2340 friend constexpr counted_iterator
2341 operator+(iter_difference_t<_It> __n,
const counted_iterator& __x)
2342 requires random_access_iterator<_It>
2343 {
return __x + __n; }
2345 constexpr counted_iterator&
2346 operator+=(iter_difference_t<_It> __n)
2347 requires random_access_iterator<_It>
2349 __glibcxx_assert(__n <= _M_length);
2355 constexpr counted_iterator
2356 operator-(iter_difference_t<_It> __n)
const
2357 requires random_access_iterator<_It>
2358 {
return counted_iterator(_M_current - __n, _M_length + __n); }
2360 template<common_with<_It> _It2>
2361 friend constexpr iter_difference_t<_It2>
2363 const counted_iterator<_It2>& __y)
2364 {
return __y._M_length - __x._M_length; }
2366 friend constexpr iter_difference_t<_It>
2367 operator-(
const counted_iterator& __x, default_sentinel_t)
2368 {
return -__x._M_length; }
2370 friend constexpr iter_difference_t<_It>
2371 operator-(default_sentinel_t,
const counted_iterator& __y)
2372 {
return __y._M_length; }
2374 constexpr counted_iterator&
2375 operator-=(iter_difference_t<_It> __n)
2376 requires random_access_iterator<_It>
2378 __glibcxx_assert(-__n <= _M_length);
2384 constexpr decltype(
auto)
2385 operator[](iter_difference_t<_It> __n)
const
2386 noexcept(
noexcept(_M_current[__n]))
2387 requires random_access_iterator<_It>
2389 __glibcxx_assert(__n < _M_length);
2390 return _M_current[__n];
2393 template<common_with<_It> _It2>
2394 friend constexpr bool
2395 operator==(
const counted_iterator& __x,
2396 const counted_iterator<_It2>& __y)
2397 {
return __x._M_length == __y._M_length; }
2399 friend constexpr bool
2400 operator==(
const counted_iterator& __x, default_sentinel_t)
2401 {
return __x._M_length == 0; }
2403 template<common_with<_It> _It2>
2404 friend constexpr strong_ordering
2405 operator<=>(
const counted_iterator& __x,
2406 const counted_iterator<_It2>& __y)
2407 {
return __y._M_length <=> __x._M_length; }
2409 friend constexpr iter_rvalue_reference_t<_It>
2410 iter_move(
const counted_iterator& __i)
2411 noexcept(
noexcept(ranges::iter_move(__i._M_current)))
2412 requires input_iterator<_It>
2414 __glibcxx_assert( __i._M_length > 0 );
2415 return ranges::iter_move(__i._M_current);
2418 template<indirectly_swappable<_It> _It2>
2419 friend constexpr void
2420 iter_swap(
const counted_iterator& __x,
2421 const counted_iterator<_It2>& __y)
2422 noexcept(
noexcept(ranges::iter_swap(__x._M_current, __y._M_current)))
2424 __glibcxx_assert( __x._M_length > 0 && __y._M_length > 0 );
2425 ranges::iter_swap(__x._M_current, __y._M_current);
2429 template<input_or_output_iterator _It2>
friend class counted_iterator;
2431 _It _M_current = _It();
2432 iter_difference_t<_It> _M_length = 0;
2435 template<input_iterator _It>
2436 requires same_as<__detail::__iter_traits<_It>, iterator_traits<_It>>
2437 struct iterator_traits<counted_iterator<_It>> : iterator_traits<_It>
2439 using pointer = conditional_t<contiguous_iterator<_It>,
2440 add_pointer_t<iter_reference_t<_It>>,
2447 template<
typename _Iterator>
2448 _GLIBCXX20_CONSTEXPR
2450 __niter_base(move_iterator<_Iterator> __it)
2451 ->
decltype(make_move_iterator(__niter_base(__it.base())))
2452 {
return make_move_iterator(__niter_base(__it.base())); }
2454 template<
typename _Iterator>
2455 struct __is_move_iterator<move_iterator<_Iterator> >
2457 enum { __value = 1 };
2458 typedef __true_type __type;
2461 template<
typename _Iterator>
2462 _GLIBCXX20_CONSTEXPR
2464 __miter_base(move_iterator<_Iterator> __it)
2465 ->
decltype(__miter_base(__it.base()))
2466 {
return __miter_base(__it.base()); }
2468#define _GLIBCXX_MAKE_MOVE_ITERATOR(_Iter) std::make_move_iterator(_Iter)
2469#define _GLIBCXX_MAKE_MOVE_IF_NOEXCEPT_ITERATOR(_Iter) \
2470 std::__make_move_if_noexcept_iterator(_Iter)
2472#define _GLIBCXX_MAKE_MOVE_ITERATOR(_Iter) (_Iter)
2473#define _GLIBCXX_MAKE_MOVE_IF_NOEXCEPT_ITERATOR(_Iter) (_Iter)
2476#if __cpp_deduction_guides >= 201606
2479 template<
typename _InputIterator>
2481 typename iterator_traits<_InputIterator>::value_type::first_type>;
2483 template<
typename _InputIterator>
2484 using __iter_val_t =
2485 typename iterator_traits<_InputIterator>::value_type::second_type;
2487 template<
typename _T1,
typename _T2>
2490 template<
typename _InputIterator>
2491 using __iter_to_alloc_t =
2492 pair<add_const_t<__iter_key_t<_InputIterator>>,
2493 __iter_val_t<_InputIterator>>;
2496_GLIBCXX_END_NAMESPACE_VERSION
2499#ifdef _GLIBCXX_DEBUG
constexpr duration< __common_rep_t< _Rep2, _Rep1 >, _Period > operator*(const _Rep1 &__s, const duration< _Rep2, _Period > &__d)
constexpr time_point< _Clock, typename common_type< duration< _Rep1, _Period1 >, _Dur2 >::type > operator+(const duration< _Rep1, _Period1 > &__lhs, const time_point< _Clock, _Dur2 > &__rhs)
Adjust a time point forwards by the given duration.
constexpr common_type< duration< _Rep1, _Period1 >, duration< _Rep2, _Period2 > >::type operator-(const duration< _Rep1, _Period1 > &__lhs, const duration< _Rep2, _Period2 > &__rhs)
The difference between two durations.
constexpr complex< _Tp > operator*(const complex< _Tp > &__x, const complex< _Tp > &__y)
Return new complex value x times y.
constexpr complex< _Tp > operator-(const complex< _Tp > &__x, const complex< _Tp > &__y)
Return new complex value x minus y.
constexpr complex< _Tp > operator+(const complex< _Tp > &__x, const complex< _Tp > &__y)
Return new complex value x plus y.
typename conditional< _Cond, _Iftrue, _Iffalse >::type conditional_t
Alias template for conditional.
typename remove_const< _Tp >::type remove_const_t
Alias template for remove_const.
constexpr std::remove_reference< _Tp >::type && move(_Tp &&__t) noexcept
Convert a value to an rvalue.
constexpr _Tp * __addressof(_Tp &__r) noexcept
Same as C++11 std::addressof.
constexpr _Tp && forward(typename std::remove_reference< _Tp >::type &__t) noexcept
Forward an lvalue.
constexpr reverse_iterator< _Iterator > make_reverse_iterator(_Iterator __i)
Generator function for reverse_iterator.
insert_iterator< _Container > inserter(_Container &__x, typename _Container::iterator __i)
constexpr front_insert_iterator< _Container > front_inserter(_Container &__x)
constexpr back_insert_iterator< _Container > back_inserter(_Container &__x)
ISO C++ entities toplevel namespace is std.
GNU extensions for public use.
The bitset class represents a fixed-size sequence of bits.
Define a member typedef type to one of two argument types.
is_nothrow_copy_constructible
Traits class for iterators.
constexpr pointer operator->() const
constexpr reverse_iterator & operator-=(difference_type __n)
constexpr iterator_type base() const
constexpr reverse_iterator & operator+=(difference_type __n)
constexpr reverse_iterator operator+(difference_type __n) const
constexpr reverse_iterator(iterator_type __x)
constexpr reference operator[](difference_type __n) const
constexpr reverse_iterator & operator--()
constexpr reverse_iterator(const reverse_iterator &__x)
constexpr reverse_iterator(const reverse_iterator< _Iter > &__x)
constexpr reverse_iterator operator--(int)
constexpr reference operator*() const
constexpr reverse_iterator operator-(difference_type __n) const
constexpr reverse_iterator()
constexpr reverse_iterator operator++(int)
constexpr reverse_iterator & operator++()
Turns assignment into insertion.
constexpr back_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.
constexpr back_insert_iterator & operator++()
Simply returns *this. (This iterator does not move.)
constexpr back_insert_iterator & operator=(const typename _Container::value_type &__value)
constexpr back_insert_iterator(_Container &__x)
The only way to create this iterator is with a container.
constexpr back_insert_iterator & operator*()
Simply returns *this.
Turns assignment into insertion.
_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.)
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. (This iterator does not move.)
constexpr front_insert_iterator & operator*()
Simply returns *this.
constexpr front_insert_iterator & operator=(const typename _Container::value_type &__value)
Turns assignment into insertion.
constexpr insert_iterator & operator++(int)
Simply returns *this. (This iterator does not move.)
constexpr insert_iterator & operator*()
Simply returns *this.
_Container container_type
A nested typedef for the type of whatever container you used.
constexpr insert_iterator & operator=(const typename _Container::value_type &__value)
constexpr insert_iterator & operator++()
Simply returns *this. (This iterator does not move.)
constexpr insert_iterator(_Container &__x, _Iter __i)
Forward iterators support a superset of input iterator operations.
Bidirectional iterators support a superset of forward iterator operations.
Random-access iterators support a superset of bidirectional iterator operations.
iterator_traits< _Iterator >::iterator_category iterator_category
One of the tag types.
void difference_type
Distance between iterators is represented as this type.
iterator_traits< _Iterator >::value_type value_type
The type "pointed to" by the iterator.