30 #ifndef _GLIBCXX_RANGE_ACCESS_H
31 #define _GLIBCXX_RANGE_ACCESS_H 1
33 #pragma GCC system_header
35 #if __cplusplus >= 201103L
40 namespace std _GLIBCXX_VISIBILITY(default)
42 _GLIBCXX_BEGIN_NAMESPACE_VERSION
49 template<
typename _Container>
50 inline _GLIBCXX17_CONSTEXPR
auto
51 begin(_Container& __cont) -> decltype(__cont.begin())
52 {
return __cont.begin(); }
59 template<
typename _Container>
60 inline _GLIBCXX17_CONSTEXPR
auto
61 begin(
const _Container& __cont) -> decltype(__cont.begin())
62 {
return __cont.begin(); }
69 template<
typename _Container>
70 inline _GLIBCXX17_CONSTEXPR
auto
71 end(_Container& __cont) -> decltype(__cont.end())
72 {
return __cont.end(); }
79 template<
typename _Container>
80 inline _GLIBCXX17_CONSTEXPR
auto
81 end(
const _Container& __cont) -> decltype(__cont.end())
82 {
return __cont.end(); }
88 template<
typename _Tp,
size_t _Nm>
89 inline _GLIBCXX14_CONSTEXPR _Tp*
90 begin(_Tp (&__arr)[_Nm]) noexcept
98 template<
typename _Tp,
size_t _Nm>
99 inline _GLIBCXX14_CONSTEXPR _Tp*
100 end(_Tp (&__arr)[_Nm]) noexcept
101 {
return __arr + _Nm; }
103 #if __cplusplus >= 201402L
105 template<
typename _Tp>
class valarray;
107 template<
typename _Tp> _Tp*
begin(valarray<_Tp>&);
108 template<
typename _Tp>
const _Tp*
begin(
const valarray<_Tp>&);
109 template<
typename _Tp> _Tp*
end(valarray<_Tp>&);
110 template<
typename _Tp>
const _Tp*
end(
const valarray<_Tp>&);
117 template<
typename _Container>
118 inline constexpr
auto
128 template<
typename _Container>
129 inline constexpr
auto
139 template<
typename _Container>
140 inline _GLIBCXX17_CONSTEXPR
auto
141 rbegin(_Container& __cont) -> decltype(__cont.rbegin())
142 {
return __cont.rbegin(); }
149 template<
typename _Container>
150 inline _GLIBCXX17_CONSTEXPR
auto
151 rbegin(
const _Container& __cont) -> decltype(__cont.rbegin())
152 {
return __cont.rbegin(); }
159 template<
typename _Container>
160 inline _GLIBCXX17_CONSTEXPR
auto
161 rend(_Container& __cont) -> decltype(__cont.rend())
162 {
return __cont.rend(); }
169 template<
typename _Container>
170 inline _GLIBCXX17_CONSTEXPR
auto
171 rend(
const _Container& __cont) -> decltype(__cont.rend())
172 {
return __cont.rend(); }
179 template<
typename _Tp,
size_t _Nm>
180 inline _GLIBCXX17_CONSTEXPR reverse_iterator<_Tp*>
189 template<
typename _Tp,
size_t _Nm>
190 inline _GLIBCXX17_CONSTEXPR reverse_iterator<_Tp*>
191 rend(_Tp (&__arr)[_Nm]) noexcept
199 template<
typename _Tp>
200 inline _GLIBCXX17_CONSTEXPR reverse_iterator<const _Tp*>
209 template<
typename _Tp>
210 inline _GLIBCXX17_CONSTEXPR reverse_iterator<const _Tp*>
219 template<
typename _Container>
220 inline _GLIBCXX17_CONSTEXPR
auto
229 template<
typename _Container>
230 inline _GLIBCXX17_CONSTEXPR
auto
236 #if __cplusplus >= 201703L
237 #define __cpp_lib_nonmember_container_access 201411
243 template <
typename _Container>
245 size(
const _Container& __cont) noexcept(noexcept(__cont.size()))
246 -> decltype(__cont.size())
247 {
return __cont.size(); }
252 template <
typename _Tp,
size_t _Nm>
254 size(
const _Tp (&)[_Nm]) noexcept
261 template <
typename _Container>
262 [[nodiscard]] constexpr
auto
263 empty(
const _Container& __cont) noexcept(noexcept(__cont.empty()))
264 -> decltype(__cont.empty())
265 {
return __cont.empty(); }
270 template <
typename _Tp,
size_t _Nm>
271 [[nodiscard]] constexpr
bool
272 empty(
const _Tp (&)[_Nm]) noexcept
279 template <
typename _Tp>
280 [[nodiscard]] constexpr
bool
281 empty(initializer_list<_Tp> __il) noexcept
282 {
return __il.size() == 0;}
288 template <
typename _Container>
290 data(_Container& __cont) noexcept(noexcept(__cont.data()))
291 -> decltype(__cont.data())
292 {
return __cont.data(); }
298 template <
typename _Container>
300 data(
const _Container& __cont) noexcept(noexcept(__cont.data()))
301 -> decltype(__cont.data())
302 {
return __cont.data(); }
308 template <
typename _Tp,
size_t _Nm>
310 data(_Tp (&__array)[_Nm]) noexcept
317 template <
typename _Tp>
319 data(initializer_list<_Tp> __il) noexcept
320 {
return __il.begin(); }
324 #if __cplusplus > 201703L
325 #define __cpp_lib_ssize 201902L
326 template<
typename _Container>
328 ssize(
const _Container& __cont)
329 noexcept(noexcept(__cont.size()))
333 return static_cast<common_type_t<ptrdiff_t, type>
>(__cont.size());
336 template<
typename _Tp, ptrdiff_t _Num>
338 ssize(
const _Tp (&)[_Num]) noexcept
341 #ifdef __cpp_lib_concepts
345 inline constexpr
bool disable_sized_range =
false;
347 template<
typename _Tp>
348 inline constexpr
bool enable_borrowed_range =
false;
350 template<
typename _Tp>
351 extern const bool enable_view;
355 template<
integral _Tp>
357 __to_unsigned_like(_Tp __t) noexcept
358 {
return static_cast<make_unsigned_t<_Tp>
>(__t); }
360 #if defined __STRICT_ANSI__ && defined __SIZEOF_INT128__
361 constexpr
unsigned __int128
362 __to_unsigned_like(__int128 __t) noexcept
365 constexpr
unsigned __int128
366 __to_unsigned_like(
unsigned __int128 __t) noexcept
370 template<
typename _Tp>
371 using __make_unsigned_like_t
372 = decltype(__detail::__to_unsigned_like(std::declval<_Tp>()));
375 template<
typename _Tp>
376 concept __maybe_borrowed_range
377 = is_lvalue_reference_v<_Tp>
378 || enable_borrowed_range<remove_cvref_t<_Tp>>;
382 namespace __cust_access
384 using std::ranges::__detail::__maybe_borrowed_range;
385 using std::__detail::__class_or_enum;
386 using std::__detail::__decay_copy;
387 using std::__detail::__member_begin;
388 using std::__detail::__adl_begin;
393 template<
typename _Tp>
394 static constexpr
bool
397 if constexpr (is_array_v<remove_reference_t<_Tp>>)
399 else if constexpr (__member_begin<_Tp>)
400 return noexcept(__decay_copy(
std::declval<_Tp&>().
begin()));
402 return noexcept(__decay_copy(
begin(
std::declval<_Tp&>())));
406 template<__maybe_borrowed_range _Tp>
410 operator()(_Tp&& __t) const noexcept(_S_noexcept<_Tp>())
412 if constexpr (is_array_v<remove_reference_t<_Tp>>)
414 static_assert(is_lvalue_reference_v<_Tp>);
415 using _Up = remove_all_extents_t<remove_reference_t<_Tp>>;
416 static_assert(
sizeof(_Up) != 0,
"not array of incomplete type");
419 else if constexpr (__member_begin<_Tp>)
426 template<
typename _Tp>
427 concept __member_end = requires(_Tp& __t)
429 { __decay_copy(__t.end()) }
430 -> sentinel_for<decltype(_Begin{}(std::forward<_Tp>(__t)))>;
433 void end(
auto&) =
delete;
434 void end(
const auto&) =
delete;
436 template<
typename _Tp>
437 concept __adl_end = __class_or_enum<remove_reference_t<_Tp>>
438 && requires(_Tp& __t)
440 { __decay_copy(
end(__t)) }
441 -> sentinel_for<decltype(_Begin{}(std::forward<_Tp>(__t)))>;
447 template<
typename _Tp>
448 static constexpr
bool
451 if constexpr (is_bounded_array_v<remove_reference_t<_Tp>>)
453 else if constexpr (__member_end<_Tp>)
454 return noexcept(__decay_copy(
std::declval<_Tp&>().
end()));
456 return noexcept(__decay_copy(
end(
std::declval<_Tp&>())));
460 template<__maybe_borrowed_range _Tp>
464 operator()(_Tp&& __t) const noexcept(_S_noexcept<_Tp>())
466 if constexpr (is_bounded_array_v<remove_reference_t<_Tp>>)
468 static_assert(is_lvalue_reference_v<_Tp>);
469 return __t + extent_v<remove_reference_t<_Tp>>;
471 else if constexpr (__member_end<_Tp>)
478 template<
typename _Tp>
479 constexpr decltype(
auto)
480 __as_const(_Tp&& __t) noexcept
482 if constexpr (is_lvalue_reference_v<_Tp>)
483 return static_cast<const remove_reference_t<_Tp>&
>(__t);
485 return static_cast<const _Tp&&
>(__t);
490 template<
typename _Tp>
492 operator()(_Tp&& __e)
const
493 noexcept(noexcept(_Begin{}(__cust_access::__as_const((_Tp&&)__e))))
494 requires requires { _Begin{}(__cust_access::__as_const((_Tp&&)__e)); }
496 return _Begin{}(__cust_access::__as_const(std::forward<_Tp>(__e)));
502 template<
typename _Tp>
504 operator()(_Tp&& __e)
const
505 noexcept(noexcept(_End{}(__cust_access::__as_const((_Tp&&)__e))))
506 requires requires { _End{}(__cust_access::__as_const((_Tp&&)__e)); }
508 return _End{}(__cust_access::__as_const(std::forward<_Tp>(__e)));
512 template<
typename _Tp>
513 concept __member_rbegin = requires(_Tp& __t)
515 { __decay_copy(__t.rbegin()) } -> input_or_output_iterator;
518 void rbegin(
auto&) =
delete;
519 void rbegin(
const auto&) =
delete;
521 template<
typename _Tp>
522 concept __adl_rbegin = __class_or_enum<remove_reference_t<_Tp>>
523 && requires(_Tp& __t)
525 { __decay_copy(
rbegin(__t)) } -> input_or_output_iterator;
528 template<
typename _Tp>
529 concept __reversable = requires(_Tp& __t)
531 { _Begin{}(__t) } -> bidirectional_iterator;
532 { _End{}(__t) } -> same_as<decltype(_Begin{}(__t))>;
538 template<
typename _Tp>
539 static constexpr
bool
542 if constexpr (__member_rbegin<_Tp>)
543 return noexcept(__decay_copy(std::declval<_Tp&>().
rbegin()));
544 else if constexpr (__adl_rbegin<_Tp>)
545 return noexcept(__decay_copy(
rbegin(std::declval<_Tp&>())));
548 if constexpr (noexcept(_End{}(std::declval<_Tp&>())))
550 using _It = decltype(_End{}(std::declval<_Tp&>()));
552 return is_nothrow_copy_constructible_v<_It>;
560 template<__maybe_borrowed_range _Tp>
561 requires __member_rbegin<_Tp> || __adl_rbegin<_Tp> || __reversable<_Tp>
563 operator()(_Tp&& __t)
const
564 noexcept(_S_noexcept<_Tp>())
566 if constexpr (__member_rbegin<_Tp>)
568 else if constexpr (__adl_rbegin<_Tp>)
575 template<
typename _Tp>
576 concept __member_rend = requires(_Tp& __t)
578 { __decay_copy(__t.rend()) }
579 -> sentinel_for<decltype(_RBegin{}(__t))>;
582 void rend(
auto&) =
delete;
583 void rend(
const auto&) =
delete;
585 template<
typename _Tp>
586 concept __adl_rend = __class_or_enum<remove_reference_t<_Tp>>
587 && requires(_Tp& __t)
589 { __decay_copy(
rend(__t)) }
590 -> sentinel_for<decltype(_RBegin{}(std::forward<_Tp>(__t)))>;
596 template<
typename _Tp>
597 static constexpr
bool
600 if constexpr (__member_rend<_Tp>)
601 return noexcept(__decay_copy(std::declval<_Tp&>().
rend()));
602 else if constexpr (__adl_rend<_Tp>)
603 return noexcept(__decay_copy(
rend(std::declval<_Tp&>())));
606 if constexpr (noexcept(_Begin{}(std::declval<_Tp&>())))
608 using _It = decltype(_Begin{}(std::declval<_Tp&>()));
610 return is_nothrow_copy_constructible_v<_It>;
618 template<__maybe_borrowed_range _Tp>
619 requires __member_rend<_Tp> || __adl_rend<_Tp> || __reversable<_Tp>
621 operator()(_Tp&& __t)
const
622 noexcept(_S_noexcept<_Tp>())
624 if constexpr (__member_rend<_Tp>)
626 else if constexpr (__adl_rend<_Tp>)
635 template<
typename _Tp>
637 operator()(_Tp&& __e)
const
638 noexcept(noexcept(_RBegin{}(__cust_access::__as_const((_Tp&&)__e))))
639 requires requires { _RBegin{}(__cust_access::__as_const((_Tp&&)__e)); }
641 return _RBegin{}(__cust_access::__as_const(std::forward<_Tp>(__e)));
647 template<
typename _Tp>
649 operator()(_Tp&& __e)
const
650 noexcept(noexcept(_REnd{}(__cust_access::__as_const((_Tp&&)__e))))
651 requires requires { _REnd{}(__cust_access::__as_const((_Tp&&)__e)); }
653 return _REnd{}(__cust_access::__as_const(std::forward<_Tp>(__e)));
657 template<
typename _Tp>
658 concept __member_size = !disable_sized_range<remove_cvref_t<_Tp>>
659 && requires(_Tp&& __t)
661 { __decay_copy(std::forward<_Tp>(__t).size()) }
662 -> __detail::__is_integer_like;
665 void size(
auto&) =
delete;
666 void size(
const auto&) =
delete;
668 template<
typename _Tp>
669 concept __adl_size = __class_or_enum<remove_reference_t<_Tp>>
670 && !disable_sized_range<remove_cvref_t<_Tp>>
671 && requires(_Tp&& __t)
673 { __decay_copy(size(std::forward<_Tp>(__t))) }
674 -> __detail::__is_integer_like;
677 template<
typename _Tp>
678 concept __sentinel_size = requires(_Tp&& __t)
680 { _Begin{}(std::forward<_Tp>(__t)) } -> forward_iterator;
682 { _End{}(std::forward<_Tp>(__t)) }
683 -> sized_sentinel_for<decltype(_Begin{}(std::forward<_Tp>(__t)))>;
689 template<
typename _Tp>
690 static constexpr
bool
693 if constexpr (is_bounded_array_v<remove_reference_t<_Tp>>)
695 else if constexpr (__member_size<_Tp>)
696 return noexcept(__decay_copy(
std::declval<_Tp>().size()));
697 else if constexpr (__adl_size<_Tp>)
698 return noexcept(__decay_copy(size(
std::declval<_Tp>())));
699 else if constexpr (__sentinel_size<_Tp>)
700 return noexcept(_End{}(std::declval<_Tp>())
701 - _Begin{}(std::declval<_Tp>()));
705 template<
typename _Tp>
706 requires is_bounded_array_v<remove_reference_t<_Tp>>
707 || __member_size<_Tp> || __adl_size<_Tp> || __sentinel_size<_Tp>
709 operator()(_Tp&& __e)
const noexcept(_S_noexcept<_Tp>())
711 if constexpr (is_bounded_array_v<remove_reference_t<_Tp>>)
713 return extent_v<remove_reference_t<_Tp>>;
715 else if constexpr (__member_size<_Tp>)
716 return std::forward<_Tp>(__e).size();
717 else if constexpr (__adl_size<_Tp>)
718 return size(std::forward<_Tp>(__e));
719 else if constexpr (__sentinel_size<_Tp>)
720 return __detail::__to_unsigned_like(
721 _End{}(std::forward<_Tp>(__e))
722 - _Begin{}(std::forward<_Tp>(__e)));
728 template<
typename _Tp>
729 requires requires (_Tp&& __e)
731 _Begin{}(std::forward<_Tp>(__e));
732 _Size{}(std::forward<_Tp>(__e));
735 operator()(_Tp&& __e)
const
736 noexcept(noexcept(_Size{}(std::forward<_Tp>(__e))))
738 using __iter_type = decltype(_Begin{}(std::forward<_Tp>(__e)));
739 using __diff_type = iter_difference_t<__iter_type>;
741 auto __size = _Size{}(std::forward<_Tp>(__e));
742 if constexpr (integral<__diff_type>)
744 if constexpr (__int_traits<__diff_type>::__digits
745 < __int_traits<ptrdiff_t>::__digits)
746 return static_cast<ptrdiff_t
>(__size);
748 return static_cast<__diff_type
>(__size);
752 template<
typename _Tp>
753 concept __member_empty = requires(_Tp&& __t)
754 { bool(std::forward<_Tp>(__t).empty()); };
756 template<
typename _Tp>
757 concept __size0_empty = requires(_Tp&& __t)
758 { _Size{}(std::forward<_Tp>(__t)) == 0; };
760 template<
typename _Tp>
761 concept __eq_iter_empty = requires(_Tp&& __t)
763 { _Begin{}(std::forward<_Tp>(__t)) } -> forward_iterator;
764 bool(_Begin{}(std::forward<_Tp>(__t))
765 == _End{}(std::forward<_Tp>(__t)));
771 template<
typename _Tp>
772 static constexpr
bool
775 if constexpr (__member_empty<_Tp>)
776 return noexcept(
bool(std::declval<_Tp>().empty()));
777 else if constexpr (__size0_empty<_Tp>)
778 return noexcept(_Size{}(std::declval<_Tp>()) == 0);
780 return noexcept(
bool(_Begin{}(std::declval<_Tp>())
781 == _End{}(std::declval<_Tp>())));
785 template<
typename _Tp>
786 requires __member_empty<_Tp> || __size0_empty<_Tp>
787 || __eq_iter_empty<_Tp>
789 operator()(_Tp&& __e)
const noexcept(_S_noexcept<_Tp>())
791 if constexpr (__member_empty<_Tp>)
792 return bool(std::forward<_Tp>(__e).empty());
793 else if constexpr (__size0_empty<_Tp>)
794 return _Size{}(std::forward<_Tp>(__e)) == 0;
796 return bool(_Begin{}(std::forward<_Tp>(__e))
797 == _End{}(std::forward<_Tp>(__e)));
801 template<
typename _Tp>
802 concept __pointer_to_object = is_pointer_v<_Tp>
803 && is_object_v<remove_pointer_t<_Tp>>;
805 template<
typename _Tp>
806 concept __member_data = is_lvalue_reference_v<_Tp>
807 && requires(_Tp __t) { { __t.data() } -> __pointer_to_object; };
809 template<
typename _Tp>
810 concept __begin_data = requires(_Tp&& __t)
811 { { _Begin{}(std::forward<_Tp>(__t)) } -> contiguous_iterator; };
816 template<
typename _Tp>
817 static constexpr
bool
820 if constexpr (__member_data<_Tp>)
821 return noexcept(__decay_copy(std::declval<_Tp>().data()));
823 return noexcept(_Begin{}(std::declval<_Tp>()));
827 template<__maybe_borrowed_range _Tp>
828 requires __member_data<_Tp> || __begin_data<_Tp>
830 operator()(_Tp&& __e)
const noexcept(_S_noexcept<_Tp>())
832 if constexpr (__member_data<_Tp>)
835 return std::to_address(_Begin{}(std::forward<_Tp>(__e)));
841 template<
typename _Tp>
843 operator()(_Tp&& __e)
const
844 noexcept(noexcept(_Data{}(__cust_access::__as_const((_Tp&&)__e))))
845 requires requires { _Data{}(__cust_access::__as_const((_Tp&&)__e)); }
847 return _Data{}(__cust_access::__as_const(std::forward<_Tp>(__e)));
853 inline namespace __cust
855 inline constexpr __cust_access::_Begin
begin{};
856 inline constexpr __cust_access::_End
end{};
857 inline constexpr __cust_access::_CBegin
cbegin{};
858 inline constexpr __cust_access::_CEnd
cend{};
859 inline constexpr __cust_access::_RBegin
rbegin{};
860 inline constexpr __cust_access::_REnd
rend{};
861 inline constexpr __cust_access::_CRBegin
crbegin{};
862 inline constexpr __cust_access::_CREnd
crend{};
863 inline constexpr __cust_access::_Size size{};
864 inline constexpr __cust_access::_SSize ssize{};
865 inline constexpr __cust_access::_Empty empty{};
866 inline constexpr __cust_access::_Data data{};
867 inline constexpr __cust_access::_CData cdata{};
871 template<
typename _Tp>
872 concept range = requires(_Tp& __t)
879 template<
typename _Tp>
880 concept borrowed_range
881 = range<_Tp> && __detail::__maybe_borrowed_range<_Tp>;
883 template<
typename _Tp>
884 using iterator_t = std::__detail::__range_iter_t<_Tp>;
886 template<range _Range>
887 using sentinel_t = decltype(
ranges::end(std::declval<_Range&>()));
889 template<range _Range>
890 using range_difference_t = iter_difference_t<iterator_t<_Range>>;
892 template<range _Range>
893 using range_value_t = iter_value_t<iterator_t<_Range>>;
895 template<range _Range>
896 using range_reference_t = iter_reference_t<iterator_t<_Range>>;
898 template<range _Range>
899 using range_rvalue_reference_t
900 = iter_rvalue_reference_t<iterator_t<_Range>>;
903 template<
typename _Tp>
904 concept sized_range = range<_Tp>
905 && requires(_Tp& __t) { ranges::size(__t); };
907 template<sized_range _Range>
908 using range_size_t = decltype(ranges::size(std::declval<_Range&>()));
913 template<
typename _Range,
typename _Tp>
915 = range<_Range> && output_iterator<iterator_t<_Range>, _Tp>;
918 template<
typename _Tp>
919 concept input_range = range<_Tp> && input_iterator<iterator_t<_Tp>>;
922 template<
typename _Tp>
923 concept forward_range
924 = input_range<_Tp> && forward_iterator<iterator_t<_Tp>>;
927 template<
typename _Tp>
928 concept bidirectional_range
929 = forward_range<_Tp> && bidirectional_iterator<iterator_t<_Tp>>;
932 template<
typename _Tp>
933 concept random_access_range
934 = bidirectional_range<_Tp> && random_access_iterator<iterator_t<_Tp>>;
937 template<
typename _Tp>
938 concept contiguous_range
939 = random_access_range<_Tp> && contiguous_iterator<iterator_t<_Tp>>
940 && requires(_Tp& __t)
942 { ranges::data(__t) } -> same_as<add_pointer_t<range_reference_t<_Tp>>>;
946 template<
typename _Tp>
948 = range<_Tp> && same_as<iterator_t<_Tp>, sentinel_t<_Tp>>;
954 template<input_or_output_iterator _It>
956 operator()(_It& __it, iter_difference_t<_It> __n)
const
958 if constexpr (random_access_iterator<_It>)
960 else if constexpr (bidirectional_iterator<_It>)
981 #ifdef __cpp_lib_is_constant_evaluated
982 if (std::is_constant_evaluated() && __n < 0)
983 throw "attempt to decrement a non-bidirectional iterator";
985 __glibcxx_assert(__n >= 0);
991 template<input_or_output_iterator _It, sentinel_for<_It> _Sent>
993 operator()(_It& __it, _Sent __bound)
const
995 if constexpr (assignable_from<_It&, _Sent>)
997 else if constexpr (sized_sentinel_for<_Sent, _It>)
998 (*this)(__it, __bound - __it);
1001 while (__it != __bound)
1006 template<input_or_output_iterator _It, sentinel_for<_It> _Sent>
1007 constexpr iter_difference_t<_It>
1008 operator()(_It& __it, iter_difference_t<_It> __n, _Sent __bound)
const
1010 if constexpr (sized_sentinel_for<_Sent, _It>)
1012 const auto __diff = __bound - __it;
1016 else if (__diff > 0 ? __n >= __diff : __n <= __diff)
1018 (*this)(__it, __bound);
1019 return __n - __diff;
1021 else if (__n != 0) [[likely]]
1023 #ifdef __cpp_lib_is_constant_evaluated
1024 if (std::is_constant_evaluated() && !(__n < 0 == __diff < 0))
1025 throw "inconsistent directions for distance and bound";
1028 __glibcxx_assert(__n < 0 == __diff < 0);
1036 else if (__it == __bound || __n == 0)
1040 iter_difference_t<_It> __m = 0;
1046 while (__m != __n && __it != __bound);
1049 else if constexpr (bidirectional_iterator<_It> && same_as<_It, _Sent>)
1051 iter_difference_t<_It> __m = 0;
1057 while (__m != __n && __it != __bound);
1062 #ifdef __cpp_lib_is_constant_evaluated
1063 if (std::is_constant_evaluated() && __n < 0)
1064 throw "attempt to decrement a non-bidirectional iterator";
1066 __glibcxx_assert(__n >= 0);
1072 inline constexpr __advance_fn
advance{};
1074 struct __distance_fn
1076 template<input_or_output_iterator _It, sentinel_for<_It> _Sent>
1077 constexpr iter_difference_t<_It>
1078 operator()(_It __first, _Sent __last)
const
1080 if constexpr (sized_sentinel_for<_Sent, _It>)
1081 return __last - __first;
1084 iter_difference_t<_It> __n = 0;
1085 while (__first != __last)
1094 template<range _Range>
1095 constexpr range_difference_t<_Range>
1096 operator()(_Range&& __r)
const
1098 if constexpr (sized_range<_Range>)
1099 return static_cast<range_difference_t<_Range>
>(ranges::size(__r));
1105 inline constexpr __distance_fn
distance{};
1109 template<input_or_output_iterator _It>
1111 operator()(_It __x)
const
1117 template<input_or_output_iterator _It>
1119 operator()(_It __x, iter_difference_t<_It> __n)
const
1125 template<input_or_output_iterator _It, sentinel_for<_It> _Sent>
1127 operator()(_It __x, _Sent __bound)
const
1133 template<input_or_output_iterator _It, sentinel_for<_It> _Sent>
1135 operator()(_It __x, iter_difference_t<_It> __n, _Sent __bound)
const
1142 inline constexpr __next_fn next{};
1146 template<b
idirectional_iterator _It>
1148 operator()(_It __x)
const
1154 template<b
idirectional_iterator _It>
1156 operator()(_It __x, iter_difference_t<_It> __n)
const
1162 template<b
idirectional_iterator _It>
1164 operator()(_It __x, iter_difference_t<_It> __n, _It __bound)
const
1171 inline constexpr __prev_fn prev{};
1176 _GLIBCXX_END_NAMESPACE_VERSION
typename remove_reference< _Tp >::type remove_reference_t
Alias template for remove_reference.
typename common_type< _Tp... >::type common_type_t
Alias template for common_type.
typename make_signed< _Tp >::type make_signed_t
Alias template for make_signed.
constexpr std::remove_reference< _Tp >::type && move(_Tp &&__t) noexcept
Convert a value to an rvalue.
_Tp * end(valarray< _Tp > &__va) noexcept
Return an iterator pointing to one past the last element of the valarray.
_Tp * begin(valarray< _Tp > &__va) noexcept
Return an iterator pointing to the first element of the valarray.
constexpr reverse_iterator< _Iterator > make_reverse_iterator(_Iterator __i)
Generator function for reverse_iterator.
ISO C++ entities toplevel namespace is std.
constexpr iterator_traits< _InputIterator >::difference_type distance(_InputIterator __first, _InputIterator __last)
A generalization of pointer arithmetic.
constexpr _Tp * end(_Tp(&__arr)[_Nm]) noexcept
Return an iterator pointing to one past the last element of the array.
constexpr auto crend(const _Container &__cont) -> decltype(std::rend(__cont))
Return a reverse iterator pointing one past the first element of the const container.
constexpr auto rend(_Container &__cont) -> decltype(__cont.rend())
Return a reverse iterator pointing one past the first element of the container.
constexpr _Tp * begin(_Tp(&__arr)[_Nm]) noexcept
Return an iterator pointing to the first element of the array.
constexpr auto cend(const _Container &__cont) noexcept(noexcept(std::end(__cont))) -> decltype(std::end(__cont))
Return an iterator pointing to one past the last element of the const container.
constexpr void advance(_InputIterator &__i, _Distance __n)
A generalization of pointer arithmetic.
constexpr auto rbegin(_Container &__cont) -> decltype(__cont.rbegin())
Return a reverse iterator pointing to the last element of the container.
constexpr auto crbegin(const _Container &__cont) -> decltype(std::rbegin(__cont))
Return a reverse iterator pointing to the last element of the const container.
constexpr auto cbegin(const _Container &__cont) noexcept(noexcept(std::begin(__cont))) -> decltype(std::begin(__cont))
Return an iterator pointing to the first element of the const container.
__numeric_traits_integer< _Tp > __int_traits
Convenience alias for __numeric_traits<integer-type>.