60 #ifndef _STL_ITERATOR_H
61 #define _STL_ITERATOR_H 1
68 #if __cplusplus >= 201103L
72 #if __cplusplus > 201402L
73 # define __cpp_lib_array_constexpr 201803
76 #if __cplusplus > 201703L
81 namespace std _GLIBCXX_VISIBILITY(default)
83 _GLIBCXX_BEGIN_NAMESPACE_VERSION
109 template<
typename _Iterator>
111 :
public iterator<typename iterator_traits<_Iterator>::iterator_category,
112 typename iterator_traits<_Iterator>::value_type,
113 typename iterator_traits<_Iterator>::difference_type,
114 typename iterator_traits<_Iterator>::pointer,
115 typename iterator_traits<_Iterator>::reference>
123 typedef _Iterator iterator_type;
124 typedef typename __traits_type::difference_type difference_type;
125 typedef typename __traits_type::pointer pointer;
126 typedef typename __traits_type::reference reference;
141 explicit _GLIBCXX17_CONSTEXPR
149 : current(__x.current) { }
151 #if __cplusplus >= 201103L
159 template<
typename _Iter>
162 : current(__x.
base()) { }
167 _GLIBCXX17_CONSTEXPR iterator_type
181 _GLIBCXX17_CONSTEXPR reference
184 _Iterator __tmp = current;
193 _GLIBCXX17_CONSTEXPR pointer
195 #if __cplusplus > 201703L && defined __cpp_concepts
196 requires is_pointer_v<_Iterator>
197 || requires(
const _Iterator __i) { __i.operator->(); }
202 _Iterator __tmp = current;
204 return _S_to_pointer(__tmp);
306 _GLIBCXX17_CONSTEXPR reference
308 {
return *(*
this + __n); }
311 template<
typename _Tp>
312 static _GLIBCXX17_CONSTEXPR _Tp*
313 _S_to_pointer(_Tp* __p)
316 template<
typename _Tp>
317 static _GLIBCXX17_CONSTEXPR pointer
318 _S_to_pointer(_Tp __t)
319 {
return __t.operator->(); }
332 template<
typename _Iterator>
333 inline _GLIBCXX17_CONSTEXPR
bool
336 {
return __x.
base() == __y.
base(); }
338 template<
typename _Iterator>
339 inline _GLIBCXX17_CONSTEXPR
bool
340 operator<(
const reverse_iterator<_Iterator>& __x,
341 const reverse_iterator<_Iterator>& __y)
342 {
return __y.base() < __x.base(); }
344 template<
typename _Iterator>
345 inline _GLIBCXX17_CONSTEXPR
bool
346 operator!=(
const reverse_iterator<_Iterator>& __x,
347 const reverse_iterator<_Iterator>& __y)
348 {
return !(__x == __y); }
350 template<
typename _Iterator>
351 inline _GLIBCXX17_CONSTEXPR
bool
352 operator>(
const reverse_iterator<_Iterator>& __x,
353 const reverse_iterator<_Iterator>& __y)
354 {
return __y < __x; }
356 template<
typename _Iterator>
357 inline _GLIBCXX17_CONSTEXPR
bool
358 operator<=(
const reverse_iterator<_Iterator>& __x,
359 const reverse_iterator<_Iterator>& __y)
360 {
return !(__y < __x); }
362 template<
typename _Iterator>
363 inline _GLIBCXX17_CONSTEXPR
bool
364 operator>=(
const reverse_iterator<_Iterator>& __x,
365 const reverse_iterator<_Iterator>& __y)
366 {
return !(__x < __y); }
370 template<
typename _IteratorL,
typename _IteratorR>
371 inline _GLIBCXX17_CONSTEXPR
bool
372 operator==(
const reverse_iterator<_IteratorL>& __x,
373 const reverse_iterator<_IteratorR>& __y)
374 {
return __x.base() == __y.base(); }
376 template<
typename _IteratorL,
typename _IteratorR>
377 inline _GLIBCXX17_CONSTEXPR
bool
378 operator<(
const reverse_iterator<_IteratorL>& __x,
379 const reverse_iterator<_IteratorR>& __y)
380 {
return __y.base() < __x.base(); }
382 template<
typename _IteratorL,
typename _IteratorR>
383 inline _GLIBCXX17_CONSTEXPR
bool
384 operator!=(
const reverse_iterator<_IteratorL>& __x,
385 const reverse_iterator<_IteratorR>& __y)
386 {
return !(__x == __y); }
388 template<
typename _IteratorL,
typename _IteratorR>
389 inline _GLIBCXX17_CONSTEXPR
bool
390 operator>(
const reverse_iterator<_IteratorL>& __x,
391 const reverse_iterator<_IteratorR>& __y)
392 {
return __y < __x; }
394 template<
typename _IteratorL,
typename _IteratorR>
395 inline _GLIBCXX17_CONSTEXPR
bool
396 operator<=(
const reverse_iterator<_IteratorL>& __x,
397 const reverse_iterator<_IteratorR>& __y)
398 {
return !(__y < __x); }
400 template<
typename _IteratorL,
typename _IteratorR>
401 inline _GLIBCXX17_CONSTEXPR
bool
402 operator>=(
const reverse_iterator<_IteratorL>& __x,
403 const reverse_iterator<_IteratorR>& __y)
404 {
return !(__x < __y); }
407 #if __cplusplus < 201103L
408 template<
typename _Iterator>
409 inline typename reverse_iterator<_Iterator>::difference_type
410 operator-(
const reverse_iterator<_Iterator>& __x,
411 const reverse_iterator<_Iterator>& __y)
412 {
return __y.base() - __x.base(); }
414 template<
typename _IteratorL,
typename _IteratorR>
415 inline typename reverse_iterator<_IteratorL>::difference_type
416 operator-(
const reverse_iterator<_IteratorL>& __x,
417 const reverse_iterator<_IteratorR>& __y)
418 {
return __y.base() - __x.base(); }
422 template<
typename _IteratorL,
typename _IteratorR>
423 inline _GLIBCXX17_CONSTEXPR
auto
424 operator-(
const reverse_iterator<_IteratorL>& __x,
425 const reverse_iterator<_IteratorR>& __y)
426 -> decltype(__y.base() - __x.base())
427 {
return __y.base() - __x.base(); }
430 template<
typename _Iterator>
431 inline _GLIBCXX17_CONSTEXPR reverse_iterator<_Iterator>
432 operator+(
typename reverse_iterator<_Iterator>::difference_type __n,
433 const reverse_iterator<_Iterator>& __x)
434 {
return reverse_iterator<_Iterator>(__x.base() - __n); }
436 #if __cplusplus >= 201103L
438 template<
typename _Iterator>
439 inline _GLIBCXX17_CONSTEXPR reverse_iterator<_Iterator>
440 __make_reverse_iterator(_Iterator __i)
441 {
return reverse_iterator<_Iterator>(__i); }
443 # if __cplusplus >= 201402L
444 # define __cpp_lib_make_reverse_iterator 201402
449 template<
typename _Iterator>
450 inline _GLIBCXX17_CONSTEXPR reverse_iterator<_Iterator>
454 # if __cplusplus > 201703L && defined __cpp_lib_concepts
455 template<
typename _Iterator1,
typename _Iterator2>
456 requires (!sized_sentinel_for<_Iterator1, _Iterator2>)
457 inline constexpr
bool
458 disable_sized_sentinel_for<reverse_iterator<_Iterator1>,
459 reverse_iterator<_Iterator2>> =
true;
463 template<
typename _Iterator>
466 __niter_base(reverse_iterator<_Iterator> __it)
467 -> decltype(__make_reverse_iterator(__niter_base(__it.base())))
468 {
return __make_reverse_iterator(__niter_base(__it.base())); }
470 template<
typename _Iterator>
471 struct __is_move_iterator<reverse_iterator<_Iterator> >
472 : __is_move_iterator<_Iterator>
475 template<
typename _Iterator>
478 __miter_base(reverse_iterator<_Iterator> __it)
479 -> decltype(__make_reverse_iterator(__miter_base(__it.base())))
480 {
return __make_reverse_iterator(__miter_base(__it.base())); }
494 template<
typename _Container>
496 :
public iterator<output_iterator_tag, void, void, void, void>
499 #if __cplusplus <= 201703L
500 _Container* container;
502 _Container* container =
nullptr;
508 #if __cplusplus > 201703L
512 #if __cplusplus > 201703L
532 #if __cplusplus < 201103L
534 operator=(
typename _Container::const_reference __value)
536 container->push_back(__value);
541 operator=(
const typename _Container::value_type& __value)
543 container->push_back(__value);
548 operator=(
typename _Container::value_type&& __value)
550 container->push_back(
std::move(__value));
582 template<
typename _Container>
583 inline back_insert_iterator<_Container>
597 template<
typename _Container>
599 :
public iterator<output_iterator_tag, void, void, void, void>
602 #if __cplusplus <= 201703L
603 _Container* container;
605 _Container* container =
nullptr;
611 #if __cplusplus > 201703L
615 #if __cplusplus > 201703L
634 #if __cplusplus < 201103L
636 operator=(
typename _Container::const_reference __value)
638 container->push_front(__value);
643 operator=(
const typename _Container::value_type& __value)
645 container->push_front(__value);
650 operator=(
typename _Container::value_type&& __value)
652 container->push_front(
std::move(__value));
684 template<
typename _Container>
685 inline front_insert_iterator<_Container>
703 template<
typename _Container>
705 :
public iterator<output_iterator_tag, void, void, void, void>
708 _Container* container;
709 typename _Container::iterator iter;
745 #if __cplusplus < 201103L
747 operator=(
typename _Container::const_reference __value)
749 iter = container->insert(iter, __value);
755 operator=(
const typename _Container::value_type& __value)
757 iter = container->insert(iter, __value);
763 operator=(
typename _Container::value_type&& __value)
765 iter = container->insert(iter,
std::move(__value));
799 template<
typename _Container,
typename _Iterator>
800 inline insert_iterator<_Container>
804 typename _Container::iterator(__i));
809 _GLIBCXX_END_NAMESPACE_VERSION
812 namespace __gnu_cxx _GLIBCXX_VISIBILITY(default)
814 _GLIBCXX_BEGIN_NAMESPACE_VERSION
823 template<
typename _Iterator,
typename _Container>
824 class __normal_iterator
827 _Iterator _M_current;
832 typedef _Iterator iterator_type;
833 typedef typename __traits_type::iterator_category iterator_category;
834 typedef typename __traits_type::value_type value_type;
835 typedef typename __traits_type::difference_type difference_type;
836 typedef typename __traits_type::reference reference;
837 typedef typename __traits_type::pointer pointer;
839 #if __cplusplus > 201703L && __cpp_lib_concepts
840 using iterator_concept = std::__detail::__iter_concept<_Iterator>;
843 _GLIBCXX_CONSTEXPR __normal_iterator() _GLIBCXX_NOEXCEPT
844 : _M_current(_Iterator()) { }
846 explicit _GLIBCXX20_CONSTEXPR
847 __normal_iterator(
const _Iterator& __i) _GLIBCXX_NOEXCEPT
848 : _M_current(__i) { }
851 template<
typename _Iter>
853 __normal_iterator(
const __normal_iterator<_Iter,
854 typename __enable_if<
855 (std::__are_same<_Iter, typename _Container::pointer>::__value),
856 _Container>::__type>& __i) _GLIBCXX_NOEXCEPT
857 : _M_current(__i.base()) { }
863 {
return *_M_current; }
867 operator->() const _GLIBCXX_NOEXCEPT
868 {
return _M_current; }
872 operator++() _GLIBCXX_NOEXCEPT
880 operator++(
int) _GLIBCXX_NOEXCEPT
881 {
return __normal_iterator(_M_current++); }
886 operator--() _GLIBCXX_NOEXCEPT
894 operator--(
int) _GLIBCXX_NOEXCEPT
895 {
return __normal_iterator(_M_current--); }
900 operator[](difference_type __n)
const _GLIBCXX_NOEXCEPT
901 {
return _M_current[__n]; }
905 operator+=(difference_type __n) _GLIBCXX_NOEXCEPT
906 { _M_current += __n;
return *
this; }
910 operator+(difference_type __n)
const _GLIBCXX_NOEXCEPT
911 {
return __normal_iterator(_M_current + __n); }
915 operator-=(difference_type __n) _GLIBCXX_NOEXCEPT
916 { _M_current -= __n;
return *
this; }
920 operator-(difference_type __n)
const _GLIBCXX_NOEXCEPT
921 {
return __normal_iterator(_M_current - __n); }
925 base() const _GLIBCXX_NOEXCEPT
926 {
return _M_current; }
938 template<
typename _IteratorL,
typename _IteratorR,
typename _Container>
941 operator==(
const __normal_iterator<_IteratorL, _Container>& __lhs,
942 const __normal_iterator<_IteratorR, _Container>& __rhs)
944 {
return __lhs.base() == __rhs.base(); }
946 template<
typename _Iterator,
typename _Container>
949 operator==(
const __normal_iterator<_Iterator, _Container>& __lhs,
950 const __normal_iterator<_Iterator, _Container>& __rhs)
952 {
return __lhs.base() == __rhs.base(); }
954 template<
typename _IteratorL,
typename _IteratorR,
typename _Container>
957 operator!=(
const __normal_iterator<_IteratorL, _Container>& __lhs,
958 const __normal_iterator<_IteratorR, _Container>& __rhs)
960 {
return __lhs.base() != __rhs.base(); }
962 template<
typename _Iterator,
typename _Container>
965 operator!=(
const __normal_iterator<_Iterator, _Container>& __lhs,
966 const __normal_iterator<_Iterator, _Container>& __rhs)
968 {
return __lhs.base() != __rhs.base(); }
971 template<
typename _IteratorL,
typename _IteratorR,
typename _Container>
974 operator<(
const __normal_iterator<_IteratorL, _Container>& __lhs,
975 const __normal_iterator<_IteratorR, _Container>& __rhs)
977 {
return __lhs.base() < __rhs.base(); }
979 template<
typename _Iterator,
typename _Container>
982 operator<(
const __normal_iterator<_Iterator, _Container>& __lhs,
983 const __normal_iterator<_Iterator, _Container>& __rhs)
985 {
return __lhs.base() < __rhs.base(); }
987 template<
typename _IteratorL,
typename _IteratorR,
typename _Container>
990 operator>(
const __normal_iterator<_IteratorL, _Container>& __lhs,
991 const __normal_iterator<_IteratorR, _Container>& __rhs)
993 {
return __lhs.base() > __rhs.base(); }
995 template<
typename _Iterator,
typename _Container>
998 operator>(
const __normal_iterator<_Iterator, _Container>& __lhs,
999 const __normal_iterator<_Iterator, _Container>& __rhs)
1001 {
return __lhs.base() > __rhs.base(); }
1003 template<
typename _IteratorL,
typename _IteratorR,
typename _Container>
1004 _GLIBCXX20_CONSTEXPR
1006 operator<=(
const __normal_iterator<_IteratorL, _Container>& __lhs,
1007 const __normal_iterator<_IteratorR, _Container>& __rhs)
1009 {
return __lhs.base() <= __rhs.base(); }
1011 template<
typename _Iterator,
typename _Container>
1012 _GLIBCXX20_CONSTEXPR
1014 operator<=(
const __normal_iterator<_Iterator, _Container>& __lhs,
1015 const __normal_iterator<_Iterator, _Container>& __rhs)
1017 {
return __lhs.base() <= __rhs.base(); }
1019 template<
typename _IteratorL,
typename _IteratorR,
typename _Container>
1020 _GLIBCXX20_CONSTEXPR
1022 operator>=(
const __normal_iterator<_IteratorL, _Container>& __lhs,
1023 const __normal_iterator<_IteratorR, _Container>& __rhs)
1025 {
return __lhs.base() >= __rhs.base(); }
1027 template<
typename _Iterator,
typename _Container>
1028 _GLIBCXX20_CONSTEXPR
1030 operator>=(
const __normal_iterator<_Iterator, _Container>& __lhs,
1031 const __normal_iterator<_Iterator, _Container>& __rhs)
1033 {
return __lhs.base() >= __rhs.base(); }
1039 template<
typename _IteratorL,
typename _IteratorR,
typename _Container>
1040 #if __cplusplus >= 201103L
1042 _GLIBCXX20_CONSTEXPR
1044 operator-(
const __normal_iterator<_IteratorL, _Container>& __lhs,
1045 const __normal_iterator<_IteratorR, _Container>& __rhs) noexcept
1046 -> decltype(__lhs.base() - __rhs.base())
1048 inline typename __normal_iterator<_IteratorL, _Container>::difference_type
1049 operator-(
const __normal_iterator<_IteratorL, _Container>& __lhs,
1050 const __normal_iterator<_IteratorR, _Container>& __rhs)
1052 {
return __lhs.base() - __rhs.base(); }
1054 template<
typename _Iterator,
typename _Container>
1055 _GLIBCXX20_CONSTEXPR
1056 inline typename __normal_iterator<_Iterator, _Container>::difference_type
1057 operator-(
const __normal_iterator<_Iterator, _Container>& __lhs,
1058 const __normal_iterator<_Iterator, _Container>& __rhs)
1060 {
return __lhs.base() - __rhs.base(); }
1062 template<
typename _Iterator,
typename _Container>
1063 _GLIBCXX20_CONSTEXPR
1064 inline __normal_iterator<_Iterator, _Container>
1065 operator+(
typename __normal_iterator<_Iterator, _Container>::difference_type
1066 __n,
const __normal_iterator<_Iterator, _Container>& __i)
1068 {
return __normal_iterator<_Iterator, _Container>(__i.base() + __n); }
1070 _GLIBCXX_END_NAMESPACE_VERSION
1073 namespace std _GLIBCXX_VISIBILITY(default)
1075 _GLIBCXX_BEGIN_NAMESPACE_VERSION
1077 template<
typename _Iterator,
typename _Container>
1078 _GLIBCXX20_CONSTEXPR
1080 __niter_base(__gnu_cxx::__normal_iterator<_Iterator, _Container> __it)
1082 {
return __it.base(); }
1084 #if __cplusplus >= 201103L
1090 #if __cplusplus > 201703L && __cpp_lib_concepts
1091 template<semiregular _Sent>
1097 noexcept(is_nothrow_default_constructible_v<_Sent>)
1101 move_sentinel(_Sent __s)
1102 noexcept(is_nothrow_move_constructible_v<_Sent>)
1105 template<
typename _S2> requires convertible_to<const _S2&, _Sent>
1107 move_sentinel(
const move_sentinel<_S2>& __s)
1108 noexcept(is_nothrow_constructible_v<_Sent, const _S2&>)
1109 : _M_last(__s.base())
1112 template<
typename _S2> requires assignable_from<_Sent&, const _S2&>
1113 constexpr move_sentinel&
1114 operator=(
const move_sentinel<_S2>& __s)
1115 noexcept(is_nothrow_assignable_v<_Sent, const _S2&>)
1117 _M_last = __s.base();
1123 noexcept(is_nothrow_copy_constructible_v<_Sent>)
1134 template<
typename _Cat,
typename _Limit,
typename _Otherwise = _Cat>
1135 using __clamp_iter_cat
1136 = conditional_t<derived_from<_Cat, _Limit>, _Limit, _Otherwise>;
1149 template<
typename _Iterator>
1152 _Iterator _M_current;
1155 #if __cplusplus > 201703L && __cpp_lib_concepts
1156 using __base_cat =
typename __traits_type::iterator_category;
1158 using __base_ref =
typename __traits_type::reference;
1162 using iterator_type = _Iterator;
1164 #if __cplusplus > 201703L && __cpp_lib_concepts
1166 using iterator_category
1167 = __detail::__clamp_iter_cat<__base_cat, random_access_iterator_tag>;
1168 using value_type = iter_value_t<_Iterator>;
1169 using difference_type = iter_difference_t<_Iterator>;
1170 using pointer = _Iterator;
1171 using reference = iter_rvalue_reference_t<_Iterator>;
1173 typedef typename __traits_type::iterator_category iterator_category;
1174 typedef typename __traits_type::value_type value_type;
1175 typedef typename __traits_type::difference_type difference_type;
1177 typedef _Iterator pointer;
1181 typename remove_reference<__base_ref>::type&&,
1182 __base_ref>::type reference;
1185 _GLIBCXX17_CONSTEXPR
1189 explicit _GLIBCXX17_CONSTEXPR
1193 template<
typename _Iter>
1194 _GLIBCXX17_CONSTEXPR
1196 : _M_current(__i.base()) { }
1198 #if __cplusplus <= 201703L
1199 _GLIBCXX17_CONSTEXPR iterator_type
1201 {
return _M_current; }
1203 constexpr iterator_type
1205 #if __cpp_lib_concepts
1206 requires copy_constructible<iterator_type>
1208 {
return _M_current; }
1210 constexpr iterator_type
1215 _GLIBCXX17_CONSTEXPR reference
1217 {
return static_cast<reference
>(*_M_current); }
1219 _GLIBCXX17_CONSTEXPR pointer
1221 {
return _M_current; }
1254 operator+(difference_type __n)
const
1258 operator+=(difference_type __n)
1265 operator-(difference_type __n)
const
1269 operator-=(difference_type __n)
1275 _GLIBCXX17_CONSTEXPR reference
1276 operator[](difference_type __n)
const
1279 #if __cplusplus > 201703L && __cpp_lib_concepts
1280 template<sentinel_for<_Iterator> _Sent>
1281 friend constexpr
bool
1282 operator==(
const move_iterator& __x,
const move_sentinel<_Sent>& __y)
1283 {
return __x.base() == __y.base(); }
1285 template<sized_sentinel_for<_Iterator> _Sent>
1286 friend constexpr iter_difference_t<_Iterator>
1287 operator-(
const move_sentinel<_Sent>& __x,
const move_iterator& __y)
1288 {
return __x.base() - __y.base(); }
1290 template<sized_sentinel_for<_Iterator> _Sent>
1291 friend constexpr iter_difference_t<_Iterator>
1292 operator-(
const move_iterator& __x,
const move_sentinel<_Sent>& __y)
1293 {
return __x.base() - __y.base(); }
1295 friend constexpr iter_rvalue_reference_t<_Iterator>
1297 noexcept(noexcept(ranges::iter_move(__i._M_current)))
1298 {
return ranges::iter_move(__i._M_current); }
1300 template<indirectly_swappable<_Iterator> _Iter2>
1301 friend constexpr
void
1303 noexcept(noexcept(ranges::iter_swap(__x._M_current, __y._M_current)))
1304 {
return ranges::iter_swap(__x._M_current, __y._M_current); }
1311 template<
typename _IteratorL,
typename _IteratorR>
1312 inline _GLIBCXX17_CONSTEXPR
bool
1315 {
return __x.base() == __y.base(); }
1317 template<
typename _Iterator>
1318 inline _GLIBCXX17_CONSTEXPR
bool
1319 operator==(
const move_iterator<_Iterator>& __x,
1320 const move_iterator<_Iterator>& __y)
1321 {
return __x.base() == __y.base(); }
1323 template<
typename _IteratorL,
typename _IteratorR>
1324 inline _GLIBCXX17_CONSTEXPR
bool
1325 operator!=(
const move_iterator<_IteratorL>& __x,
1326 const move_iterator<_IteratorR>& __y)
1327 {
return !(__x == __y); }
1329 template<
typename _Iterator>
1330 inline _GLIBCXX17_CONSTEXPR
bool
1331 operator!=(
const move_iterator<_Iterator>& __x,
1332 const move_iterator<_Iterator>& __y)
1333 {
return !(__x == __y); }
1335 template<
typename _IteratorL,
typename _IteratorR>
1336 inline _GLIBCXX17_CONSTEXPR
bool
1337 operator<(
const move_iterator<_IteratorL>& __x,
1338 const move_iterator<_IteratorR>& __y)
1339 {
return __x.base() < __y.base(); }
1341 template<
typename _Iterator>
1342 inline _GLIBCXX17_CONSTEXPR
bool
1343 operator<(
const move_iterator<_Iterator>& __x,
1344 const move_iterator<_Iterator>& __y)
1345 {
return __x.base() < __y.base(); }
1347 template<
typename _IteratorL,
typename _IteratorR>
1348 inline _GLIBCXX17_CONSTEXPR
bool
1349 operator<=(
const move_iterator<_IteratorL>& __x,
1350 const move_iterator<_IteratorR>& __y)
1351 {
return !(__y < __x); }
1353 template<
typename _Iterator>
1354 inline _GLIBCXX17_CONSTEXPR
bool
1355 operator<=(
const move_iterator<_Iterator>& __x,
1356 const move_iterator<_Iterator>& __y)
1357 {
return !(__y < __x); }
1359 template<
typename _IteratorL,
typename _IteratorR>
1360 inline _GLIBCXX17_CONSTEXPR
bool
1361 operator>(
const move_iterator<_IteratorL>& __x,
1362 const move_iterator<_IteratorR>& __y)
1363 {
return __y < __x; }
1365 template<
typename _Iterator>
1366 inline _GLIBCXX17_CONSTEXPR
bool
1367 operator>(
const move_iterator<_Iterator>& __x,
1368 const move_iterator<_Iterator>& __y)
1369 {
return __y < __x; }
1371 template<
typename _IteratorL,
typename _IteratorR>
1372 inline _GLIBCXX17_CONSTEXPR
bool
1373 operator>=(
const move_iterator<_IteratorL>& __x,
1374 const move_iterator<_IteratorR>& __y)
1375 {
return !(__x < __y); }
1377 template<
typename _Iterator>
1378 inline _GLIBCXX17_CONSTEXPR
bool
1379 operator>=(
const move_iterator<_Iterator>& __x,
1380 const move_iterator<_Iterator>& __y)
1381 {
return !(__x < __y); }
1384 template<
typename _IteratorL,
typename _IteratorR>
1385 inline _GLIBCXX17_CONSTEXPR
auto
1386 operator-(
const move_iterator<_IteratorL>& __x,
1387 const move_iterator<_IteratorR>& __y)
1388 -> decltype(__x.base() - __y.base())
1389 {
return __x.base() - __y.base(); }
1391 template<
typename _Iterator>
1392 inline _GLIBCXX17_CONSTEXPR move_iterator<_Iterator>
1393 operator+(
typename move_iterator<_Iterator>::difference_type __n,
1394 const move_iterator<_Iterator>& __x)
1395 {
return __x + __n; }
1397 template<
typename _Iterator>
1398 inline _GLIBCXX17_CONSTEXPR move_iterator<_Iterator>
1399 make_move_iterator(_Iterator __i)
1400 {
return move_iterator<_Iterator>(
std::move(__i)); }
1402 template<
typename _Iterator,
typename _ReturnType
1403 =
typename conditional<__move_if_noexcept_cond
1404 <
typename iterator_traits<_Iterator>::value_type>::value,
1405 _Iterator, move_iterator<_Iterator>>::type>
1406 inline _GLIBCXX17_CONSTEXPR _ReturnType
1407 __make_move_if_noexcept_iterator(_Iterator __i)
1408 {
return _ReturnType(__i); }
1412 template<
typename _Tp,
typename _ReturnType
1413 =
typename conditional<__move_if_noexcept_cond<_Tp>::value,
1414 const _Tp*, move_iterator<_Tp*>>::type>
1415 inline _GLIBCXX17_CONSTEXPR _ReturnType
1416 __make_move_if_noexcept_iterator(_Tp* __i)
1417 {
return _ReturnType(__i); }
1419 #if __cplusplus > 201703L && __cpp_lib_concepts
1424 template<input_or_output_iterator _It>
1425 class _Common_iter_proxy
1427 iter_value_t<_It> _M_keep;
1429 _Common_iter_proxy(iter_reference_t<_It>&& __x)
1432 template<
typename _Iter,
typename _Sent>
1433 friend class common_iterator;
1436 const iter_value_t<_It>*
1441 template<
typename _It>
1442 concept __common_iter_has_arrow = indirectly_readable<const _It>
1443 && (requires(
const _It& __it) { __it.operator->(); }
1444 || is_reference_v<iter_reference_t<_It>>
1445 || constructible_from<iter_value_t<_It>, iter_reference_t<_It>>);
1450 template<input_or_output_iterator _It, sentinel_for<_It> _Sent>
1451 requires (!same_as<_It, _Sent>) && copyable<_It>
1452 class common_iterator
1454 template<
typename _Tp,
typename _Up>
1455 static constexpr
bool
1458 if constexpr (is_trivially_default_constructible_v<_Tp>)
1459 return is_nothrow_assignable_v<_Tp, _Up>;
1461 return is_nothrow_constructible_v<_Tp, _Up>;
1464 template<
typename _It2,
typename _Sent2>
1465 static constexpr
bool
1467 {
return _S_noexcept1<_It, _It2>() && _S_noexcept1<_Sent, _Sent2>(); }
1472 noexcept(is_nothrow_default_constructible_v<_It>)
1473 : _M_it(), _M_index(0)
1477 common_iterator(_It __i)
1478 noexcept(is_nothrow_move_constructible_v<_It>)
1479 : _M_it(
std::
move(__i)), _M_index(0)
1483 common_iterator(_Sent __s)
1484 noexcept(is_nothrow_move_constructible_v<_Sent>)
1485 : _M_sent(
std::
move(__s)), _M_index(1)
1488 template<
typename _It2,
typename _Sent2>
1489 requires convertible_to<const _It2&, _It>
1490 && convertible_to<const _Sent2&, _Sent>
1492 common_iterator(
const common_iterator<_It2, _Sent2>& __x)
1493 noexcept(_S_noexcept<const _It2&, const _Sent2&>())
1494 : _M_valueless(), _M_index(__x._M_index)
1498 if constexpr (is_trivially_default_constructible_v<_It>)
1503 else if (_M_index == 1)
1505 if constexpr (is_trivially_default_constructible_v<_Sent>)
1513 common_iterator(
const common_iterator& __x)
1514 noexcept(_S_noexcept<const _It&, const _Sent&>())
1515 : _M_valueless(), _M_index(__x._M_index)
1519 if constexpr (is_trivially_default_constructible_v<_It>)
1524 else if (_M_index == 1)
1526 if constexpr (is_trivially_default_constructible_v<_Sent>)
1534 operator=(
const common_iterator& __x)
1535 noexcept(is_nothrow_copy_assignable_v<_It>
1536 && is_nothrow_copy_assignable_v<_Sent>
1537 && is_nothrow_copy_constructible_v<_It>
1538 && is_nothrow_copy_constructible_v<_Sent>)
1540 return this->
operator=<_It, _Sent>(__x);
1543 template<
typename _It2,
typename _Sent2>
1544 requires convertible_to<const _It2&, _It>
1545 && convertible_to<const _Sent2&, _Sent>
1546 && assignable_from<_It&, const _It2&>
1547 && assignable_from<_Sent&, const _Sent2&>
1549 operator=(
const common_iterator<_It2, _Sent2>& __x)
1550 noexcept(is_nothrow_constructible_v<_It, const _It2&>
1551 && is_nothrow_constructible_v<_Sent, const _Sent2&>
1552 && is_nothrow_assignable_v<_It, const _It2&>
1553 && is_nothrow_assignable_v<_Sent, const _Sent2&>)
1555 switch(_M_index << 2 | __x._M_index)
1561 _M_sent = __x._M_sent;
1580 __glibcxx_assert(__x._M_has_value());
1581 __builtin_unreachable();
1602 __glibcxx_assert(_M_index == 0);
1607 operator*() const requires __detail::__dereferenceable<const _It>
1609 __glibcxx_assert(_M_index == 0);
1614 operator->() const requires __detail::__common_iter_has_arrow<_It>
1616 __glibcxx_assert(_M_index == 0);
1617 if constexpr (is_pointer_v<_It> || requires { _M_it.operator->(); })
1619 else if constexpr (is_reference_v<iter_reference_t<_It>>)
1621 auto&& __tmp = *_M_it;
1625 return _Common_iter_proxy(*_M_it);
1631 __glibcxx_assert(_M_index == 0);
1639 __glibcxx_assert(_M_index == 0);
1640 if constexpr (forward_iterator<_It>)
1642 common_iterator __tmp = *
this;
1650 template<
typename _It2, sentinel_for<_It> _Sent2>
1651 requires sentinel_for<_Sent, _It2>
1653 operator==(
const common_iterator& __x,
1654 const common_iterator<_It2, _Sent2>& __y)
1656 switch(__x._M_index << 2 | __y._M_index)
1662 return __x._M_it == __y._M_sent;
1664 return __x._M_sent == __y._M_it;
1666 __glibcxx_assert(__x._M_has_value());
1667 __glibcxx_assert(__y._M_has_value());
1668 __builtin_unreachable();
1672 template<
typename _It2, sentinel_for<_It> _Sent2>
1673 requires sentinel_for<_Sent, _It2> && equality_comparable_with<_It, _It2>
1675 operator==(
const common_iterator& __x,
1676 const common_iterator<_It2, _Sent2>& __y)
1678 switch(__x._M_index << 2 | __y._M_index)
1683 return __x._M_it == __y._M_it;
1685 return __x._M_it == __y._M_sent;
1687 return __x._M_sent == __y._M_it;
1689 __glibcxx_assert(__x._M_has_value());
1690 __glibcxx_assert(__y._M_has_value());
1691 __builtin_unreachable();
1695 template<sized_sentinel_for<_It> _It2, sized_sentinel_for<_It> _Sent2>
1696 requires sized_sentinel_for<_Sent, _It2>
1697 friend iter_difference_t<_It2>
1699 const common_iterator<_It2, _Sent2>& __y)
1701 switch(__x._M_index << 2 | __y._M_index)
1706 return __x._M_it - __y._M_it;
1708 return __x._M_it - __y._M_sent;
1710 return __x._M_sent - __y._M_it;
1712 __glibcxx_assert(__x._M_has_value());
1713 __glibcxx_assert(__y._M_has_value());
1714 __builtin_unreachable();
1718 friend iter_rvalue_reference_t<_It>
1719 iter_move(
const common_iterator& __i)
1720 noexcept(noexcept(ranges::iter_move(std::declval<const _It&>())))
1721 requires input_iterator<_It>
1723 __glibcxx_assert(__i._M_index == 0);
1724 return ranges::iter_move(__i._M_it);
1727 template<indirectly_swappable<_It> _It2,
typename _Sent2>
1729 iter_swap(
const common_iterator& __x,
1730 const common_iterator<_It2, _Sent2>& __y)
1731 noexcept(noexcept(ranges::iter_swap(std::declval<const _It&>(),
1732 std::declval<const _It2&>())))
1734 __glibcxx_assert(__x._M_index == 0);
1735 __glibcxx_assert(__y._M_index == 0);
1736 return ranges::iter_swap(__x._M_it, __y._M_it);
1740 template<input_or_output_iterator _It2, sentinel_for<_It2> _Sent2>
1741 friend class common_iterator;
1743 bool _M_has_value() const noexcept {
return _M_index < 2; }
1749 unsigned char _M_valueless;
1751 unsigned char _M_index;
1754 template<
typename _It,
typename _Sent>
1755 struct incrementable_traits<common_iterator<_It, _Sent>>
1757 using difference_type = iter_difference_t<_It>;
1763 template<
typename _It,
typename _Sent>
1764 struct __common_iter_ptr
1769 template<
typename _It,
typename _Sent>
1770 requires __detail::__common_iter_has_arrow<_It>
1771 struct __common_iter_ptr<_It, _Sent>
1773 using common_iterator = std::common_iterator<_It, _Sent>;
1776 = decltype(std::declval<const common_iterator&>().operator->());
1780 template<input_iterator _It,
typename _Sent>
1781 struct iterator_traits<common_iterator<_It, _Sent>>
1783 using iterator_concept = conditional_t<forward_iterator<_It>,
1784 forward_iterator_tag, input_iterator_tag>;
1785 using iterator_category = __detail::__clamp_iter_cat<
1786 typename iterator_traits<_It>::iterator_category,
1787 forward_iterator_tag, input_iterator_tag>;
1788 using value_type = iter_value_t<_It>;
1789 using difference_type = iter_difference_t<_It>;
1790 using pointer =
typename __detail::__common_iter_ptr<_It, _Sent>::type;
1791 using reference = iter_reference_t<_It>;
1797 template<input_or_output_iterator _It>
1798 class counted_iterator
1801 using iterator_type = _It;
1803 constexpr counted_iterator() =
default;
1806 counted_iterator(_It __i, iter_difference_t<_It> __n)
1807 : _M_current(
std::
move(__i)), _M_length(__n)
1808 { __glibcxx_assert(__n >= 0); }
1810 template<
typename _It2>
1811 requires convertible_to<const _It2&, _It>
1813 counted_iterator(
const counted_iterator<_It2>& __x)
1814 : _M_current(__x._M_current), _M_length(__x._M_length)
1817 template<
typename _It2>
1818 requires assignable_from<_It&, const _It2&>
1819 constexpr counted_iterator&
1820 operator=(
const counted_iterator<_It2>& __x)
1822 _M_current = __x._M_current;
1823 _M_length = __x._M_length;
1829 noexcept(is_nothrow_copy_constructible_v<_It>)
1830 requires copy_constructible<_It>
1831 {
return _M_current; }
1835 noexcept(is_nothrow_move_constructible_v<_It>)
1838 constexpr iter_difference_t<_It>
1839 count() const noexcept {
return _M_length; }
1841 constexpr decltype(
auto)
1843 noexcept(noexcept(*_M_current))
1844 {
return *_M_current; }
1846 constexpr decltype(
auto)
1848 noexcept(noexcept(*_M_current))
1849 requires __detail::__dereferenceable<const _It>
1850 {
return *_M_current; }
1852 constexpr counted_iterator&
1855 __glibcxx_assert(_M_length > 0);
1864 __glibcxx_assert(_M_length > 0);
1868 return _M_current++;
1876 constexpr counted_iterator
1877 operator++(
int) requires forward_iterator<_It>
1884 constexpr counted_iterator&
1885 operator--() requires bidirectional_iterator<_It>
1892 constexpr counted_iterator
1893 operator--(
int) requires bidirectional_iterator<_It>
1900 constexpr counted_iterator
1901 operator+(iter_difference_t<_It> __n)
const
1902 requires random_access_iterator<_It>
1903 {
return counted_iterator(_M_current + __n, _M_length - __n); }
1905 friend constexpr counted_iterator
1906 operator+(iter_difference_t<_It> __n,
const counted_iterator& __x)
1907 requires random_access_iterator<_It>
1908 {
return __x + __n; }
1910 constexpr counted_iterator&
1911 operator+=(iter_difference_t<_It> __n)
1912 requires random_access_iterator<_It>
1914 __glibcxx_assert(__n <= _M_length);
1920 constexpr counted_iterator
1921 operator-(iter_difference_t<_It> __n)
const
1922 requires random_access_iterator<_It>
1923 {
return counted_iterator(_M_current - __n, _M_length + __n); }
1925 template<common_with<_It> _It2>
1926 friend constexpr iter_difference_t<_It2>
1928 const counted_iterator<_It2>& __y)
1929 {
return __y._M_length - __x._M_length; }
1931 friend constexpr iter_difference_t<_It>
1932 operator-(
const counted_iterator& __x, default_sentinel_t)
1933 {
return -__x._M_length; }
1935 friend constexpr iter_difference_t<_It>
1936 operator-(default_sentinel_t,
const counted_iterator& __y)
1937 {
return __y._M_length; }
1939 constexpr counted_iterator&
1940 operator-=(iter_difference_t<_It> __n)
1941 requires random_access_iterator<_It>
1943 __glibcxx_assert(-__n <= _M_length);
1949 constexpr decltype(
auto)
1950 operator[](iter_difference_t<_It> __n) const
1951 noexcept(noexcept(_M_current[__n]))
1952 requires random_access_iterator<_It>
1954 __glibcxx_assert(__n < _M_length);
1955 return _M_current[__n];
1958 template<common_with<_It> _It2>
1959 friend constexpr
bool
1960 operator==(
const counted_iterator& __x,
1961 const counted_iterator<_It2>& __y)
1962 {
return __x._M_length == __y._M_length; }
1964 friend constexpr
bool
1965 operator==(
const counted_iterator& __x, default_sentinel_t)
1966 {
return __x._M_length == 0; }
1968 template<common_with<_It> _It2>
1969 friend constexpr strong_ordering
1970 operator<=>(
const counted_iterator& __x,
1971 const counted_iterator<_It2>& __y)
1972 {
return __y._M_length <=> __x._M_length; }
1974 friend constexpr iter_rvalue_reference_t<_It>
1975 iter_move(
const counted_iterator& __i)
1976 noexcept(noexcept(ranges::iter_move(__i._M_current)))
1977 requires input_iterator<_It>
1978 {
return ranges::iter_move(__i._M_current); }
1980 template<indirectly_swappable<_It> _It2>
1981 friend constexpr
void
1982 iter_swap(
const counted_iterator& __x,
1983 const counted_iterator<_It2>& __y)
1984 noexcept(noexcept(ranges::iter_swap(__x._M_current, __y._M_current)))
1985 { ranges::iter_swap(__x._M_current, __y._M_current); }
1988 template<input_or_output_iterator _It2>
friend class counted_iterator;
1990 _It _M_current = _It();
1991 iter_difference_t<_It> _M_length = 0;
1994 template<
typename _It>
1995 struct incrementable_traits<counted_iterator<_It>>
1997 using difference_type = iter_difference_t<_It>;
2000 template<input_iterator _It>
2001 struct iterator_traits<counted_iterator<_It>> : iterator_traits<_It>
2003 using pointer = void;
2009 template<
typename _Iterator>
2011 __niter_base(move_iterator<_Iterator> __it)
2012 -> decltype(make_move_iterator(__niter_base(__it.base())))
2013 {
return make_move_iterator(__niter_base(__it.base())); }
2015 template<
typename _Iterator>
2016 struct __is_move_iterator<move_iterator<_Iterator> >
2018 enum { __value = 1 };
2019 typedef __true_type __type;
2022 template<
typename _Iterator>
2024 __miter_base(move_iterator<_Iterator> __it)
2025 -> decltype(__miter_base(__it.base()))
2026 {
return __miter_base(__it.base()); }
2028 #define _GLIBCXX_MAKE_MOVE_ITERATOR(_Iter) std::make_move_iterator(_Iter)
2029 #define _GLIBCXX_MAKE_MOVE_IF_NOEXCEPT_ITERATOR(_Iter) \
2030 std::__make_move_if_noexcept_iterator(_Iter)
2032 #define _GLIBCXX_MAKE_MOVE_ITERATOR(_Iter) (_Iter)
2033 #define _GLIBCXX_MAKE_MOVE_IF_NOEXCEPT_ITERATOR(_Iter) (_Iter)
2036 #if __cpp_deduction_guides >= 201606
2039 template<
typename _InputIterator>
2041 typename iterator_traits<_InputIterator>::value_type::first_type>;
2043 template<
typename _InputIterator>
2044 using __iter_val_t =
2045 typename iterator_traits<_InputIterator>::value_type::second_type;
2047 template<
typename _T1,
typename _T2>
2050 template<
typename _InputIterator>
2051 using __iter_to_alloc_t =
2052 pair<add_const_t<__iter_key_t<_InputIterator>>,
2053 __iter_val_t<_InputIterator>>;
2054 #endif // __cpp_deduction_guides
2056 _GLIBCXX_END_NAMESPACE_VERSION
2059 #ifdef _GLIBCXX_DEBUG