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;
395 template<
typename _Tp,
typename _Up>
397 __assign_one(_Tp* __to, _Up* __from)
401#if __cplusplus >= 201103L
403 struct __copy_move<true, false, random_access_iterator_tag>
405 template<
typename _II,
typename _OI>
408 __copy_m(_II __first, _II __last, _OI __result)
410 typedef typename iterator_traits<_II>::difference_type _Distance;
411 for(_Distance __n = __last - __first; __n > 0; --__n)
420 template<
typename _Tp,
typename _Up>
422 __assign_one(_Tp* __to, _Up* __from)
427 template<
bool _IsMove>
428 struct __copy_move<_IsMove, true, random_access_iterator_tag>
430 template<
typename _Tp,
typename _Up>
433 __copy_m(_Tp* __first, _Tp* __last, _Up* __result)
435 const ptrdiff_t _Num = __last - __first;
436 if (__builtin_expect(_Num > 1,
true))
437 __builtin_memmove(__result, __first,
sizeof(_Tp) * _Num);
439 std::__copy_move<_IsMove, false, random_access_iterator_tag>::
440 __assign_one(__result, __first);
441 return __result + _Num;
445_GLIBCXX_BEGIN_NAMESPACE_CONTAINER
447 template<
typename _Tp,
typename _Ref,
typename _Ptr>
448 struct _Deque_iterator;
450 struct _Bit_iterator;
452_GLIBCXX_END_NAMESPACE_CONTAINER
457 template<
typename _CharT>
460 template<
typename _CharT,
typename _Traits>
461 class istreambuf_iterator;
463 template<
typename _CharT,
typename _Traits>
464 class ostreambuf_iterator;
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(_CharT*, _CharT*,
470 ostreambuf_iterator<_CharT, char_traits<_CharT> >);
472 template<
bool _IsMove,
typename _CharT>
473 typename __gnu_cxx::__enable_if<__is_char<_CharT>::__value,
474 ostreambuf_iterator<_CharT, char_traits<_CharT> > >::__type
475 __copy_move_a2(
const _CharT*,
const _CharT*,
476 ostreambuf_iterator<_CharT, char_traits<_CharT> >);
478 template<
bool _IsMove,
typename _CharT>
479 typename __gnu_cxx::__enable_if<__is_char<_CharT>::__value,
481 __copy_move_a2(istreambuf_iterator<_CharT, char_traits<_CharT> >,
482 istreambuf_iterator<_CharT, char_traits<_CharT> >, _CharT*);
484 template<
bool _IsMove,
typename _CharT>
485 typename __gnu_cxx::__enable_if<
486 __is_char<_CharT>::__value,
487 _GLIBCXX_STD_C::_Deque_iterator<_CharT, _CharT&, _CharT*> >::__type
489 istreambuf_iterator<_CharT, char_traits<_CharT> >,
490 istreambuf_iterator<_CharT, char_traits<_CharT> >,
491 _GLIBCXX_STD_C::_Deque_iterator<_CharT, _CharT&, _CharT*>);
494 template<
bool _IsMove,
typename _II,
typename _OI>
497 __copy_move_a2(_II __first, _II __last, _OI __result)
499 typedef typename iterator_traits<_II>::iterator_category _Category;
500#ifdef __cpp_lib_is_constant_evaluated
502 return std::__copy_move<_IsMove, false, _Category>::
503 __copy_m(__first, __last, __result);
505 return std::__copy_move<_IsMove, __memcpyable<_OI, _II>::__value,
506 _Category>::__copy_m(__first, __last, __result);
509 template<
bool _IsMove,
510 typename _Tp,
typename _Ref,
typename _Ptr,
typename _OI>
512 __copy_move_a1(_GLIBCXX_STD_C::_Deque_iterator<_Tp, _Ref, _Ptr>,
513 _GLIBCXX_STD_C::_Deque_iterator<_Tp, _Ref, _Ptr>,
516 template<
bool _IsMove,
517 typename _ITp,
typename _IRef,
typename _IPtr,
typename _OTp>
518 _GLIBCXX_STD_C::_Deque_iterator<_OTp, _OTp&, _OTp*>
519 __copy_move_a1(_GLIBCXX_STD_C::_Deque_iterator<_ITp, _IRef, _IPtr>,
520 _GLIBCXX_STD_C::_Deque_iterator<_ITp, _IRef, _IPtr>,
521 _GLIBCXX_STD_C::_Deque_iterator<_OTp, _OTp&, _OTp*>);
523 template<
bool _IsMove,
typename _II,
typename _Tp>
524 typename __gnu_cxx::__enable_if<
525 __is_random_access_iter<_II>::__value,
526 _GLIBCXX_STD_C::_Deque_iterator<_Tp, _Tp&, _Tp*> >::__type
527 __copy_move_a1(_II, _II, _GLIBCXX_STD_C::_Deque_iterator<_Tp, _Tp&, _Tp*>);
529 template<
bool _IsMove,
typename _II,
typename _OI>
532 __copy_move_a1(_II __first, _II __last, _OI __result)
533 {
return std::__copy_move_a2<_IsMove>(__first, __last, __result); }
535 template<
bool _IsMove,
typename _II,
typename _OI>
538 __copy_move_a(_II __first, _II __last, _OI __result)
540 return std::__niter_wrap(__result,
541 std::__copy_move_a1<_IsMove>(std::__niter_base(__first),
542 std::__niter_base(__last),
543 std::__niter_base(__result)));
546 template<
bool _IsMove,
547 typename _Ite,
typename _Seq,
typename _Cat,
typename _OI>
549 __copy_move_a(const ::__gnu_debug::_Safe_iterator<_Ite, _Seq, _Cat>&,
550 const ::__gnu_debug::_Safe_iterator<_Ite, _Seq, _Cat>&,
553 template<
bool _IsMove,
554 typename _II,
typename _Ite,
typename _Seq,
typename _Cat>
556 __copy_move_a(_II, _II,
557 const ::__gnu_debug::_Safe_iterator<_Ite, _Seq, _Cat>&);
559 template<
bool _IsMove,
560 typename _IIte,
typename _ISeq,
typename _ICat,
561 typename _OIte,
typename _OSeq,
typename _OCat>
563 __copy_move_a(const ::__gnu_debug::_Safe_iterator<_IIte, _ISeq, _ICat>&,
564 const ::__gnu_debug::_Safe_iterator<_IIte, _ISeq, _ICat>&,
565 const ::__gnu_debug::_Safe_iterator<_OIte, _OSeq, _OCat>&);
567 template<
typename _InputIterator,
typename _Size,
typename _OutputIterator>
570 __copy_n_a(_InputIterator __first, _Size __n, _OutputIterator __result,
577 *__result = *__first;
589 template<
typename _CharT,
typename _Size>
590 typename __gnu_cxx::__enable_if<
591 __is_char<_CharT>::__value, _CharT*>::__type
592 __copy_n_a(istreambuf_iterator<_CharT, char_traits<_CharT> >,
593 _Size, _CharT*,
bool);
595 template<
typename _CharT,
typename _Size>
596 typename __gnu_cxx::__enable_if<
597 __is_char<_CharT>::__value,
598 _GLIBCXX_STD_C::_Deque_iterator<_CharT, _CharT&, _CharT*> >::__type
599 __copy_n_a(istreambuf_iterator<_CharT, char_traits<_CharT> >, _Size,
600 _GLIBCXX_STD_C::_Deque_iterator<_CharT, _CharT&, _CharT*>,
621 template<
typename _II,
typename _OI>
624 copy(_II __first, _II __last, _OI __result)
627 __glibcxx_function_requires(_InputIteratorConcept<_II>)
628 __glibcxx_function_requires(_OutputIteratorConcept<_OI,
630 __glibcxx_requires_can_increment_range(__first, __last, __result);
632 return std::__copy_move_a<__is_move_iterator<_II>::__value>
633 (std::__miter_base(__first), std::__miter_base(__last), __result);
636#if __cplusplus >= 201103L
654 template<
typename _II,
typename _OI>
657 move(_II __first, _II __last, _OI __result)
660 __glibcxx_function_requires(_InputIteratorConcept<_II>)
661 __glibcxx_function_requires(_OutputIteratorConcept<_OI,
663 __glibcxx_requires_can_increment_range(__first, __last, __result);
665 return std::__copy_move_a<true>(std::__miter_base(__first),
666 std::__miter_base(__last), __result);
669#define _GLIBCXX_MOVE3(_Tp, _Up, _Vp) std::move(_Tp, _Up, _Vp)
671#define _GLIBCXX_MOVE3(_Tp, _Up, _Vp) std::copy(_Tp, _Up, _Vp)
674 template<
bool _IsMove,
bool _IsSimple,
typename _Category>
675 struct __copy_move_backward
677 template<
typename _BI1,
typename _BI2>
680 __copy_move_b(_BI1 __first, _BI1 __last, _BI2 __result)
682 while (__first != __last)
683 *--__result = *--__last;
688#if __cplusplus >= 201103L
689 template<
typename _Category>
690 struct __copy_move_backward<true, false, _Category>
692 template<
typename _BI1,
typename _BI2>
695 __copy_move_b(_BI1 __first, _BI1 __last, _BI2 __result)
697 while (__first != __last)
705 struct __copy_move_backward<false, false, random_access_iterator_tag>
707 template<
typename _BI1,
typename _BI2>
710 __copy_move_b(_BI1 __first, _BI1 __last, _BI2 __result)
712 typename iterator_traits<_BI1>::difference_type
713 __n = __last - __first;
714 for (; __n > 0; --__n)
715 *--__result = *--__last;
720#if __cplusplus >= 201103L
722 struct __copy_move_backward<true, false, random_access_iterator_tag>
724 template<
typename _BI1,
typename _BI2>
727 __copy_move_b(_BI1 __first, _BI1 __last, _BI2 __result)
729 typename iterator_traits<_BI1>::difference_type
730 __n = __last - __first;
731 for (; __n > 0; --__n)
738 template<
bool _IsMove>
739 struct __copy_move_backward<_IsMove, true, random_access_iterator_tag>
741 template<
typename _Tp,
typename _Up>
744 __copy_move_b(_Tp* __first, _Tp* __last, _Up* __result)
746 const ptrdiff_t _Num = __last - __first;
747 if (__builtin_expect(_Num > 1,
true))
748 __builtin_memmove(__result - _Num, __first,
sizeof(_Tp) * _Num);
750 std::__copy_move<_IsMove, false, random_access_iterator_tag>::
751 __assign_one(__result - 1, __first);
752 return __result - _Num;
756 template<
bool _IsMove,
typename _BI1,
typename _BI2>
759 __copy_move_backward_a2(_BI1 __first, _BI1 __last, _BI2 __result)
761 typedef typename iterator_traits<_BI1>::iterator_category _Category;
762#ifdef __cpp_lib_is_constant_evaluated
764 return std::__copy_move_backward<_IsMove, false, _Category>::
765 __copy_move_b(__first, __last, __result);
767 return std::__copy_move_backward<_IsMove,
768 __memcpyable<_BI2, _BI1>::__value,
769 _Category>::__copy_move_b(__first,
774 template<
bool _IsMove,
typename _BI1,
typename _BI2>
777 __copy_move_backward_a1(_BI1 __first, _BI1 __last, _BI2 __result)
778 {
return std::__copy_move_backward_a2<_IsMove>(__first, __last, __result); }
780 template<
bool _IsMove,
781 typename _Tp,
typename _Ref,
typename _Ptr,
typename _OI>
783 __copy_move_backward_a1(_GLIBCXX_STD_C::_Deque_iterator<_Tp, _Ref, _Ptr>,
784 _GLIBCXX_STD_C::_Deque_iterator<_Tp, _Ref, _Ptr>,
787 template<
bool _IsMove,
788 typename _ITp,
typename _IRef,
typename _IPtr,
typename _OTp>
789 _GLIBCXX_STD_C::_Deque_iterator<_OTp, _OTp&, _OTp*>
790 __copy_move_backward_a1(
791 _GLIBCXX_STD_C::_Deque_iterator<_ITp, _IRef, _IPtr>,
792 _GLIBCXX_STD_C::_Deque_iterator<_ITp, _IRef, _IPtr>,
793 _GLIBCXX_STD_C::_Deque_iterator<_OTp, _OTp&, _OTp*>);
795 template<
bool _IsMove,
typename _II,
typename _Tp>
796 typename __gnu_cxx::__enable_if<
797 __is_random_access_iter<_II>::__value,
798 _GLIBCXX_STD_C::_Deque_iterator<_Tp, _Tp&, _Tp*> >::__type
799 __copy_move_backward_a1(_II, _II,
800 _GLIBCXX_STD_C::_Deque_iterator<_Tp, _Tp&, _Tp*>);
802 template<
bool _IsMove,
typename _II,
typename _OI>
805 __copy_move_backward_a(_II __first, _II __last, _OI __result)
807 return std::__niter_wrap(__result,
808 std::__copy_move_backward_a1<_IsMove>
809 (std::__niter_base(__first), std::__niter_base(__last),
810 std::__niter_base(__result)));
813 template<
bool _IsMove,
814 typename _Ite,
typename _Seq,
typename _Cat,
typename _OI>
816 __copy_move_backward_a(
817 const ::__gnu_debug::_Safe_iterator<_Ite, _Seq, _Cat>&,
818 const ::__gnu_debug::_Safe_iterator<_Ite, _Seq, _Cat>&,
821 template<
bool _IsMove,
822 typename _II,
typename _Ite,
typename _Seq,
typename _Cat>
824 __copy_move_backward_a(_II, _II,
825 const ::__gnu_debug::_Safe_iterator<_Ite, _Seq, _Cat>&);
827 template<
bool _IsMove,
828 typename _IIte,
typename _ISeq,
typename _ICat,
829 typename _OIte,
typename _OSeq,
typename _OCat>
831 __copy_move_backward_a(
832 const ::__gnu_debug::_Safe_iterator<_IIte, _ISeq, _ICat>&,
833 const ::__gnu_debug::_Safe_iterator<_IIte, _ISeq, _ICat>&,
834 const ::__gnu_debug::_Safe_iterator<_OIte, _OSeq, _OCat>&);
854 template<
typename _BI1,
typename _BI2>
857 copy_backward(_BI1 __first, _BI1 __last, _BI2 __result)
860 __glibcxx_function_requires(_BidirectionalIteratorConcept<_BI1>)
861 __glibcxx_function_requires(_Mutable_BidirectionalIteratorConcept<_BI2>)
862 __glibcxx_function_requires(_OutputIteratorConcept<_BI2,
864 __glibcxx_requires_can_decrement_range(__first, __last, __result);
866 return std::__copy_move_backward_a<__is_move_iterator<_BI1>::__value>
867 (std::__miter_base(__first), std::__miter_base(__last), __result);
870#if __cplusplus >= 201103L
889 template<
typename _BI1,
typename _BI2>
895 __glibcxx_function_requires(_BidirectionalIteratorConcept<_BI1>)
896 __glibcxx_function_requires(_Mutable_BidirectionalIteratorConcept<_BI2>)
897 __glibcxx_function_requires(_OutputIteratorConcept<_BI2,
899 __glibcxx_requires_can_decrement_range(__first, __last, __result);
901 return std::__copy_move_backward_a<true>(std::__miter_base(__first),
902 std::__miter_base(__last),
906#define _GLIBCXX_MOVE_BACKWARD3(_Tp, _Up, _Vp) std::move_backward(_Tp, _Up, _Vp)
908#define _GLIBCXX_MOVE_BACKWARD3(_Tp, _Up, _Vp) std::copy_backward(_Tp, _Up, _Vp)
911 template<
typename _ForwardIterator,
typename _Tp>
914 __gnu_cxx::__enable_if<!__is_scalar<_Tp>::__value,
void>::__type
915 __fill_a1(_ForwardIterator __first, _ForwardIterator __last,
918 for (; __first != __last; ++__first)
922 template<
typename _ForwardIterator,
typename _Tp>
925 __gnu_cxx::__enable_if<__is_scalar<_Tp>::__value,
void>::__type
926 __fill_a1(_ForwardIterator __first, _ForwardIterator __last,
929 const _Tp __tmp = __value;
930 for (; __first != __last; ++__first)
935 template<
typename _Tp>
938 __gnu_cxx::__enable_if<__is_byte<_Tp>::__value,
void>::__type
939 __fill_a1(_Tp* __first, _Tp* __last,
const _Tp& __c)
941 const _Tp __tmp = __c;
942#if __cpp_lib_is_constant_evaluated
945 for (; __first != __last; ++__first)
950 if (
const size_t __len = __last - __first)
951 __builtin_memset(__first,
static_cast<unsigned char>(__tmp), __len);
954 template<
typename _Ite,
typename _Cont,
typename _Tp>
957 __fill_a1(::__gnu_cxx::__normal_iterator<_Ite, _Cont> __first,
958 ::__gnu_cxx::__normal_iterator<_Ite, _Cont> __last,
960 { std::__fill_a1(__first.base(), __last.base(), __value); }
962 template<
typename _Tp,
typename _VTp>
964 __fill_a1(
const _GLIBCXX_STD_C::_Deque_iterator<_Tp, _Tp&, _Tp*>&,
965 const _GLIBCXX_STD_C::_Deque_iterator<_Tp, _Tp&, _Tp*>&,
970 __fill_a1(_GLIBCXX_STD_C::_Bit_iterator, _GLIBCXX_STD_C::_Bit_iterator,
973 template<
typename _FIte,
typename _Tp>
976 __fill_a(_FIte __first, _FIte __last,
const _Tp& __value)
977 { std::__fill_a1(__first, __last, __value); }
979 template<
typename _Ite,
typename _Seq,
typename _Cat,
typename _Tp>
981 __fill_a(const ::__gnu_debug::_Safe_iterator<_Ite, _Seq, _Cat>&,
982 const ::__gnu_debug::_Safe_iterator<_Ite, _Seq, _Cat>&,
997 template<
typename _ForwardIterator,
typename _Tp>
1000 fill(_ForwardIterator __first, _ForwardIterator __last,
const _Tp& __value)
1003 __glibcxx_function_requires(_Mutable_ForwardIteratorConcept<
1005 __glibcxx_requires_valid_range(__first, __last);
1007 std::__fill_a(__first, __last, __value);
1011 inline _GLIBCXX_CONSTEXPR
int
1012 __size_to_integer(
int __n) {
return __n; }
1013 inline _GLIBCXX_CONSTEXPR
unsigned
1014 __size_to_integer(
unsigned __n) {
return __n; }
1015 inline _GLIBCXX_CONSTEXPR
long
1016 __size_to_integer(
long __n) {
return __n; }
1017 inline _GLIBCXX_CONSTEXPR
unsigned long
1018 __size_to_integer(
unsigned long __n) {
return __n; }
1019 inline _GLIBCXX_CONSTEXPR
long long
1020 __size_to_integer(
long long __n) {
return __n; }
1021 inline _GLIBCXX_CONSTEXPR
unsigned long long
1022 __size_to_integer(
unsigned long long __n) {
return __n; }
1024#if defined(__GLIBCXX_TYPE_INT_N_0)
1025 __extension__
inline _GLIBCXX_CONSTEXPR __GLIBCXX_TYPE_INT_N_0
1026 __size_to_integer(__GLIBCXX_TYPE_INT_N_0 __n) {
return __n; }
1027 __extension__
inline _GLIBCXX_CONSTEXPR
unsigned __GLIBCXX_TYPE_INT_N_0
1028 __size_to_integer(
unsigned __GLIBCXX_TYPE_INT_N_0 __n) {
return __n; }
1030#if defined(__GLIBCXX_TYPE_INT_N_1)
1031 __extension__
inline _GLIBCXX_CONSTEXPR __GLIBCXX_TYPE_INT_N_1
1032 __size_to_integer(__GLIBCXX_TYPE_INT_N_1 __n) {
return __n; }
1033 __extension__
inline _GLIBCXX_CONSTEXPR
unsigned __GLIBCXX_TYPE_INT_N_1
1034 __size_to_integer(
unsigned __GLIBCXX_TYPE_INT_N_1 __n) {
return __n; }
1036#if defined(__GLIBCXX_TYPE_INT_N_2)
1037 __extension__
inline _GLIBCXX_CONSTEXPR __GLIBCXX_TYPE_INT_N_2
1038 __size_to_integer(__GLIBCXX_TYPE_INT_N_2 __n) {
return __n; }
1039 __extension__
inline _GLIBCXX_CONSTEXPR
unsigned __GLIBCXX_TYPE_INT_N_2
1040 __size_to_integer(
unsigned __GLIBCXX_TYPE_INT_N_2 __n) {
return __n; }
1042#if defined(__GLIBCXX_TYPE_INT_N_3)
1043 __extension__
inline _GLIBCXX_CONSTEXPR
unsigned __GLIBCXX_TYPE_INT_N_3
1044 __size_to_integer(__GLIBCXX_TYPE_INT_N_3 __n) {
return __n; }
1045 __extension__
inline _GLIBCXX_CONSTEXPR __GLIBCXX_TYPE_INT_N_3
1046 __size_to_integer(
unsigned __GLIBCXX_TYPE_INT_N_3 __n) {
return __n; }
1049 inline _GLIBCXX_CONSTEXPR
long long
1050 __size_to_integer(
float __n) {
return (
long long)__n; }
1051 inline _GLIBCXX_CONSTEXPR
long long
1052 __size_to_integer(
double __n) {
return (
long long)__n; }
1053 inline _GLIBCXX_CONSTEXPR
long long
1054 __size_to_integer(
long double __n) {
return (
long long)__n; }
1055#if !defined(__STRICT_ANSI__) && defined(_GLIBCXX_USE_FLOAT128)
1056 __extension__
inline _GLIBCXX_CONSTEXPR
long long
1057 __size_to_integer(__float128 __n) {
return (
long long)__n; }
1060 template<
typename _OutputIterator,
typename _Size,
typename _Tp>
1061 _GLIBCXX20_CONSTEXPR
1063 __gnu_cxx::__enable_if<!__is_scalar<_Tp>::__value, _OutputIterator>::__type
1064 __fill_n_a1(_OutputIterator __first, _Size __n,
const _Tp& __value)
1066 for (; __n > 0; --__n, (void) ++__first)
1071 template<
typename _OutputIterator,
typename _Size,
typename _Tp>
1072 _GLIBCXX20_CONSTEXPR
1074 __gnu_cxx::__enable_if<__is_scalar<_Tp>::__value, _OutputIterator>::__type
1075 __fill_n_a1(_OutputIterator __first, _Size __n,
const _Tp& __value)
1077 const _Tp __tmp = __value;
1078 for (; __n > 0; --__n, (void) ++__first)
1083 template<
typename _Ite,
typename _Seq,
typename _Cat,
typename _Size,
1086 __fill_n_a(const ::__gnu_debug::_Safe_iterator<_Ite, _Seq, _Cat>& __first,
1087 _Size __n,
const _Tp& __value,
1090 template<
typename _OutputIterator,
typename _Size,
typename _Tp>
1091 _GLIBCXX20_CONSTEXPR
1092 inline _OutputIterator
1093 __fill_n_a(_OutputIterator __first, _Size __n,
const _Tp& __value,
1096#if __cplusplus >= 201103L
1097 static_assert(is_integral<_Size>{},
"fill_n must pass integral size");
1099 return __fill_n_a1(__first, __n, __value);
1102 template<
typename _OutputIterator,
typename _Size,
typename _Tp>
1103 _GLIBCXX20_CONSTEXPR
1104 inline _OutputIterator
1105 __fill_n_a(_OutputIterator __first, _Size __n,
const _Tp& __value,
1108#if __cplusplus >= 201103L
1109 static_assert(is_integral<_Size>{},
"fill_n must pass integral size");
1111 return __fill_n_a1(__first, __n, __value);
1114 template<
typename _OutputIterator,
typename _Size,
typename _Tp>
1115 _GLIBCXX20_CONSTEXPR
1116 inline _OutputIterator
1117 __fill_n_a(_OutputIterator __first, _Size __n,
const _Tp& __value,
1120#if __cplusplus >= 201103L
1121 static_assert(is_integral<_Size>{},
"fill_n must pass integral size");
1126 __glibcxx_requires_can_increment(__first, __n);
1128 std::__fill_a(__first, __first + __n, __value);
1129 return __first + __n;
1149 template<
typename _OI,
typename _Size,
typename _Tp>
1150 _GLIBCXX20_CONSTEXPR
1152 fill_n(_OI __first, _Size __n,
const _Tp& __value)
1155 __glibcxx_function_requires(_OutputIteratorConcept<_OI, const _Tp&>)
1157 return std::__fill_n_a(__first, std::__size_to_integer(__n), __value,
1161 template<
bool _BoolType>
1164 template<
typename _II1,
typename _II2>
1165 _GLIBCXX20_CONSTEXPR
1167 equal(_II1 __first1, _II1 __last1, _II2 __first2)
1169 for (; __first1 != __last1; ++__first1, (void) ++__first2)
1170 if (!(*__first1 == *__first2))
1177 struct __equal<true>
1179 template<
typename _Tp>
1180 _GLIBCXX20_CONSTEXPR
1182 equal(
const _Tp* __first1,
const _Tp* __last1,
const _Tp* __first2)
1184 if (
const size_t __len = (__last1 - __first1))
1185 return !std::__memcmp(__first1, __first2, __len);
1190 template<
typename _Tp,
typename _Ref,
typename _Ptr,
typename _II>
1191 typename __gnu_cxx::__enable_if<
1192 __is_random_access_iter<_II>::__value,
bool>::__type
1193 __equal_aux1(_GLIBCXX_STD_C::_Deque_iterator<_Tp, _Ref, _Ptr>,
1194 _GLIBCXX_STD_C::_Deque_iterator<_Tp, _Ref, _Ptr>,
1197 template<
typename _Tp1,
typename _Ref1,
typename _Ptr1,
1198 typename _Tp2,
typename _Ref2,
typename _Ptr2>
1200 __equal_aux1(_GLIBCXX_STD_C::_Deque_iterator<_Tp1, _Ref1, _Ptr1>,
1201 _GLIBCXX_STD_C::_Deque_iterator<_Tp1, _Ref1, _Ptr1>,
1202 _GLIBCXX_STD_C::_Deque_iterator<_Tp2, _Ref2, _Ptr2>);
1204 template<
typename _II,
typename _Tp,
typename _Ref,
typename _Ptr>
1205 typename __gnu_cxx::__enable_if<
1206 __is_random_access_iter<_II>::__value,
bool>::__type
1207 __equal_aux1(_II, _II,
1208 _GLIBCXX_STD_C::_Deque_iterator<_Tp, _Ref, _Ptr>);
1210 template<
typename _II1,
typename _II2>
1211 _GLIBCXX20_CONSTEXPR
1213 __equal_aux1(_II1 __first1, _II1 __last1, _II2 __first2)
1215 typedef typename iterator_traits<_II1>::value_type _ValueType1;
1216 const bool __simple = ((__is_integer<_ValueType1>::__value
1217 || __is_pointer<_ValueType1>::__value)
1218 && __memcmpable<_II1, _II2>::__value);
1219 return std::__equal<__simple>::equal(__first1, __last1, __first2);
1222 template<
typename _II1,
typename _II2>
1223 _GLIBCXX20_CONSTEXPR
1225 __equal_aux(_II1 __first1, _II1 __last1, _II2 __first2)
1227 return std::__equal_aux1(std::__niter_base(__first1),
1228 std::__niter_base(__last1),
1229 std::__niter_base(__first2));
1232 template<
typename _II1,
typename _Seq1,
typename _Cat1,
typename _II2>
1234 __equal_aux(const ::__gnu_debug::_Safe_iterator<_II1, _Seq1, _Cat1>&,
1235 const ::__gnu_debug::_Safe_iterator<_II1, _Seq1, _Cat1>&,
1238 template<
typename _II1,
typename _II2,
typename _Seq2,
typename _Cat2>
1240 __equal_aux(_II1, _II1,
1241 const ::__gnu_debug::_Safe_iterator<_II2, _Seq2, _Cat2>&);
1243 template<
typename _II1,
typename _Seq1,
typename _Cat1,
1244 typename _II2,
typename _Seq2,
typename _Cat2>
1246 __equal_aux(const ::__gnu_debug::_Safe_iterator<_II1, _Seq1, _Cat1>&,
1247 const ::__gnu_debug::_Safe_iterator<_II1, _Seq1, _Cat1>&,
1248 const ::__gnu_debug::_Safe_iterator<_II2, _Seq2, _Cat2>&);
1250 template<
typename,
typename>
1253 template<
typename _II1,
typename _II2>
1254 _GLIBCXX20_CONSTEXPR
1256 __newlast1(_II1, _II1 __last1, _II2, _II2)
1259 template<
typename _II>
1260 _GLIBCXX20_CONSTEXPR
1262 __cnd2(_II __first, _II __last)
1263 {
return __first != __last; }
1267 struct __lc_rai<random_access_iterator_tag, random_access_iterator_tag>
1269 template<
typename _RAI1,
typename _RAI2>
1270 _GLIBCXX20_CONSTEXPR
1272 __newlast1(_RAI1 __first1, _RAI1 __last1,
1273 _RAI2 __first2, _RAI2 __last2)
1275 const typename iterator_traits<_RAI1>::difference_type
1276 __diff1 = __last1 - __first1;
1277 const typename iterator_traits<_RAI2>::difference_type
1278 __diff2 = __last2 - __first2;
1279 return __diff2 < __diff1 ? __first1 + __diff2 : __last1;
1282 template<
typename _RAI>
1283 static _GLIBCXX20_CONSTEXPR
bool
1288 template<
typename _II1,
typename _II2,
typename _Compare>
1289 _GLIBCXX20_CONSTEXPR
1291 __lexicographical_compare_impl(_II1 __first1, _II1 __last1,
1292 _II2 __first2, _II2 __last2,
1295 typedef typename iterator_traits<_II1>::iterator_category _Category1;
1296 typedef typename iterator_traits<_II2>::iterator_category _Category2;
1297 typedef std::__lc_rai<_Category1, _Category2> __rai_type;
1299 __last1 = __rai_type::__newlast1(__first1, __last1, __first2, __last2);
1300 for (; __first1 != __last1 && __rai_type::__cnd2(__first2, __last2);
1301 ++__first1, (void)++__first2)
1303 if (__comp(__first1, __first2))
1305 if (__comp(__first2, __first1))
1308 return __first1 == __last1 && __first2 != __last2;
1311 template<
bool _BoolType>
1312 struct __lexicographical_compare
1314 template<
typename _II1,
typename _II2>
1315 _GLIBCXX20_CONSTEXPR
1317 __lc(_II1 __first1, _II1 __last1, _II2 __first2, _II2 __last2)
1319 using __gnu_cxx::__ops::__iter_less_iter;
1320 return std::__lexicographical_compare_impl(__first1, __last1,
1322 __iter_less_iter());
1325 template<
typename _II1,
typename _II2>
1326 _GLIBCXX20_CONSTEXPR
1328 __3way(_II1 __first1, _II1 __last1, _II2 __first2, _II2 __last2)
1330 while (__first1 != __last1)
1332 if (__first2 == __last2)
1334 if (*__first1 < *__first2)
1336 if (*__first2 < *__first1)
1341 return int(__first2 == __last2) - 1;
1346 struct __lexicographical_compare<true>
1348 template<
typename _Tp,
typename _Up>
1349 _GLIBCXX20_CONSTEXPR
1351 __lc(
const _Tp* __first1,
const _Tp* __last1,
1352 const _Up* __first2,
const _Up* __last2)
1353 {
return __3way(__first1, __last1, __first2, __last2) < 0; }
1355 template<
typename _Tp,
typename _Up>
1356 _GLIBCXX20_CONSTEXPR
1358 __3way(
const _Tp* __first1,
const _Tp* __last1,
1359 const _Up* __first2,
const _Up* __last2)
1361 const size_t __len1 = __last1 - __first1;
1362 const size_t __len2 = __last2 - __first2;
1363 if (
const size_t __len =
std::min(__len1, __len2))
1364 if (
int __result = std::__memcmp(__first1, __first2, __len))
1366 return ptrdiff_t(__len1 - __len2);
1370 template<
typename _II1,
typename _II2>
1371 _GLIBCXX20_CONSTEXPR
1373 __lexicographical_compare_aux1(_II1 __first1, _II1 __last1,
1374 _II2 __first2, _II2 __last2)
1376 typedef typename iterator_traits<_II1>::value_type _ValueType1;
1377 typedef typename iterator_traits<_II2>::value_type _ValueType2;
1378 const bool __simple =
1379 (__is_memcmp_ordered_with<_ValueType1, _ValueType2>::__value
1380 && __is_pointer<_II1>::__value
1381 && __is_pointer<_II2>::__value
1382#if __cplusplus > 201703L && __cpp_lib_concepts
1386 && !is_volatile_v<remove_reference_t<iter_reference_t<_II1>>>
1387 && !is_volatile_v<remove_reference_t<iter_reference_t<_II2>>>
1391 return std::__lexicographical_compare<__simple>::__lc(__first1, __last1,
1395 template<
typename _Tp1,
typename _Ref1,
typename _Ptr1,
1398 __lexicographical_compare_aux1(
1399 _GLIBCXX_STD_C::_Deque_iterator<_Tp1, _Ref1, _Ptr1>,
1400 _GLIBCXX_STD_C::_Deque_iterator<_Tp1, _Ref1, _Ptr1>,
1403 template<
typename _Tp1,
1404 typename _Tp2,
typename _Ref2,
typename _Ptr2>
1406 __lexicographical_compare_aux1(_Tp1*, _Tp1*,
1407 _GLIBCXX_STD_C::_Deque_iterator<_Tp2, _Ref2, _Ptr2>,
1408 _GLIBCXX_STD_C::_Deque_iterator<_Tp2, _Ref2, _Ptr2>);
1410 template<
typename _Tp1,
typename _Ref1,
typename _Ptr1,
1411 typename _Tp2,
typename _Ref2,
typename _Ptr2>
1413 __lexicographical_compare_aux1(
1414 _GLIBCXX_STD_C::_Deque_iterator<_Tp1, _Ref1, _Ptr1>,
1415 _GLIBCXX_STD_C::_Deque_iterator<_Tp1, _Ref1, _Ptr1>,
1416 _GLIBCXX_STD_C::_Deque_iterator<_Tp2, _Ref2, _Ptr2>,
1417 _GLIBCXX_STD_C::_Deque_iterator<_Tp2, _Ref2, _Ptr2>);
1419 template<
typename _II1,
typename _II2>
1420 _GLIBCXX20_CONSTEXPR
1422 __lexicographical_compare_aux(_II1 __first1, _II1 __last1,
1423 _II2 __first2, _II2 __last2)
1425 return std::__lexicographical_compare_aux1(std::__niter_base(__first1),
1426 std::__niter_base(__last1),
1427 std::__niter_base(__first2),
1428 std::__niter_base(__last2));
1431 template<
typename _Iter1,
typename _Seq1,
typename _Cat1,
1434 __lexicographical_compare_aux(
1435 const ::__gnu_debug::_Safe_iterator<_Iter1, _Seq1, _Cat1>&,
1436 const ::__gnu_debug::_Safe_iterator<_Iter1, _Seq1, _Cat1>&,
1439 template<
typename _II1,
1440 typename _Iter2,
typename _Seq2,
typename _Cat2>
1442 __lexicographical_compare_aux(
1444 const ::__gnu_debug::_Safe_iterator<_Iter2, _Seq2, _Cat2>&,
1445 const ::__gnu_debug::_Safe_iterator<_Iter2, _Seq2, _Cat2>&);
1447 template<
typename _Iter1,
typename _Seq1,
typename _Cat1,
1448 typename _Iter2,
typename _Seq2,
typename _Cat2>
1450 __lexicographical_compare_aux(
1451 const ::__gnu_debug::_Safe_iterator<_Iter1, _Seq1, _Cat1>&,
1452 const ::__gnu_debug::_Safe_iterator<_Iter1, _Seq1, _Cat1>&,
1453 const ::__gnu_debug::_Safe_iterator<_Iter2, _Seq2, _Cat2>&,
1454 const ::__gnu_debug::_Safe_iterator<_Iter2, _Seq2, _Cat2>&);
1456 template<
typename _ForwardIterator,
typename _Tp,
typename _Compare>
1457 _GLIBCXX20_CONSTEXPR
1459 __lower_bound(_ForwardIterator __first, _ForwardIterator __last,
1460 const _Tp& __val, _Compare __comp)
1462 typedef typename iterator_traits<_ForwardIterator>::difference_type
1469 _DistanceType __half = __len >> 1;
1470 _ForwardIterator __middle = __first;
1472 if (__comp(__middle, __val))
1476 __len = __len - __half - 1;
1495 template<
typename _ForwardIterator,
typename _Tp>
1496 _GLIBCXX20_CONSTEXPR
1497 inline _ForwardIterator
1498 lower_bound(_ForwardIterator __first, _ForwardIterator __last,
1502 __glibcxx_function_requires(_ForwardIteratorConcept<_ForwardIterator>)
1503 __glibcxx_function_requires(_LessThanOpConcept<
1505 __glibcxx_requires_partitioned_lower(__first, __last, __val);
1507 return std::__lower_bound(__first, __last, __val,
1508 __gnu_cxx::__ops::__iter_less_val());
1513 template<
typename _Tp>
1514 inline _GLIBCXX_CONSTEXPR _Tp
1517#if __cplusplus >= 201402L
1521 const int __sz =
sizeof(+__n);
1522 int __w = __sz * __CHAR_BIT__ - 1;
1523 if (__sz ==
sizeof(
long long))
1524 __w -= __builtin_clzll(+__n);
1525 else if (__sz ==
sizeof(
long))
1526 __w -= __builtin_clzl(+__n);
1527 else if (__sz ==
sizeof(
int))
1528 __w -= __builtin_clz(+__n);
1533_GLIBCXX_BEGIN_NAMESPACE_ALGO
1547 template<
typename _II1,
typename _II2>
1548 _GLIBCXX20_CONSTEXPR
1550 equal(_II1 __first1, _II1 __last1, _II2 __first2)
1553 __glibcxx_function_requires(_InputIteratorConcept<_II1>)
1554 __glibcxx_function_requires(_InputIteratorConcept<_II2>)
1555 __glibcxx_function_requires(_EqualOpConcept<
1558 __glibcxx_requires_can_increment_range(__first1, __last1, __first2);
1560 return std::__equal_aux(__first1, __last1, __first2);
1578 template<
typename _IIter1,
typename _IIter2,
typename _BinaryPredicate>
1579 _GLIBCXX20_CONSTEXPR
1581 equal(_IIter1 __first1, _IIter1 __last1,
1582 _IIter2 __first2, _BinaryPredicate __binary_pred)
1585 __glibcxx_function_requires(_InputIteratorConcept<_IIter1>)
1586 __glibcxx_function_requires(_InputIteratorConcept<_IIter2>)
1587 __glibcxx_requires_valid_range(__first1, __last1);
1589 for (; __first1 != __last1; ++__first1, (void)++__first2)
1590 if (!
bool(__binary_pred(*__first1, *__first2)))
1595#if __cplusplus >= 201103L
1597 template<
typename _II1,
typename _II2>
1598 _GLIBCXX20_CONSTEXPR
1600 __equal4(_II1 __first1, _II1 __last1, _II2 __first2, _II2 __last2)
1602 using _RATag = random_access_iterator_tag;
1603 using _Cat1 =
typename iterator_traits<_II1>::iterator_category;
1604 using _Cat2 =
typename iterator_traits<_II2>::iterator_category;
1605 using _RAIters = __and_<is_same<_Cat1, _RATag>, is_same<_Cat2, _RATag>>;
1612 return _GLIBCXX_STD_A::equal(__first1, __last1, __first2);
1615 for (; __first1 != __last1 && __first2 != __last2;
1616 ++__first1, (void)++__first2)
1617 if (!(*__first1 == *__first2))
1619 return __first1 == __last1 && __first2 == __last2;
1623 template<
typename _II1,
typename _II2,
typename _BinaryPredicate>
1624 _GLIBCXX20_CONSTEXPR
1626 __equal4(_II1 __first1, _II1 __last1, _II2 __first2, _II2 __last2,
1627 _BinaryPredicate __binary_pred)
1629 using _RATag = random_access_iterator_tag;
1630 using _Cat1 =
typename iterator_traits<_II1>::iterator_category;
1631 using _Cat2 =
typename iterator_traits<_II2>::iterator_category;
1632 using _RAIters = __and_<is_same<_Cat1, _RATag>, is_same<_Cat2, _RATag>>;
1639 return _GLIBCXX_STD_A::equal(__first1, __last1, __first2,
1643 for (; __first1 != __last1 && __first2 != __last2;
1644 ++__first1, (void)++__first2)
1645 if (!
bool(__binary_pred(*__first1, *__first2)))
1647 return __first1 == __last1 && __first2 == __last2;
1651#if __cplusplus > 201103L
1653#define __cpp_lib_robust_nonmodifying_seq_ops 201304L
1668 template<
typename _II1,
typename _II2>
1669 _GLIBCXX20_CONSTEXPR
1671 equal(_II1 __first1, _II1 __last1, _II2 __first2, _II2 __last2)
1674 __glibcxx_function_requires(_InputIteratorConcept<_II1>)
1675 __glibcxx_function_requires(_InputIteratorConcept<_II2>)
1676 __glibcxx_function_requires(_EqualOpConcept<
1679 __glibcxx_requires_valid_range(__first1, __last1);
1680 __glibcxx_requires_valid_range(__first2, __last2);
1682 return _GLIBCXX_STD_A::__equal4(__first1, __last1, __first2, __last2);
1701 template<
typename _IIter1,
typename _IIter2,
typename _BinaryPredicate>
1702 _GLIBCXX20_CONSTEXPR
1704 equal(_IIter1 __first1, _IIter1 __last1,
1705 _IIter2 __first2, _IIter2 __last2, _BinaryPredicate __binary_pred)
1708 __glibcxx_function_requires(_InputIteratorConcept<_IIter1>)
1709 __glibcxx_function_requires(_InputIteratorConcept<_IIter2>)
1710 __glibcxx_requires_valid_range(__first1, __last1);
1711 __glibcxx_requires_valid_range(__first2, __last2);
1713 return _GLIBCXX_STD_A::__equal4(__first1, __last1, __first2, __last2,
1733 template<
typename _II1,
typename _II2>
1734 _GLIBCXX20_CONSTEXPR
1736 lexicographical_compare(_II1 __first1, _II1 __last1,
1737 _II2 __first2, _II2 __last2)
1739#ifdef _GLIBCXX_CONCEPT_CHECKS
1744 __glibcxx_function_requires(_InputIteratorConcept<_II1>)
1745 __glibcxx_function_requires(_InputIteratorConcept<_II2>)
1746 __glibcxx_function_requires(_LessThanOpConcept<_ValueType1, _ValueType2>)
1747 __glibcxx_function_requires(_LessThanOpConcept<_ValueType2, _ValueType1>)
1748 __glibcxx_requires_valid_range(__first1, __last1);
1749 __glibcxx_requires_valid_range(__first2, __last2);
1751 return std::__lexicographical_compare_aux(__first1, __last1,
1768 template<
typename _II1,
typename _II2,
typename _Compare>
1769 _GLIBCXX20_CONSTEXPR
1771 lexicographical_compare(_II1 __first1, _II1 __last1,
1772 _II2 __first2, _II2 __last2, _Compare __comp)
1775 __glibcxx_function_requires(_InputIteratorConcept<_II1>)
1776 __glibcxx_function_requires(_InputIteratorConcept<_II2>)
1777 __glibcxx_requires_valid_range(__first1, __last1);
1778 __glibcxx_requires_valid_range(__first2, __last2);
1780 return std::__lexicographical_compare_impl
1781 (__first1, __last1, __first2, __last2,
1782 __gnu_cxx::__ops::__iter_comp_iter(__comp));
1785#if __cpp_lib_three_way_comparison
1788 template<
typename _Iter>
1789 concept __is_byte_iter = contiguous_iterator<_Iter>
1790 && __is_memcmp_ordered<iter_value_t<_Iter>>::__value;
1794 template<
typename _Tp>
1796 __min_cmp(_Tp __x, _Tp __y)
1800 decltype(__x <=> __y) _M_cmp;
1802 auto __c = __x <=> __y;
1804 return _Res{__y, __c};
1805 return _Res{__x, __c};
1819 template<
typename _InputIter1,
typename _InputIter2,
typename _Comp>
1821 lexicographical_compare_three_way(_InputIter1 __first1,
1822 _InputIter1 __last1,
1823 _InputIter2 __first2,
1824 _InputIter2 __last2,
1826 ->
decltype(__comp(*__first1, *__first2))
1829 __glibcxx_function_requires(_InputIteratorConcept<_InputIter1>)
1830 __glibcxx_function_requires(_InputIteratorConcept<_InputIter2>)
1831 __glibcxx_requires_valid_range(__first1, __last1);
1832 __glibcxx_requires_valid_range(__first2, __last2);
1834 using _Cat =
decltype(__comp(*__first1, *__first2));
1835 static_assert(same_as<common_comparison_category_t<_Cat>, _Cat>);
1837 if (!std::__is_constant_evaluated())
1838 if constexpr (same_as<_Comp, __detail::_Synth3way>
1839 || same_as<_Comp, compare_three_way>)
1840 if constexpr (__is_byte_iter<_InputIter1>)
1841 if constexpr (__is_byte_iter<_InputIter2>)
1843 const auto [__len, __lencmp] = _GLIBCXX_STD_A::
1844 __min_cmp(__last1 - __first1, __last2 - __first2);
1848 = __builtin_memcmp(&*__first1, &*__first2, __len) <=> 0;
1855 while (__first1 != __last1)
1857 if (__first2 == __last2)
1858 return strong_ordering::greater;
1859 if (
auto __cmp = __comp(*__first1, *__first2); __cmp != 0)
1864 return (__first2 == __last2) <=>
true;
1867 template<
typename _InputIter1,
typename _InputIter2>
1869 lexicographical_compare_three_way(_InputIter1 __first1,
1870 _InputIter1 __last1,
1871 _InputIter2 __first2,
1872 _InputIter2 __last2)
1874 return _GLIBCXX_STD_A::
1875 lexicographical_compare_three_way(__first1, __last1, __first2, __last2,
1876 compare_three_way{});
1880 template<
typename _InputIterator1,
typename _InputIterator2,
1881 typename _BinaryPredicate>
1882 _GLIBCXX20_CONSTEXPR
1883 pair<_InputIterator1, _InputIterator2>
1884 __mismatch(_InputIterator1 __first1, _InputIterator1 __last1,
1885 _InputIterator2 __first2, _BinaryPredicate __binary_pred)
1887 while (__first1 != __last1 && __binary_pred(__first1, __first2))
1892 return pair<_InputIterator1, _InputIterator2>(__first1, __first2);
1908 template<
typename _InputIterator1,
typename _InputIterator2>
1909 _GLIBCXX20_CONSTEXPR
1910 inline pair<_InputIterator1, _InputIterator2>
1911 mismatch(_InputIterator1 __first1, _InputIterator1 __last1,
1912 _InputIterator2 __first2)
1915 __glibcxx_function_requires(_InputIteratorConcept<_InputIterator1>)
1916 __glibcxx_function_requires(_InputIteratorConcept<_InputIterator2>)
1917 __glibcxx_function_requires(_EqualOpConcept<
1920 __glibcxx_requires_valid_range(__first1, __last1);
1922 return _GLIBCXX_STD_A::__mismatch(__first1, __last1, __first2,
1923 __gnu_cxx::__ops::__iter_equal_to_iter());
1942 template<
typename _InputIterator1,
typename _InputIterator2,
1943 typename _BinaryPredicate>
1944 _GLIBCXX20_CONSTEXPR
1945 inline pair<_InputIterator1, _InputIterator2>
1946 mismatch(_InputIterator1 __first1, _InputIterator1 __last1,
1947 _InputIterator2 __first2, _BinaryPredicate __binary_pred)
1950 __glibcxx_function_requires(_InputIteratorConcept<_InputIterator1>)
1951 __glibcxx_function_requires(_InputIteratorConcept<_InputIterator2>)
1952 __glibcxx_requires_valid_range(__first1, __last1);
1954 return _GLIBCXX_STD_A::__mismatch(__first1, __last1, __first2,
1955 __gnu_cxx::__ops::__iter_comp_iter(__binary_pred));
1958#if __cplusplus > 201103L
1960 template<
typename _InputIterator1,
typename _InputIterator2,
1961 typename _BinaryPredicate>
1962 _GLIBCXX20_CONSTEXPR
1963 pair<_InputIterator1, _InputIterator2>
1964 __mismatch(_InputIterator1 __first1, _InputIterator1 __last1,
1965 _InputIterator2 __first2, _InputIterator2 __last2,
1966 _BinaryPredicate __binary_pred)
1968 while (__first1 != __last1 && __first2 != __last2
1969 && __binary_pred(__first1, __first2))
1974 return pair<_InputIterator1, _InputIterator2>(__first1, __first2);
1991 template<
typename _InputIterator1,
typename _InputIterator2>
1992 _GLIBCXX20_CONSTEXPR
1993 inline pair<_InputIterator1, _InputIterator2>
1994 mismatch(_InputIterator1 __first1, _InputIterator1 __last1,
1995 _InputIterator2 __first2, _InputIterator2 __last2)
1998 __glibcxx_function_requires(_InputIteratorConcept<_InputIterator1>)
1999 __glibcxx_function_requires(_InputIteratorConcept<_InputIterator2>)
2000 __glibcxx_function_requires(_EqualOpConcept<
2003 __glibcxx_requires_valid_range(__first1, __last1);
2004 __glibcxx_requires_valid_range(__first2, __last2);
2006 return _GLIBCXX_STD_A::__mismatch(__first1, __last1, __first2, __last2,
2007 __gnu_cxx::__ops::__iter_equal_to_iter());
2027 template<
typename _InputIterator1,
typename _InputIterator2,
2028 typename _BinaryPredicate>
2029 _GLIBCXX20_CONSTEXPR
2030 inline pair<_InputIterator1, _InputIterator2>
2031 mismatch(_InputIterator1 __first1, _InputIterator1 __last1,
2032 _InputIterator2 __first2, _InputIterator2 __last2,
2033 _BinaryPredicate __binary_pred)
2036 __glibcxx_function_requires(_InputIteratorConcept<_InputIterator1>)
2037 __glibcxx_function_requires(_InputIteratorConcept<_InputIterator2>)
2038 __glibcxx_requires_valid_range(__first1, __last1);
2039 __glibcxx_requires_valid_range(__first2, __last2);
2041 return _GLIBCXX_STD_A::__mismatch(__first1, __last1, __first2, __last2,
2042 __gnu_cxx::__ops::__iter_comp_iter(__binary_pred));
2046_GLIBCXX_END_NAMESPACE_ALGO
2049 template<
typename _InputIterator,
typename _Predicate>
2050 _GLIBCXX20_CONSTEXPR
2051 inline _InputIterator
2055 while (__first != __last && !__pred(__first))
2061 template<
typename _RandomAccessIterator,
typename _Predicate>
2062 _GLIBCXX20_CONSTEXPR
2063 _RandomAccessIterator
2064 __find_if(_RandomAccessIterator __first, _RandomAccessIterator __last,
2068 __trip_count = (__last - __first) >> 2;
2070 for (; __trip_count > 0; --__trip_count)
2072 if (__pred(__first))
2076 if (__pred(__first))
2080 if (__pred(__first))
2084 if (__pred(__first))
2089 switch (__last - __first)
2092 if (__pred(__first))
2097 if (__pred(__first))
2102 if (__pred(__first))
2112 template<
typename _Iterator,
typename _Predicate>
2113 _GLIBCXX20_CONSTEXPR
2115 __find_if(_Iterator __first, _Iterator __last, _Predicate __pred)
2117 return __find_if(__first, __last, __pred,
2121 template<
typename _InputIterator,
typename _Predicate>
2122 _GLIBCXX20_CONSTEXPR
2123 typename iterator_traits<_InputIterator>::difference_type
2124 __count_if(_InputIterator __first, _InputIterator __last, _Predicate __pred)
2126 typename iterator_traits<_InputIterator>::difference_type __n = 0;
2127 for (; __first != __last; ++__first)
2128 if (__pred(__first))
2133 template<
typename _ForwardIterator,
typename _Predicate>
2134 _GLIBCXX20_CONSTEXPR
2136 __remove_if(_ForwardIterator __first, _ForwardIterator __last,
2140 if (__first == __last)
2142 _ForwardIterator __result = __first;
2144 for (; __first != __last; ++__first)
2145 if (!__pred(__first))
2147 *__result = _GLIBCXX_MOVE(*__first);
2153#if __cplusplus >= 201103L
2154 template<
typename _ForwardIterator1,
typename _ForwardIterator2,
2155 typename _BinaryPredicate>
2156 _GLIBCXX20_CONSTEXPR
2158 __is_permutation(_ForwardIterator1 __first1, _ForwardIterator1 __last1,
2159 _ForwardIterator2 __first2, _BinaryPredicate __pred)
2163 for (; __first1 != __last1; ++__first1, (void)++__first2)
2164 if (!__pred(__first1, __first2))
2167 if (__first1 == __last1)
2172 _ForwardIterator2 __last2 = __first2;
2174 for (_ForwardIterator1 __scan = __first1; __scan != __last1; ++__scan)
2177 __gnu_cxx::__ops::__iter_comp_iter(__pred, __scan)))
2181 = std::__count_if(__first2, __last2,
2182 __gnu_cxx::__ops::__iter_comp_iter(__pred, __scan));
2183 if (0 == __matches ||
2184 std::__count_if(__scan, __last1,
2185 __gnu_cxx::__ops::__iter_comp_iter(__pred, __scan))
2204 template<
typename _ForwardIterator1,
typename _ForwardIterator2>
2205 _GLIBCXX20_CONSTEXPR
2207 is_permutation(_ForwardIterator1 __first1, _ForwardIterator1 __last1,
2208 _ForwardIterator2 __first2)
2211 __glibcxx_function_requires(_ForwardIteratorConcept<_ForwardIterator1>)
2212 __glibcxx_function_requires(_ForwardIteratorConcept<_ForwardIterator2>)
2213 __glibcxx_function_requires(_EqualOpConcept<
2216 __glibcxx_requires_valid_range(__first1, __last1);
2218 return std::__is_permutation(__first1, __last1, __first2,
2219 __gnu_cxx::__ops::__iter_equal_to_iter());
2223_GLIBCXX_END_NAMESPACE_VERSION
2229#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.