56#ifndef _STL_ALGOBASE_H
57#define _STL_ALGOBASE_H 1
72#if __cplusplus >= 201103L
75#if __cplusplus >= 201402L
78#if __cplusplus >= 202002L
82namespace std _GLIBCXX_VISIBILITY(default)
84_GLIBCXX_BEGIN_NAMESPACE_VERSION
90 template<
typename _Tp,
typename _Up>
93 __memcmp(
const _Tp* __first1,
const _Up* __first2,
size_t __num)
95#if __cplusplus >= 201103L
96 static_assert(
sizeof(_Tp) ==
sizeof(_Up),
"can be compared with memcmp");
98#ifdef __cpp_lib_is_constant_evaluated
101 for(; __num > 0; ++__first1, ++__first2, --__num)
102 if (*__first1 != *__first2)
103 return *__first1 < *__first2 ? -1 : 1;
108 return __builtin_memcmp(__first1, __first2,
sizeof(_Tp) * __num);
111#if __cplusplus < 201103L
115 template<
bool _BoolType>
118 template<
typename _ForwardIterator1,
typename _ForwardIterator2>
120 iter_swap(_ForwardIterator1 __a, _ForwardIterator2 __b)
122 typedef typename iterator_traits<_ForwardIterator1>::value_type
124 _ValueType1 __tmp = *__a;
131 struct __iter_swap<true>
133 template<
typename _ForwardIterator1,
typename _ForwardIterator2>
135 iter_swap(_ForwardIterator1 __a, _ForwardIterator2 __b)
152 template<
typename _ForwardIterator1,
typename _ForwardIterator2>
155 iter_swap(_ForwardIterator1 __a, _ForwardIterator2 __b)
158 __glibcxx_function_requires(_Mutable_ForwardIteratorConcept<
160 __glibcxx_function_requires(_Mutable_ForwardIteratorConcept<
163#if __cplusplus < 201103L
169 __glibcxx_function_requires(_ConvertibleConcept<_ValueType1,
171 __glibcxx_function_requires(_ConvertibleConcept<_ValueType2,
178 std::__iter_swap<__are_same<_ValueType1, _ValueType2>::__value
179 && __are_same<_ValueType1&, _ReferenceType1>::__value
180 && __are_same<_ValueType2&, _ReferenceType2>::__value>::
201 template<
typename _ForwardIterator1,
typename _ForwardIterator2>
204 swap_ranges(_ForwardIterator1 __first1, _ForwardIterator1 __last1,
205 _ForwardIterator2 __first2)
208 __glibcxx_function_requires(_Mutable_ForwardIteratorConcept<
210 __glibcxx_function_requires(_Mutable_ForwardIteratorConcept<
212 __glibcxx_requires_valid_range(__first1, __last1);
214 for (; __first1 != __last1; ++__first1, (void)++__first2)
215 std::iter_swap(__first1, __first2);
230 template<
typename _Tp>
233 min(
const _Tp& __a,
const _Tp& __b)
236 __glibcxx_function_requires(_LessThanComparableConcept<_Tp>)
254 template<
typename _Tp>
257 max(
const _Tp& __a,
const _Tp& __b)
260 __glibcxx_function_requires(_LessThanComparableConcept<_Tp>)
278 template<
typename _Tp,
typename _Compare>
281 min(
const _Tp& __a,
const _Tp& __b, _Compare __comp)
284 if (__comp(__b, __a))
300 template<
typename _Tp,
typename _Compare>
303 max(
const _Tp& __a,
const _Tp& __b, _Compare __comp)
306 if (__comp(__a, __b))
313 template<
typename _Iterator>
316 __niter_base(_Iterator __it)
320 template<
typename _Ite,
typename _Seq>
322 __niter_base(const ::__gnu_debug::_Safe_iterator<_Ite, _Seq,
328 template<
typename _From,
typename _To>
331 __niter_wrap(_From __from, _To __res)
332 {
return __from + (__res - std::__niter_base(__from)); }
335 template<
typename _Iterator>
338 __niter_wrap(
const _Iterator&, _Iterator __res)
347 template<
bool _IsMove,
bool _IsSimple,
typename _Category>
350 template<
typename _II,
typename _OI>
353 __copy_m(_II __first, _II __last, _OI __result)
355 for (; __first != __last; ++__result, (void)++__first)
356 *__result = *__first;
361#if __cplusplus >= 201103L
362 template<
typename _Category>
363 struct __copy_move<true, false, _Category>
365 template<
typename _II,
typename _OI>
368 __copy_m(_II __first, _II __last, _OI __result)
370 for (; __first != __last; ++__result, (void)++__first)
378 struct __copy_move<false, false, random_access_iterator_tag>
380 template<
typename _II,
typename _OI>
383 __copy_m(_II __first, _II __last, _OI __result)
385 typedef typename iterator_traits<_II>::difference_type _Distance;
386 for(_Distance __n = __last - __first; __n > 0; --__n)
388 *__result = *__first;
396#if __cplusplus >= 201103L
398 struct __copy_move<true, false, random_access_iterator_tag>
400 template<
typename _II,
typename _OI>
403 __copy_m(_II __first, _II __last, _OI __result)
405 typedef typename iterator_traits<_II>::difference_type _Distance;
406 for(_Distance __n = __last - __first; __n > 0; --__n)
417 template<
bool _IsMove>
418 struct __copy_move<_IsMove, true, random_access_iterator_tag>
420 template<
typename _Tp>
423 __copy_m(
const _Tp* __first,
const _Tp* __last, _Tp* __result)
425#if __cplusplus >= 201103L
426 using __assignable = __conditional_t<_IsMove,
427 is_move_assignable<_Tp>,
428 is_copy_assignable<_Tp>>;
430 static_assert( __assignable::value,
"type must be assignable" );
432 const ptrdiff_t _Num = __last - __first;
434 __builtin_memmove(__result, __first,
sizeof(_Tp) * _Num);
435 return __result + _Num;
439_GLIBCXX_BEGIN_NAMESPACE_CONTAINER
441 template<
typename _Tp,
typename _Ref,
typename _Ptr>
442 struct _Deque_iterator;
444 struct _Bit_iterator;
446_GLIBCXX_END_NAMESPACE_CONTAINER
451 template<
typename _CharT>
454 template<
typename _CharT,
typename _Traits>
455 class istreambuf_iterator;
457 template<
typename _CharT,
typename _Traits>
458 class ostreambuf_iterator;
460 template<
bool _IsMove,
typename _CharT>
461 typename __gnu_cxx::__enable_if<__is_char<_CharT>::__value,
462 ostreambuf_iterator<_CharT, char_traits<_CharT> > >::__type
463 __copy_move_a2(_CharT*, _CharT*,
464 ostreambuf_iterator<_CharT, char_traits<_CharT> >);
466 template<
bool _IsMove,
typename _CharT>
467 typename __gnu_cxx::__enable_if<__is_char<_CharT>::__value,
468 ostreambuf_iterator<_CharT, char_traits<_CharT> > >::__type
469 __copy_move_a2(
const _CharT*,
const _CharT*,
470 ostreambuf_iterator<_CharT, char_traits<_CharT> >);
472 template<
bool _IsMove,
typename _CharT>
473 typename __gnu_cxx::__enable_if<__is_char<_CharT>::__value,
475 __copy_move_a2(istreambuf_iterator<_CharT, char_traits<_CharT> >,
476 istreambuf_iterator<_CharT, char_traits<_CharT> >, _CharT*);
478 template<
bool _IsMove,
typename _CharT>
479 typename __gnu_cxx::__enable_if<
480 __is_char<_CharT>::__value,
481 _GLIBCXX_STD_C::_Deque_iterator<_CharT, _CharT&, _CharT*> >::__type
483 istreambuf_iterator<_CharT, char_traits<_CharT> >,
484 istreambuf_iterator<_CharT, char_traits<_CharT> >,
485 _GLIBCXX_STD_C::_Deque_iterator<_CharT, _CharT&, _CharT*>);
488 template<
bool _IsMove,
typename _II,
typename _OI>
491 __copy_move_a2(_II __first, _II __last, _OI __result)
493 typedef typename iterator_traits<_II>::iterator_category _Category;
494#ifdef __cpp_lib_is_constant_evaluated
496 return std::__copy_move<_IsMove, false, _Category>::
497 __copy_m(__first, __last, __result);
499 return std::__copy_move<_IsMove, __memcpyable<_OI, _II>::__value,
500 _Category>::__copy_m(__first, __last, __result);
503 template<
bool _IsMove,
504 typename _Tp,
typename _Ref,
typename _Ptr,
typename _OI>
506 __copy_move_a1(_GLIBCXX_STD_C::_Deque_iterator<_Tp, _Ref, _Ptr>,
507 _GLIBCXX_STD_C::_Deque_iterator<_Tp, _Ref, _Ptr>,
510 template<
bool _IsMove,
511 typename _ITp,
typename _IRef,
typename _IPtr,
typename _OTp>
512 _GLIBCXX_STD_C::_Deque_iterator<_OTp, _OTp&, _OTp*>
513 __copy_move_a1(_GLIBCXX_STD_C::_Deque_iterator<_ITp, _IRef, _IPtr>,
514 _GLIBCXX_STD_C::_Deque_iterator<_ITp, _IRef, _IPtr>,
515 _GLIBCXX_STD_C::_Deque_iterator<_OTp, _OTp&, _OTp*>);
517 template<
bool _IsMove,
typename _II,
typename _Tp>
518 typename __gnu_cxx::__enable_if<
519 __is_random_access_iter<_II>::__value,
520 _GLIBCXX_STD_C::_Deque_iterator<_Tp, _Tp&, _Tp*> >::__type
521 __copy_move_a1(_II, _II, _GLIBCXX_STD_C::_Deque_iterator<_Tp, _Tp&, _Tp*>);
523 template<
bool _IsMove,
typename _II,
typename _OI>
526 __copy_move_a1(_II __first, _II __last, _OI __result)
527 {
return std::__copy_move_a2<_IsMove>(__first, __last, __result); }
529 template<
bool _IsMove,
typename _II,
typename _OI>
532 __copy_move_a(_II __first, _II __last, _OI __result)
534 return std::__niter_wrap(__result,
535 std::__copy_move_a1<_IsMove>(std::__niter_base(__first),
536 std::__niter_base(__last),
537 std::__niter_base(__result)));
540 template<
bool _IsMove,
541 typename _Ite,
typename _Seq,
typename _Cat,
typename _OI>
543 __copy_move_a(const ::__gnu_debug::_Safe_iterator<_Ite, _Seq, _Cat>&,
544 const ::__gnu_debug::_Safe_iterator<_Ite, _Seq, _Cat>&,
547 template<
bool _IsMove,
548 typename _II,
typename _Ite,
typename _Seq,
typename _Cat>
550 __copy_move_a(_II, _II,
551 const ::__gnu_debug::_Safe_iterator<_Ite, _Seq, _Cat>&);
553 template<
bool _IsMove,
554 typename _IIte,
typename _ISeq,
typename _ICat,
555 typename _OIte,
typename _OSeq,
typename _OCat>
557 __copy_move_a(const ::__gnu_debug::_Safe_iterator<_IIte, _ISeq, _ICat>&,
558 const ::__gnu_debug::_Safe_iterator<_IIte, _ISeq, _ICat>&,
559 const ::__gnu_debug::_Safe_iterator<_OIte, _OSeq, _OCat>&);
561 template<
typename _InputIterator,
typename _Size,
typename _OutputIterator>
564 __copy_n_a(_InputIterator __first, _Size __n, _OutputIterator __result,
571 *__result = *__first;
583 template<
typename _CharT,
typename _Size>
584 typename __gnu_cxx::__enable_if<
585 __is_char<_CharT>::__value, _CharT*>::__type
586 __copy_n_a(istreambuf_iterator<_CharT, char_traits<_CharT> >,
587 _Size, _CharT*,
bool);
589 template<
typename _CharT,
typename _Size>
590 typename __gnu_cxx::__enable_if<
591 __is_char<_CharT>::__value,
592 _GLIBCXX_STD_C::_Deque_iterator<_CharT, _CharT&, _CharT*> >::__type
593 __copy_n_a(istreambuf_iterator<_CharT, char_traits<_CharT> >, _Size,
594 _GLIBCXX_STD_C::_Deque_iterator<_CharT, _CharT&, _CharT*>,
615 template<
typename _II,
typename _OI>
618 copy(_II __first, _II __last, _OI __result)
621 __glibcxx_function_requires(_InputIteratorConcept<_II>)
622 __glibcxx_function_requires(_OutputIteratorConcept<_OI,
624 __glibcxx_requires_can_increment_range(__first, __last, __result);
626 return std::__copy_move_a<__is_move_iterator<_II>::__value>
627 (std::__miter_base(__first), std::__miter_base(__last), __result);
630#if __cplusplus >= 201103L
648 template<
typename _II,
typename _OI>
651 move(_II __first, _II __last, _OI __result)
654 __glibcxx_function_requires(_InputIteratorConcept<_II>)
655 __glibcxx_function_requires(_OutputIteratorConcept<_OI,
657 __glibcxx_requires_can_increment_range(__first, __last, __result);
659 return std::__copy_move_a<true>(std::__miter_base(__first),
660 std::__miter_base(__last), __result);
663#define _GLIBCXX_MOVE3(_Tp, _Up, _Vp) std::move(_Tp, _Up, _Vp)
665#define _GLIBCXX_MOVE3(_Tp, _Up, _Vp) std::copy(_Tp, _Up, _Vp)
668 template<
bool _IsMove,
bool _IsSimple,
typename _Category>
669 struct __copy_move_backward
671 template<
typename _BI1,
typename _BI2>
674 __copy_move_b(_BI1 __first, _BI1 __last, _BI2 __result)
676 while (__first != __last)
677 *--__result = *--__last;
682#if __cplusplus >= 201103L
683 template<
typename _Category>
684 struct __copy_move_backward<true, false, _Category>
686 template<
typename _BI1,
typename _BI2>
689 __copy_move_b(_BI1 __first, _BI1 __last, _BI2 __result)
691 while (__first != __last)
699 struct __copy_move_backward<false, false, random_access_iterator_tag>
701 template<
typename _BI1,
typename _BI2>
704 __copy_move_b(_BI1 __first, _BI1 __last, _BI2 __result)
706 typename iterator_traits<_BI1>::difference_type
707 __n = __last - __first;
708 for (; __n > 0; --__n)
709 *--__result = *--__last;
714#if __cplusplus >= 201103L
716 struct __copy_move_backward<true, false, random_access_iterator_tag>
718 template<
typename _BI1,
typename _BI2>
721 __copy_move_b(_BI1 __first, _BI1 __last, _BI2 __result)
723 typename iterator_traits<_BI1>::difference_type
724 __n = __last - __first;
725 for (; __n > 0; --__n)
732 template<
bool _IsMove>
733 struct __copy_move_backward<_IsMove, true, random_access_iterator_tag>
735 template<
typename _Tp>
738 __copy_move_b(
const _Tp* __first,
const _Tp* __last, _Tp* __result)
740#if __cplusplus >= 201103L
741 using __assignable = __conditional_t<_IsMove,
742 is_move_assignable<_Tp>,
743 is_copy_assignable<_Tp>>;
745 static_assert( __assignable::value,
"type must be assignable" );
747 const ptrdiff_t _Num = __last - __first;
749 __builtin_memmove(__result - _Num, __first,
sizeof(_Tp) * _Num);
750 return __result - _Num;
754 template<
bool _IsMove,
typename _BI1,
typename _BI2>
757 __copy_move_backward_a2(_BI1 __first, _BI1 __last, _BI2 __result)
759 typedef typename iterator_traits<_BI1>::iterator_category _Category;
760#ifdef __cpp_lib_is_constant_evaluated
762 return std::__copy_move_backward<_IsMove, false, _Category>::
763 __copy_move_b(__first, __last, __result);
765 return std::__copy_move_backward<_IsMove,
766 __memcpyable<_BI2, _BI1>::__value,
767 _Category>::__copy_move_b(__first,
772 template<
bool _IsMove,
typename _BI1,
typename _BI2>
775 __copy_move_backward_a1(_BI1 __first, _BI1 __last, _BI2 __result)
776 {
return std::__copy_move_backward_a2<_IsMove>(__first, __last, __result); }
778 template<
bool _IsMove,
779 typename _Tp,
typename _Ref,
typename _Ptr,
typename _OI>
781 __copy_move_backward_a1(_GLIBCXX_STD_C::_Deque_iterator<_Tp, _Ref, _Ptr>,
782 _GLIBCXX_STD_C::_Deque_iterator<_Tp, _Ref, _Ptr>,
785 template<
bool _IsMove,
786 typename _ITp,
typename _IRef,
typename _IPtr,
typename _OTp>
787 _GLIBCXX_STD_C::_Deque_iterator<_OTp, _OTp&, _OTp*>
788 __copy_move_backward_a1(
789 _GLIBCXX_STD_C::_Deque_iterator<_ITp, _IRef, _IPtr>,
790 _GLIBCXX_STD_C::_Deque_iterator<_ITp, _IRef, _IPtr>,
791 _GLIBCXX_STD_C::_Deque_iterator<_OTp, _OTp&, _OTp*>);
793 template<
bool _IsMove,
typename _II,
typename _Tp>
794 typename __gnu_cxx::__enable_if<
795 __is_random_access_iter<_II>::__value,
796 _GLIBCXX_STD_C::_Deque_iterator<_Tp, _Tp&, _Tp*> >::__type
797 __copy_move_backward_a1(_II, _II,
798 _GLIBCXX_STD_C::_Deque_iterator<_Tp, _Tp&, _Tp*>);
800 template<
bool _IsMove,
typename _II,
typename _OI>
803 __copy_move_backward_a(_II __first, _II __last, _OI __result)
805 return std::__niter_wrap(__result,
806 std::__copy_move_backward_a1<_IsMove>
807 (std::__niter_base(__first), std::__niter_base(__last),
808 std::__niter_base(__result)));
811 template<
bool _IsMove,
812 typename _Ite,
typename _Seq,
typename _Cat,
typename _OI>
814 __copy_move_backward_a(
815 const ::__gnu_debug::_Safe_iterator<_Ite, _Seq, _Cat>&,
816 const ::__gnu_debug::_Safe_iterator<_Ite, _Seq, _Cat>&,
819 template<
bool _IsMove,
820 typename _II,
typename _Ite,
typename _Seq,
typename _Cat>
822 __copy_move_backward_a(_II, _II,
823 const ::__gnu_debug::_Safe_iterator<_Ite, _Seq, _Cat>&);
825 template<
bool _IsMove,
826 typename _IIte,
typename _ISeq,
typename _ICat,
827 typename _OIte,
typename _OSeq,
typename _OCat>
829 __copy_move_backward_a(
830 const ::__gnu_debug::_Safe_iterator<_IIte, _ISeq, _ICat>&,
831 const ::__gnu_debug::_Safe_iterator<_IIte, _ISeq, _ICat>&,
832 const ::__gnu_debug::_Safe_iterator<_OIte, _OSeq, _OCat>&);
852 template<
typename _BI1,
typename _BI2>
855 copy_backward(_BI1 __first, _BI1 __last, _BI2 __result)
858 __glibcxx_function_requires(_BidirectionalIteratorConcept<_BI1>)
859 __glibcxx_function_requires(_Mutable_BidirectionalIteratorConcept<_BI2>)
860 __glibcxx_function_requires(_OutputIteratorConcept<_BI2,
862 __glibcxx_requires_can_decrement_range(__first, __last, __result);
864 return std::__copy_move_backward_a<__is_move_iterator<_BI1>::__value>
865 (std::__miter_base(__first), std::__miter_base(__last), __result);
868#if __cplusplus >= 201103L
887 template<
typename _BI1,
typename _BI2>
893 __glibcxx_function_requires(_BidirectionalIteratorConcept<_BI1>)
894 __glibcxx_function_requires(_Mutable_BidirectionalIteratorConcept<_BI2>)
895 __glibcxx_function_requires(_OutputIteratorConcept<_BI2,
897 __glibcxx_requires_can_decrement_range(__first, __last, __result);
899 return std::__copy_move_backward_a<true>(std::__miter_base(__first),
900 std::__miter_base(__last),
904#define _GLIBCXX_MOVE_BACKWARD3(_Tp, _Up, _Vp) std::move_backward(_Tp, _Up, _Vp)
906#define _GLIBCXX_MOVE_BACKWARD3(_Tp, _Up, _Vp) std::copy_backward(_Tp, _Up, _Vp)
909 template<
typename _ForwardIterator,
typename _Tp>
912 __gnu_cxx::__enable_if<!__is_scalar<_Tp>::__value,
void>::__type
913 __fill_a1(_ForwardIterator __first, _ForwardIterator __last,
916 for (; __first != __last; ++__first)
920 template<
typename _ForwardIterator,
typename _Tp>
923 __gnu_cxx::__enable_if<__is_scalar<_Tp>::__value,
void>::__type
924 __fill_a1(_ForwardIterator __first, _ForwardIterator __last,
927 const _Tp __tmp = __value;
928 for (; __first != __last; ++__first)
933 template<
typename _Tp>
936 __gnu_cxx::__enable_if<__is_byte<_Tp>::__value,
void>::__type
937 __fill_a1(_Tp* __first, _Tp* __last,
const _Tp& __c)
939 const _Tp __tmp = __c;
940#if __cpp_lib_is_constant_evaluated
943 for (; __first != __last; ++__first)
948 if (
const size_t __len = __last - __first)
949 __builtin_memset(__first,
static_cast<unsigned char>(__tmp), __len);
952 template<
typename _Ite,
typename _Cont,
typename _Tp>
955 __fill_a1(::__gnu_cxx::__normal_iterator<_Ite, _Cont> __first,
956 ::__gnu_cxx::__normal_iterator<_Ite, _Cont> __last,
958 { std::__fill_a1(__first.base(), __last.base(), __value); }
960 template<
typename _Tp,
typename _VTp>
962 __fill_a1(
const _GLIBCXX_STD_C::_Deque_iterator<_Tp, _Tp&, _Tp*>&,
963 const _GLIBCXX_STD_C::_Deque_iterator<_Tp, _Tp&, _Tp*>&,
968 __fill_a1(_GLIBCXX_STD_C::_Bit_iterator, _GLIBCXX_STD_C::_Bit_iterator,
971 template<
typename _FIte,
typename _Tp>
974 __fill_a(_FIte __first, _FIte __last,
const _Tp& __value)
975 { std::__fill_a1(__first, __last, __value); }
977 template<
typename _Ite,
typename _Seq,
typename _Cat,
typename _Tp>
979 __fill_a(const ::__gnu_debug::_Safe_iterator<_Ite, _Seq, _Cat>&,
980 const ::__gnu_debug::_Safe_iterator<_Ite, _Seq, _Cat>&,
995 template<
typename _ForwardIterator,
typename _Tp>
998 fill(_ForwardIterator __first, _ForwardIterator __last,
const _Tp& __value)
1001 __glibcxx_function_requires(_Mutable_ForwardIteratorConcept<
1003 __glibcxx_requires_valid_range(__first, __last);
1005 std::__fill_a(__first, __last, __value);
1009 inline _GLIBCXX_CONSTEXPR
int
1010 __size_to_integer(
int __n) {
return __n; }
1011 inline _GLIBCXX_CONSTEXPR
unsigned
1012 __size_to_integer(
unsigned __n) {
return __n; }
1013 inline _GLIBCXX_CONSTEXPR
long
1014 __size_to_integer(
long __n) {
return __n; }
1015 inline _GLIBCXX_CONSTEXPR
unsigned long
1016 __size_to_integer(
unsigned long __n) {
return __n; }
1017 inline _GLIBCXX_CONSTEXPR
long long
1018 __size_to_integer(
long long __n) {
return __n; }
1019 inline _GLIBCXX_CONSTEXPR
unsigned long long
1020 __size_to_integer(
unsigned long long __n) {
return __n; }
1022#if defined(__GLIBCXX_TYPE_INT_N_0)
1023 __extension__
inline _GLIBCXX_CONSTEXPR __GLIBCXX_TYPE_INT_N_0
1024 __size_to_integer(__GLIBCXX_TYPE_INT_N_0 __n) {
return __n; }
1025 __extension__
inline _GLIBCXX_CONSTEXPR
unsigned __GLIBCXX_TYPE_INT_N_0
1026 __size_to_integer(
unsigned __GLIBCXX_TYPE_INT_N_0 __n) {
return __n; }
1028#if defined(__GLIBCXX_TYPE_INT_N_1)
1029 __extension__
inline _GLIBCXX_CONSTEXPR __GLIBCXX_TYPE_INT_N_1
1030 __size_to_integer(__GLIBCXX_TYPE_INT_N_1 __n) {
return __n; }
1031 __extension__
inline _GLIBCXX_CONSTEXPR
unsigned __GLIBCXX_TYPE_INT_N_1
1032 __size_to_integer(
unsigned __GLIBCXX_TYPE_INT_N_1 __n) {
return __n; }
1034#if defined(__GLIBCXX_TYPE_INT_N_2)
1035 __extension__
inline _GLIBCXX_CONSTEXPR __GLIBCXX_TYPE_INT_N_2
1036 __size_to_integer(__GLIBCXX_TYPE_INT_N_2 __n) {
return __n; }
1037 __extension__
inline _GLIBCXX_CONSTEXPR
unsigned __GLIBCXX_TYPE_INT_N_2
1038 __size_to_integer(
unsigned __GLIBCXX_TYPE_INT_N_2 __n) {
return __n; }
1040#if defined(__GLIBCXX_TYPE_INT_N_3)
1041 __extension__
inline _GLIBCXX_CONSTEXPR
unsigned __GLIBCXX_TYPE_INT_N_3
1042 __size_to_integer(__GLIBCXX_TYPE_INT_N_3 __n) {
return __n; }
1043 __extension__
inline _GLIBCXX_CONSTEXPR __GLIBCXX_TYPE_INT_N_3
1044 __size_to_integer(
unsigned __GLIBCXX_TYPE_INT_N_3 __n) {
return __n; }
1047 inline _GLIBCXX_CONSTEXPR
long long
1048 __size_to_integer(
float __n) {
return (
long long)__n; }
1049 inline _GLIBCXX_CONSTEXPR
long long
1050 __size_to_integer(
double __n) {
return (
long long)__n; }
1051 inline _GLIBCXX_CONSTEXPR
long long
1052 __size_to_integer(
long double __n) {
return (
long long)__n; }
1053#if !defined(__STRICT_ANSI__) && defined(_GLIBCXX_USE_FLOAT128)
1054 __extension__
inline _GLIBCXX_CONSTEXPR
long long
1055 __size_to_integer(__float128 __n) {
return (
long long)__n; }
1058 template<
typename _OutputIterator,
typename _Size,
typename _Tp>
1059 _GLIBCXX20_CONSTEXPR
1061 __gnu_cxx::__enable_if<!__is_scalar<_Tp>::__value, _OutputIterator>::__type
1062 __fill_n_a1(_OutputIterator __first, _Size __n,
const _Tp& __value)
1064 for (; __n > 0; --__n, (void) ++__first)
1069 template<
typename _OutputIterator,
typename _Size,
typename _Tp>
1070 _GLIBCXX20_CONSTEXPR
1072 __gnu_cxx::__enable_if<__is_scalar<_Tp>::__value, _OutputIterator>::__type
1073 __fill_n_a1(_OutputIterator __first, _Size __n,
const _Tp& __value)
1075 const _Tp __tmp = __value;
1076 for (; __n > 0; --__n, (void) ++__first)
1081 template<
typename _Ite,
typename _Seq,
typename _Cat,
typename _Size,
1084 __fill_n_a(const ::__gnu_debug::_Safe_iterator<_Ite, _Seq, _Cat>& __first,
1085 _Size __n,
const _Tp& __value,
1088 template<
typename _OutputIterator,
typename _Size,
typename _Tp>
1089 _GLIBCXX20_CONSTEXPR
1090 inline _OutputIterator
1091 __fill_n_a(_OutputIterator __first, _Size __n,
const _Tp& __value,
1094#if __cplusplus >= 201103L
1095 static_assert(is_integral<_Size>{},
"fill_n must pass integral size");
1097 return __fill_n_a1(__first, __n, __value);
1100 template<
typename _OutputIterator,
typename _Size,
typename _Tp>
1101 _GLIBCXX20_CONSTEXPR
1102 inline _OutputIterator
1103 __fill_n_a(_OutputIterator __first, _Size __n,
const _Tp& __value,
1106#if __cplusplus >= 201103L
1107 static_assert(is_integral<_Size>{},
"fill_n must pass integral size");
1109 return __fill_n_a1(__first, __n, __value);
1112 template<
typename _OutputIterator,
typename _Size,
typename _Tp>
1113 _GLIBCXX20_CONSTEXPR
1114 inline _OutputIterator
1115 __fill_n_a(_OutputIterator __first, _Size __n,
const _Tp& __value,
1118#if __cplusplus >= 201103L
1119 static_assert(is_integral<_Size>{},
"fill_n must pass integral size");
1124 __glibcxx_requires_can_increment(__first, __n);
1126 std::__fill_a(__first, __first + __n, __value);
1127 return __first + __n;
1147 template<
typename _OI,
typename _Size,
typename _Tp>
1148 _GLIBCXX20_CONSTEXPR
1150 fill_n(_OI __first, _Size __n,
const _Tp& __value)
1153 __glibcxx_function_requires(_OutputIteratorConcept<_OI, const _Tp&>)
1155 return std::__fill_n_a(__first, std::__size_to_integer(__n), __value,
1159 template<
bool _BoolType>
1162 template<
typename _II1,
typename _II2>
1163 _GLIBCXX20_CONSTEXPR
1165 equal(_II1 __first1, _II1 __last1, _II2 __first2)
1167 for (; __first1 != __last1; ++__first1, (void) ++__first2)
1168 if (!(*__first1 == *__first2))
1175 struct __equal<true>
1177 template<
typename _Tp>
1178 _GLIBCXX20_CONSTEXPR
1180 equal(
const _Tp* __first1,
const _Tp* __last1,
const _Tp* __first2)
1182 if (
const size_t __len = (__last1 - __first1))
1183 return !std::__memcmp(__first1, __first2, __len);
1188 template<
typename _Tp,
typename _Ref,
typename _Ptr,
typename _II>
1189 typename __gnu_cxx::__enable_if<
1190 __is_random_access_iter<_II>::__value,
bool>::__type
1191 __equal_aux1(_GLIBCXX_STD_C::_Deque_iterator<_Tp, _Ref, _Ptr>,
1192 _GLIBCXX_STD_C::_Deque_iterator<_Tp, _Ref, _Ptr>,
1195 template<
typename _Tp1,
typename _Ref1,
typename _Ptr1,
1196 typename _Tp2,
typename _Ref2,
typename _Ptr2>
1198 __equal_aux1(_GLIBCXX_STD_C::_Deque_iterator<_Tp1, _Ref1, _Ptr1>,
1199 _GLIBCXX_STD_C::_Deque_iterator<_Tp1, _Ref1, _Ptr1>,
1200 _GLIBCXX_STD_C::_Deque_iterator<_Tp2, _Ref2, _Ptr2>);
1202 template<
typename _II,
typename _Tp,
typename _Ref,
typename _Ptr>
1203 typename __gnu_cxx::__enable_if<
1204 __is_random_access_iter<_II>::__value,
bool>::__type
1205 __equal_aux1(_II, _II,
1206 _GLIBCXX_STD_C::_Deque_iterator<_Tp, _Ref, _Ptr>);
1208 template<
typename _II1,
typename _II2>
1209 _GLIBCXX20_CONSTEXPR
1211 __equal_aux1(_II1 __first1, _II1 __last1, _II2 __first2)
1213 typedef typename iterator_traits<_II1>::value_type _ValueType1;
1214 const bool __simple = ((__is_integer<_ValueType1>::__value
1215 || __is_pointer<_ValueType1>::__value)
1216 && __memcmpable<_II1, _II2>::__value);
1217 return std::__equal<__simple>::equal(__first1, __last1, __first2);
1220 template<
typename _II1,
typename _II2>
1221 _GLIBCXX20_CONSTEXPR
1223 __equal_aux(_II1 __first1, _II1 __last1, _II2 __first2)
1225 return std::__equal_aux1(std::__niter_base(__first1),
1226 std::__niter_base(__last1),
1227 std::__niter_base(__first2));
1230 template<
typename _II1,
typename _Seq1,
typename _Cat1,
typename _II2>
1232 __equal_aux(const ::__gnu_debug::_Safe_iterator<_II1, _Seq1, _Cat1>&,
1233 const ::__gnu_debug::_Safe_iterator<_II1, _Seq1, _Cat1>&,
1236 template<
typename _II1,
typename _II2,
typename _Seq2,
typename _Cat2>
1238 __equal_aux(_II1, _II1,
1239 const ::__gnu_debug::_Safe_iterator<_II2, _Seq2, _Cat2>&);
1241 template<
typename _II1,
typename _Seq1,
typename _Cat1,
1242 typename _II2,
typename _Seq2,
typename _Cat2>
1244 __equal_aux(const ::__gnu_debug::_Safe_iterator<_II1, _Seq1, _Cat1>&,
1245 const ::__gnu_debug::_Safe_iterator<_II1, _Seq1, _Cat1>&,
1246 const ::__gnu_debug::_Safe_iterator<_II2, _Seq2, _Cat2>&);
1248 template<
typename,
typename>
1251 template<
typename _II1,
typename _II2>
1252 _GLIBCXX20_CONSTEXPR
1254 __newlast1(_II1, _II1 __last1, _II2, _II2)
1257 template<
typename _II>
1258 _GLIBCXX20_CONSTEXPR
1260 __cnd2(_II __first, _II __last)
1261 {
return __first != __last; }
1265 struct __lc_rai<random_access_iterator_tag, random_access_iterator_tag>
1267 template<
typename _RAI1,
typename _RAI2>
1268 _GLIBCXX20_CONSTEXPR
1270 __newlast1(_RAI1 __first1, _RAI1 __last1,
1271 _RAI2 __first2, _RAI2 __last2)
1273 const typename iterator_traits<_RAI1>::difference_type
1274 __diff1 = __last1 - __first1;
1275 const typename iterator_traits<_RAI2>::difference_type
1276 __diff2 = __last2 - __first2;
1277 return __diff2 < __diff1 ? __first1 + __diff2 : __last1;
1280 template<
typename _RAI>
1281 static _GLIBCXX20_CONSTEXPR
bool
1286 template<
typename _II1,
typename _II2,
typename _Compare>
1287 _GLIBCXX20_CONSTEXPR
1289 __lexicographical_compare_impl(_II1 __first1, _II1 __last1,
1290 _II2 __first2, _II2 __last2,
1293 typedef typename iterator_traits<_II1>::iterator_category _Category1;
1294 typedef typename iterator_traits<_II2>::iterator_category _Category2;
1295 typedef std::__lc_rai<_Category1, _Category2> __rai_type;
1297 __last1 = __rai_type::__newlast1(__first1, __last1, __first2, __last2);
1298 for (; __first1 != __last1 && __rai_type::__cnd2(__first2, __last2);
1299 ++__first1, (void)++__first2)
1301 if (__comp(__first1, __first2))
1303 if (__comp(__first2, __first1))
1306 return __first1 == __last1 && __first2 != __last2;
1309 template<
bool _BoolType>
1310 struct __lexicographical_compare
1312 template<
typename _II1,
typename _II2>
1313 _GLIBCXX20_CONSTEXPR
1315 __lc(_II1 __first1, _II1 __last1, _II2 __first2, _II2 __last2)
1317 using __gnu_cxx::__ops::__iter_less_iter;
1318 return std::__lexicographical_compare_impl(__first1, __last1,
1320 __iter_less_iter());
1323 template<
typename _II1,
typename _II2>
1324 _GLIBCXX20_CONSTEXPR
1326 __3way(_II1 __first1, _II1 __last1, _II2 __first2, _II2 __last2)
1328 while (__first1 != __last1)
1330 if (__first2 == __last2)
1332 if (*__first1 < *__first2)
1334 if (*__first2 < *__first1)
1339 return int(__first2 == __last2) - 1;
1344 struct __lexicographical_compare<true>
1346 template<
typename _Tp,
typename _Up>
1347 _GLIBCXX20_CONSTEXPR
1349 __lc(
const _Tp* __first1,
const _Tp* __last1,
1350 const _Up* __first2,
const _Up* __last2)
1351 {
return __3way(__first1, __last1, __first2, __last2) < 0; }
1353 template<
typename _Tp,
typename _Up>
1354 _GLIBCXX20_CONSTEXPR
1356 __3way(
const _Tp* __first1,
const _Tp* __last1,
1357 const _Up* __first2,
const _Up* __last2)
1359 const size_t __len1 = __last1 - __first1;
1360 const size_t __len2 = __last2 - __first2;
1361 if (
const size_t __len =
std::min(__len1, __len2))
1362 if (
int __result = std::__memcmp(__first1, __first2, __len))
1364 return ptrdiff_t(__len1 - __len2);
1368 template<
typename _II1,
typename _II2>
1369 _GLIBCXX20_CONSTEXPR
1371 __lexicographical_compare_aux1(_II1 __first1, _II1 __last1,
1372 _II2 __first2, _II2 __last2)
1374 typedef typename iterator_traits<_II1>::value_type _ValueType1;
1375 typedef typename iterator_traits<_II2>::value_type _ValueType2;
1376 const bool __simple =
1377 (__is_memcmp_ordered_with<_ValueType1, _ValueType2>::__value
1378 && __is_pointer<_II1>::__value
1379 && __is_pointer<_II2>::__value
1380#if __cplusplus > 201703L && __cpp_lib_concepts
1384 && !is_volatile_v<remove_reference_t<iter_reference_t<_II1>>>
1385 && !is_volatile_v<remove_reference_t<iter_reference_t<_II2>>>
1389 return std::__lexicographical_compare<__simple>::__lc(__first1, __last1,
1393 template<
typename _Tp1,
typename _Ref1,
typename _Ptr1,
1396 __lexicographical_compare_aux1(
1397 _GLIBCXX_STD_C::_Deque_iterator<_Tp1, _Ref1, _Ptr1>,
1398 _GLIBCXX_STD_C::_Deque_iterator<_Tp1, _Ref1, _Ptr1>,
1401 template<
typename _Tp1,
1402 typename _Tp2,
typename _Ref2,
typename _Ptr2>
1404 __lexicographical_compare_aux1(_Tp1*, _Tp1*,
1405 _GLIBCXX_STD_C::_Deque_iterator<_Tp2, _Ref2, _Ptr2>,
1406 _GLIBCXX_STD_C::_Deque_iterator<_Tp2, _Ref2, _Ptr2>);
1408 template<
typename _Tp1,
typename _Ref1,
typename _Ptr1,
1409 typename _Tp2,
typename _Ref2,
typename _Ptr2>
1411 __lexicographical_compare_aux1(
1412 _GLIBCXX_STD_C::_Deque_iterator<_Tp1, _Ref1, _Ptr1>,
1413 _GLIBCXX_STD_C::_Deque_iterator<_Tp1, _Ref1, _Ptr1>,
1414 _GLIBCXX_STD_C::_Deque_iterator<_Tp2, _Ref2, _Ptr2>,
1415 _GLIBCXX_STD_C::_Deque_iterator<_Tp2, _Ref2, _Ptr2>);
1417 template<
typename _II1,
typename _II2>
1418 _GLIBCXX20_CONSTEXPR
1420 __lexicographical_compare_aux(_II1 __first1, _II1 __last1,
1421 _II2 __first2, _II2 __last2)
1423 return std::__lexicographical_compare_aux1(std::__niter_base(__first1),
1424 std::__niter_base(__last1),
1425 std::__niter_base(__first2),
1426 std::__niter_base(__last2));
1429 template<
typename _Iter1,
typename _Seq1,
typename _Cat1,
1432 __lexicographical_compare_aux(
1433 const ::__gnu_debug::_Safe_iterator<_Iter1, _Seq1, _Cat1>&,
1434 const ::__gnu_debug::_Safe_iterator<_Iter1, _Seq1, _Cat1>&,
1437 template<
typename _II1,
1438 typename _Iter2,
typename _Seq2,
typename _Cat2>
1440 __lexicographical_compare_aux(
1442 const ::__gnu_debug::_Safe_iterator<_Iter2, _Seq2, _Cat2>&,
1443 const ::__gnu_debug::_Safe_iterator<_Iter2, _Seq2, _Cat2>&);
1445 template<
typename _Iter1,
typename _Seq1,
typename _Cat1,
1446 typename _Iter2,
typename _Seq2,
typename _Cat2>
1448 __lexicographical_compare_aux(
1449 const ::__gnu_debug::_Safe_iterator<_Iter1, _Seq1, _Cat1>&,
1450 const ::__gnu_debug::_Safe_iterator<_Iter1, _Seq1, _Cat1>&,
1451 const ::__gnu_debug::_Safe_iterator<_Iter2, _Seq2, _Cat2>&,
1452 const ::__gnu_debug::_Safe_iterator<_Iter2, _Seq2, _Cat2>&);
1454 template<
typename _ForwardIterator,
typename _Tp,
typename _Compare>
1455 _GLIBCXX20_CONSTEXPR
1457 __lower_bound(_ForwardIterator __first, _ForwardIterator __last,
1458 const _Tp& __val, _Compare __comp)
1460 typedef typename iterator_traits<_ForwardIterator>::difference_type
1467 _DistanceType __half = __len >> 1;
1468 _ForwardIterator __middle = __first;
1470 if (__comp(__middle, __val))
1474 __len = __len - __half - 1;
1493 template<
typename _ForwardIterator,
typename _Tp>
1494 _GLIBCXX20_CONSTEXPR
1495 inline _ForwardIterator
1496 lower_bound(_ForwardIterator __first, _ForwardIterator __last,
1500 __glibcxx_function_requires(_ForwardIteratorConcept<_ForwardIterator>)
1501 __glibcxx_function_requires(_LessThanOpConcept<
1503 __glibcxx_requires_partitioned_lower(__first, __last, __val);
1505 return std::__lower_bound(__first, __last, __val,
1506 __gnu_cxx::__ops::__iter_less_val());
1511 template<
typename _Tp>
1512 inline _GLIBCXX_CONSTEXPR _Tp
1515#if __cplusplus >= 201402L
1519 const int __sz =
sizeof(+__n);
1520 int __w = __sz * __CHAR_BIT__ - 1;
1521 if (__sz ==
sizeof(
long long))
1522 __w -= __builtin_clzll(+__n);
1523 else if (__sz ==
sizeof(
long))
1524 __w -= __builtin_clzl(+__n);
1525 else if (__sz ==
sizeof(
int))
1526 __w -= __builtin_clz(+__n);
1531_GLIBCXX_BEGIN_NAMESPACE_ALGO
1545 template<
typename _II1,
typename _II2>
1546 _GLIBCXX20_CONSTEXPR
1548 equal(_II1 __first1, _II1 __last1, _II2 __first2)
1551 __glibcxx_function_requires(_InputIteratorConcept<_II1>)
1552 __glibcxx_function_requires(_InputIteratorConcept<_II2>)
1553 __glibcxx_function_requires(_EqualOpConcept<
1556 __glibcxx_requires_can_increment_range(__first1, __last1, __first2);
1558 return std::__equal_aux(__first1, __last1, __first2);
1576 template<
typename _IIter1,
typename _IIter2,
typename _BinaryPredicate>
1577 _GLIBCXX20_CONSTEXPR
1579 equal(_IIter1 __first1, _IIter1 __last1,
1580 _IIter2 __first2, _BinaryPredicate __binary_pred)
1583 __glibcxx_function_requires(_InputIteratorConcept<_IIter1>)
1584 __glibcxx_function_requires(_InputIteratorConcept<_IIter2>)
1585 __glibcxx_requires_valid_range(__first1, __last1);
1587 for (; __first1 != __last1; ++__first1, (void)++__first2)
1588 if (!
bool(__binary_pred(*__first1, *__first2)))
1593#if __cplusplus >= 201103L
1595 template<
typename _II1,
typename _II2>
1596 _GLIBCXX20_CONSTEXPR
1598 __equal4(_II1 __first1, _II1 __last1, _II2 __first2, _II2 __last2)
1600 using _RATag = random_access_iterator_tag;
1601 using _Cat1 =
typename iterator_traits<_II1>::iterator_category;
1602 using _Cat2 =
typename iterator_traits<_II2>::iterator_category;
1603 using _RAIters = __and_<is_same<_Cat1, _RATag>, is_same<_Cat2, _RATag>>;
1610 return _GLIBCXX_STD_A::equal(__first1, __last1, __first2);
1613 for (; __first1 != __last1 && __first2 != __last2;
1614 ++__first1, (void)++__first2)
1615 if (!(*__first1 == *__first2))
1617 return __first1 == __last1 && __first2 == __last2;
1621 template<
typename _II1,
typename _II2,
typename _BinaryPredicate>
1622 _GLIBCXX20_CONSTEXPR
1624 __equal4(_II1 __first1, _II1 __last1, _II2 __first2, _II2 __last2,
1625 _BinaryPredicate __binary_pred)
1627 using _RATag = random_access_iterator_tag;
1628 using _Cat1 =
typename iterator_traits<_II1>::iterator_category;
1629 using _Cat2 =
typename iterator_traits<_II2>::iterator_category;
1630 using _RAIters = __and_<is_same<_Cat1, _RATag>, is_same<_Cat2, _RATag>>;
1637 return _GLIBCXX_STD_A::equal(__first1, __last1, __first2,
1641 for (; __first1 != __last1 && __first2 != __last2;
1642 ++__first1, (void)++__first2)
1643 if (!
bool(__binary_pred(*__first1, *__first2)))
1645 return __first1 == __last1 && __first2 == __last2;
1649#if __cplusplus > 201103L
1651#define __cpp_lib_robust_nonmodifying_seq_ops 201304L
1666 template<
typename _II1,
typename _II2>
1667 _GLIBCXX20_CONSTEXPR
1669 equal(_II1 __first1, _II1 __last1, _II2 __first2, _II2 __last2)
1672 __glibcxx_function_requires(_InputIteratorConcept<_II1>)
1673 __glibcxx_function_requires(_InputIteratorConcept<_II2>)
1674 __glibcxx_function_requires(_EqualOpConcept<
1677 __glibcxx_requires_valid_range(__first1, __last1);
1678 __glibcxx_requires_valid_range(__first2, __last2);
1680 return _GLIBCXX_STD_A::__equal4(__first1, __last1, __first2, __last2);
1699 template<
typename _IIter1,
typename _IIter2,
typename _BinaryPredicate>
1700 _GLIBCXX20_CONSTEXPR
1702 equal(_IIter1 __first1, _IIter1 __last1,
1703 _IIter2 __first2, _IIter2 __last2, _BinaryPredicate __binary_pred)
1706 __glibcxx_function_requires(_InputIteratorConcept<_IIter1>)
1707 __glibcxx_function_requires(_InputIteratorConcept<_IIter2>)
1708 __glibcxx_requires_valid_range(__first1, __last1);
1709 __glibcxx_requires_valid_range(__first2, __last2);
1711 return _GLIBCXX_STD_A::__equal4(__first1, __last1, __first2, __last2,
1731 template<
typename _II1,
typename _II2>
1732 _GLIBCXX20_CONSTEXPR
1734 lexicographical_compare(_II1 __first1, _II1 __last1,
1735 _II2 __first2, _II2 __last2)
1737#ifdef _GLIBCXX_CONCEPT_CHECKS
1742 __glibcxx_function_requires(_InputIteratorConcept<_II1>)
1743 __glibcxx_function_requires(_InputIteratorConcept<_II2>)
1744 __glibcxx_function_requires(_LessThanOpConcept<_ValueType1, _ValueType2>)
1745 __glibcxx_function_requires(_LessThanOpConcept<_ValueType2, _ValueType1>)
1746 __glibcxx_requires_valid_range(__first1, __last1);
1747 __glibcxx_requires_valid_range(__first2, __last2);
1749 return std::__lexicographical_compare_aux(__first1, __last1,
1766 template<
typename _II1,
typename _II2,
typename _Compare>
1767 _GLIBCXX20_CONSTEXPR
1769 lexicographical_compare(_II1 __first1, _II1 __last1,
1770 _II2 __first2, _II2 __last2, _Compare __comp)
1773 __glibcxx_function_requires(_InputIteratorConcept<_II1>)
1774 __glibcxx_function_requires(_InputIteratorConcept<_II2>)
1775 __glibcxx_requires_valid_range(__first1, __last1);
1776 __glibcxx_requires_valid_range(__first2, __last2);
1778 return std::__lexicographical_compare_impl
1779 (__first1, __last1, __first2, __last2,
1780 __gnu_cxx::__ops::__iter_comp_iter(__comp));
1783#if __cpp_lib_three_way_comparison
1786 template<
typename _Iter>
1787 concept __is_byte_iter = contiguous_iterator<_Iter>
1788 && __is_memcmp_ordered<iter_value_t<_Iter>>::__value;
1792 template<
typename _Tp>
1794 __min_cmp(_Tp __x, _Tp __y)
1798 decltype(__x <=> __y) _M_cmp;
1800 auto __c = __x <=> __y;
1802 return _Res{__y, __c};
1803 return _Res{__x, __c};
1817 template<
typename _InputIter1,
typename _InputIter2,
typename _Comp>
1819 lexicographical_compare_three_way(_InputIter1 __first1,
1820 _InputIter1 __last1,
1821 _InputIter2 __first2,
1822 _InputIter2 __last2,
1824 ->
decltype(__comp(*__first1, *__first2))
1827 __glibcxx_function_requires(_InputIteratorConcept<_InputIter1>)
1828 __glibcxx_function_requires(_InputIteratorConcept<_InputIter2>)
1829 __glibcxx_requires_valid_range(__first1, __last1);
1830 __glibcxx_requires_valid_range(__first2, __last2);
1832 using _Cat =
decltype(__comp(*__first1, *__first2));
1833 static_assert(same_as<common_comparison_category_t<_Cat>, _Cat>);
1835 if (!std::__is_constant_evaluated())
1836 if constexpr (same_as<_Comp, __detail::_Synth3way>
1837 || same_as<_Comp, compare_three_way>)
1838 if constexpr (__is_byte_iter<_InputIter1>)
1839 if constexpr (__is_byte_iter<_InputIter2>)
1841 const auto [__len, __lencmp] = _GLIBCXX_STD_A::
1842 __min_cmp(__last1 - __first1, __last2 - __first2);
1846 = __builtin_memcmp(&*__first1, &*__first2, __len) <=> 0;
1853 while (__first1 != __last1)
1855 if (__first2 == __last2)
1856 return strong_ordering::greater;
1857 if (
auto __cmp = __comp(*__first1, *__first2); __cmp != 0)
1862 return (__first2 == __last2) <=>
true;
1865 template<
typename _InputIter1,
typename _InputIter2>
1867 lexicographical_compare_three_way(_InputIter1 __first1,
1868 _InputIter1 __last1,
1869 _InputIter2 __first2,
1870 _InputIter2 __last2)
1872 return _GLIBCXX_STD_A::
1873 lexicographical_compare_three_way(__first1, __last1, __first2, __last2,
1874 compare_three_way{});
1878 template<
typename _InputIterator1,
typename _InputIterator2,
1879 typename _BinaryPredicate>
1880 _GLIBCXX20_CONSTEXPR
1881 pair<_InputIterator1, _InputIterator2>
1882 __mismatch(_InputIterator1 __first1, _InputIterator1 __last1,
1883 _InputIterator2 __first2, _BinaryPredicate __binary_pred)
1885 while (__first1 != __last1 && __binary_pred(__first1, __first2))
1890 return pair<_InputIterator1, _InputIterator2>(__first1, __first2);
1906 template<
typename _InputIterator1,
typename _InputIterator2>
1907 _GLIBCXX20_CONSTEXPR
1908 inline pair<_InputIterator1, _InputIterator2>
1909 mismatch(_InputIterator1 __first1, _InputIterator1 __last1,
1910 _InputIterator2 __first2)
1913 __glibcxx_function_requires(_InputIteratorConcept<_InputIterator1>)
1914 __glibcxx_function_requires(_InputIteratorConcept<_InputIterator2>)
1915 __glibcxx_function_requires(_EqualOpConcept<
1918 __glibcxx_requires_valid_range(__first1, __last1);
1920 return _GLIBCXX_STD_A::__mismatch(__first1, __last1, __first2,
1921 __gnu_cxx::__ops::__iter_equal_to_iter());
1940 template<
typename _InputIterator1,
typename _InputIterator2,
1941 typename _BinaryPredicate>
1942 _GLIBCXX20_CONSTEXPR
1943 inline pair<_InputIterator1, _InputIterator2>
1944 mismatch(_InputIterator1 __first1, _InputIterator1 __last1,
1945 _InputIterator2 __first2, _BinaryPredicate __binary_pred)
1948 __glibcxx_function_requires(_InputIteratorConcept<_InputIterator1>)
1949 __glibcxx_function_requires(_InputIteratorConcept<_InputIterator2>)
1950 __glibcxx_requires_valid_range(__first1, __last1);
1952 return _GLIBCXX_STD_A::__mismatch(__first1, __last1, __first2,
1953 __gnu_cxx::__ops::__iter_comp_iter(__binary_pred));
1956#if __cplusplus > 201103L
1958 template<
typename _InputIterator1,
typename _InputIterator2,
1959 typename _BinaryPredicate>
1960 _GLIBCXX20_CONSTEXPR
1961 pair<_InputIterator1, _InputIterator2>
1962 __mismatch(_InputIterator1 __first1, _InputIterator1 __last1,
1963 _InputIterator2 __first2, _InputIterator2 __last2,
1964 _BinaryPredicate __binary_pred)
1966 while (__first1 != __last1 && __first2 != __last2
1967 && __binary_pred(__first1, __first2))
1972 return pair<_InputIterator1, _InputIterator2>(__first1, __first2);
1989 template<
typename _InputIterator1,
typename _InputIterator2>
1990 _GLIBCXX20_CONSTEXPR
1991 inline pair<_InputIterator1, _InputIterator2>
1992 mismatch(_InputIterator1 __first1, _InputIterator1 __last1,
1993 _InputIterator2 __first2, _InputIterator2 __last2)
1996 __glibcxx_function_requires(_InputIteratorConcept<_InputIterator1>)
1997 __glibcxx_function_requires(_InputIteratorConcept<_InputIterator2>)
1998 __glibcxx_function_requires(_EqualOpConcept<
2001 __glibcxx_requires_valid_range(__first1, __last1);
2002 __glibcxx_requires_valid_range(__first2, __last2);
2004 return _GLIBCXX_STD_A::__mismatch(__first1, __last1, __first2, __last2,
2005 __gnu_cxx::__ops::__iter_equal_to_iter());
2025 template<
typename _InputIterator1,
typename _InputIterator2,
2026 typename _BinaryPredicate>
2027 _GLIBCXX20_CONSTEXPR
2028 inline pair<_InputIterator1, _InputIterator2>
2029 mismatch(_InputIterator1 __first1, _InputIterator1 __last1,
2030 _InputIterator2 __first2, _InputIterator2 __last2,
2031 _BinaryPredicate __binary_pred)
2034 __glibcxx_function_requires(_InputIteratorConcept<_InputIterator1>)
2035 __glibcxx_function_requires(_InputIteratorConcept<_InputIterator2>)
2036 __glibcxx_requires_valid_range(__first1, __last1);
2037 __glibcxx_requires_valid_range(__first2, __last2);
2039 return _GLIBCXX_STD_A::__mismatch(__first1, __last1, __first2, __last2,
2040 __gnu_cxx::__ops::__iter_comp_iter(__binary_pred));
2044_GLIBCXX_END_NAMESPACE_ALGO
2047 template<
typename _InputIterator,
typename _Predicate>
2048 _GLIBCXX20_CONSTEXPR
2049 inline _InputIterator
2053 while (__first != __last && !__pred(__first))
2059 template<
typename _RandomAccessIterator,
typename _Predicate>
2060 _GLIBCXX20_CONSTEXPR
2061 _RandomAccessIterator
2062 __find_if(_RandomAccessIterator __first, _RandomAccessIterator __last,
2066 __trip_count = (__last - __first) >> 2;
2068 for (; __trip_count > 0; --__trip_count)
2070 if (__pred(__first))
2074 if (__pred(__first))
2078 if (__pred(__first))
2082 if (__pred(__first))
2087 switch (__last - __first)
2090 if (__pred(__first))
2095 if (__pred(__first))
2100 if (__pred(__first))
2110 template<
typename _Iterator,
typename _Predicate>
2111 _GLIBCXX20_CONSTEXPR
2113 __find_if(_Iterator __first, _Iterator __last, _Predicate __pred)
2115 return __find_if(__first, __last, __pred,
2119 template<
typename _InputIterator,
typename _Predicate>
2120 _GLIBCXX20_CONSTEXPR
2121 typename iterator_traits<_InputIterator>::difference_type
2122 __count_if(_InputIterator __first, _InputIterator __last, _Predicate __pred)
2124 typename iterator_traits<_InputIterator>::difference_type __n = 0;
2125 for (; __first != __last; ++__first)
2126 if (__pred(__first))
2131 template<
typename _ForwardIterator,
typename _Predicate>
2132 _GLIBCXX20_CONSTEXPR
2134 __remove_if(_ForwardIterator __first, _ForwardIterator __last,
2138 if (__first == __last)
2140 _ForwardIterator __result = __first;
2142 for (; __first != __last; ++__first)
2143 if (!__pred(__first))
2145 *__result = _GLIBCXX_MOVE(*__first);
2151#if __cplusplus >= 201103L
2152 template<
typename _ForwardIterator1,
typename _ForwardIterator2,
2153 typename _BinaryPredicate>
2154 _GLIBCXX20_CONSTEXPR
2156 __is_permutation(_ForwardIterator1 __first1, _ForwardIterator1 __last1,
2157 _ForwardIterator2 __first2, _BinaryPredicate __pred)
2161 for (; __first1 != __last1; ++__first1, (void)++__first2)
2162 if (!__pred(__first1, __first2))
2165 if (__first1 == __last1)
2170 _ForwardIterator2 __last2 = __first2;
2172 for (_ForwardIterator1 __scan = __first1; __scan != __last1; ++__scan)
2175 __gnu_cxx::__ops::__iter_comp_iter(__pred, __scan)))
2179 = std::__count_if(__first2, __last2,
2180 __gnu_cxx::__ops::__iter_comp_iter(__pred, __scan));
2181 if (0 == __matches ||
2182 std::__count_if(__scan, __last1,
2183 __gnu_cxx::__ops::__iter_comp_iter(__pred, __scan))
2202 template<
typename _ForwardIterator1,
typename _ForwardIterator2>
2203 _GLIBCXX20_CONSTEXPR
2205 is_permutation(_ForwardIterator1 __first1, _ForwardIterator1 __last1,
2206 _ForwardIterator2 __first2)
2209 __glibcxx_function_requires(_ForwardIteratorConcept<_ForwardIterator1>)
2210 __glibcxx_function_requires(_ForwardIteratorConcept<_ForwardIterator2>)
2211 __glibcxx_function_requires(_EqualOpConcept<
2214 __glibcxx_requires_valid_range(__first1, __last1);
2216 return std::__is_permutation(__first1, __last1, __first2,
2217 __gnu_cxx::__ops::__iter_equal_to_iter());
2221_GLIBCXX_END_NAMESPACE_VERSION
2227#ifdef _GLIBCXX_PARALLEL
Parallel STL function calls corresponding to the stl_algobase.h header. The functions defined here ma...
typename make_unsigned< _Tp >::type make_unsigned_t
Alias template for make_unsigned.
constexpr bool is_constant_evaluated() noexcept
Returns true only when called during constant evaluation.
constexpr std::remove_reference< _Tp >::type && move(_Tp &&__t) noexcept
Convert a value to an rvalue.
constexpr _BI2 move_backward(_BI1 __first, _BI1 __last, _BI2 __result)
Moves the range [first,last) into result.
constexpr const _Tp & max(const _Tp &, const _Tp &)
This does what you think it does.
constexpr const _Tp & min(const _Tp &, const _Tp &)
This does what you think it does.
constexpr iterator_traits< _Iter >::iterator_category __iterator_category(const _Iter &)
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 __lg(_Tp __n)
This is a helper function for the sort routines and for random.tcc.
constexpr _InputIterator __find_if(_InputIterator __first, _InputIterator __last, _Predicate __pred, input_iterator_tag)
This is an overload used by find algos for the Input Iterator case.
constexpr void advance(_InputIterator &__i, _Distance __n)
A generalization of pointer arithmetic.
is_nothrow_copy_constructible
Traits class for iterators.
Marking output iterators.
Random-access iterators support a superset of bidirectional iterator operations.