56#ifndef _STL_ALGOBASE_H
57#define _STL_ALGOBASE_H 1
72#if __cplusplus >= 201103L
75#if __cplusplus > 201703L
79namespace std _GLIBCXX_VISIBILITY(default)
81_GLIBCXX_BEGIN_NAMESPACE_VERSION
87 template<
typename _Tp,
typename _Up>
90 __memcmp(
const _Tp* __first1,
const _Up* __first2,
size_t __num)
92#if __cplusplus >= 201103L
93 static_assert(
sizeof(_Tp) ==
sizeof(_Up),
"can be compared with memcmp");
95#ifdef __cpp_lib_is_constant_evaluated
98 for(; __num > 0; ++__first1, ++__first2, --__num)
99 if (*__first1 != *__first2)
100 return *__first1 < *__first2 ? -1 : 1;
105 return __builtin_memcmp(__first1, __first2,
sizeof(_Tp) * __num);
108#if __cplusplus < 201103L
112 template<
bool _BoolType>
115 template<
typename _ForwardIterator1,
typename _ForwardIterator2>
117 iter_swap(_ForwardIterator1 __a, _ForwardIterator2 __b)
119 typedef typename iterator_traits<_ForwardIterator1>::value_type
121 _ValueType1 __tmp = *__a;
128 struct __iter_swap<true>
130 template<
typename _ForwardIterator1,
typename _ForwardIterator2>
132 iter_swap(_ForwardIterator1 __a, _ForwardIterator2 __b)
149 template<
typename _ForwardIterator1,
typename _ForwardIterator2>
152 iter_swap(_ForwardIterator1 __a, _ForwardIterator2 __b)
155 __glibcxx_function_requires(_Mutable_ForwardIteratorConcept<
157 __glibcxx_function_requires(_Mutable_ForwardIteratorConcept<
160#if __cplusplus < 201103L
166 __glibcxx_function_requires(_ConvertibleConcept<_ValueType1,
168 __glibcxx_function_requires(_ConvertibleConcept<_ValueType2,
175 std::__iter_swap<__are_same<_ValueType1, _ValueType2>::__value
176 && __are_same<_ValueType1&, _ReferenceType1>::__value
177 && __are_same<_ValueType2&, _ReferenceType2>::__value>::
198 template<
typename _ForwardIterator1,
typename _ForwardIterator2>
201 swap_ranges(_ForwardIterator1 __first1, _ForwardIterator1 __last1,
202 _ForwardIterator2 __first2)
205 __glibcxx_function_requires(_Mutable_ForwardIteratorConcept<
207 __glibcxx_function_requires(_Mutable_ForwardIteratorConcept<
209 __glibcxx_requires_valid_range(__first1, __last1);
211 for (; __first1 != __last1; ++__first1, (void)++__first2)
212 std::iter_swap(__first1, __first2);
227 template<
typename _Tp>
230 min(
const _Tp& __a,
const _Tp& __b)
233 __glibcxx_function_requires(_LessThanComparableConcept<_Tp>)
251 template<
typename _Tp>
254 max(
const _Tp& __a,
const _Tp& __b)
257 __glibcxx_function_requires(_LessThanComparableConcept<_Tp>)
275 template<
typename _Tp,
typename _Compare>
278 min(
const _Tp& __a,
const _Tp& __b, _Compare __comp)
281 if (__comp(__b, __a))
297 template<
typename _Tp,
typename _Compare>
300 max(
const _Tp& __a,
const _Tp& __b, _Compare __comp)
303 if (__comp(__a, __b))
310 template<
typename _Iterator>
313 __niter_base(_Iterator __it)
317 template<
typename _Ite,
typename _Seq>
319 __niter_base(const ::__gnu_debug::_Safe_iterator<_Ite, _Seq,
325 template<
typename _From,
typename _To>
328 __niter_wrap(_From __from, _To __res)
329 {
return __from + (__res - std::__niter_base(__from)); }
332 template<
typename _Iterator>
335 __niter_wrap(
const _Iterator&, _Iterator __res)
344 template<
bool _IsMove,
bool _IsSimple,
typename _Category>
347 template<
typename _II,
typename _OI>
350 __copy_m(_II __first, _II __last, _OI __result)
352 for (; __first != __last; ++__result, (void)++__first)
353 *__result = *__first;
358#if __cplusplus >= 201103L
359 template<
typename _Category>
360 struct __copy_move<true, false, _Category>
362 template<
typename _II,
typename _OI>
365 __copy_m(_II __first, _II __last, _OI __result)
367 for (; __first != __last; ++__result, (void)++__first)
375 struct __copy_move<false, false, random_access_iterator_tag>
377 template<
typename _II,
typename _OI>
380 __copy_m(_II __first, _II __last, _OI __result)
382 typedef typename iterator_traits<_II>::difference_type _Distance;
383 for(_Distance __n = __last - __first; __n > 0; --__n)
385 *__result = *__first;
393#if __cplusplus >= 201103L
395 struct __copy_move<true, false, random_access_iterator_tag>
397 template<
typename _II,
typename _OI>
400 __copy_m(_II __first, _II __last, _OI __result)
402 typedef typename iterator_traits<_II>::difference_type _Distance;
403 for(_Distance __n = __last - __first; __n > 0; --__n)
414 template<
bool _IsMove>
415 struct __copy_move<_IsMove, true, random_access_iterator_tag>
417 template<
typename _Tp>
420 __copy_m(
const _Tp* __first,
const _Tp* __last, _Tp* __result)
422#if __cplusplus >= 201103L
423 using __assignable = __conditional_t<_IsMove,
424 is_move_assignable<_Tp>,
425 is_copy_assignable<_Tp>>;
427 static_assert( __assignable::value,
"type must be assignable" );
429 const ptrdiff_t _Num = __last - __first;
431 __builtin_memmove(__result, __first,
sizeof(_Tp) * _Num);
432 return __result + _Num;
436_GLIBCXX_BEGIN_NAMESPACE_CONTAINER
438 template<
typename _Tp,
typename _Ref,
typename _Ptr>
439 struct _Deque_iterator;
441 struct _Bit_iterator;
443_GLIBCXX_END_NAMESPACE_CONTAINER
448 template<
typename _CharT>
451 template<
typename _CharT,
typename _Traits>
452 class istreambuf_iterator;
454 template<
typename _CharT,
typename _Traits>
455 class ostreambuf_iterator;
457 template<
bool _IsMove,
typename _CharT>
458 typename __gnu_cxx::__enable_if<__is_char<_CharT>::__value,
459 ostreambuf_iterator<_CharT, char_traits<_CharT> > >::__type
460 __copy_move_a2(_CharT*, _CharT*,
461 ostreambuf_iterator<_CharT, char_traits<_CharT> >);
463 template<
bool _IsMove,
typename _CharT>
464 typename __gnu_cxx::__enable_if<__is_char<_CharT>::__value,
465 ostreambuf_iterator<_CharT, char_traits<_CharT> > >::__type
466 __copy_move_a2(
const _CharT*,
const _CharT*,
467 ostreambuf_iterator<_CharT, char_traits<_CharT> >);
469 template<
bool _IsMove,
typename _CharT>
470 typename __gnu_cxx::__enable_if<__is_char<_CharT>::__value,
472 __copy_move_a2(istreambuf_iterator<_CharT, char_traits<_CharT> >,
473 istreambuf_iterator<_CharT, char_traits<_CharT> >, _CharT*);
475 template<
bool _IsMove,
typename _CharT>
476 typename __gnu_cxx::__enable_if<
477 __is_char<_CharT>::__value,
478 _GLIBCXX_STD_C::_Deque_iterator<_CharT, _CharT&, _CharT*> >::__type
480 istreambuf_iterator<_CharT, char_traits<_CharT> >,
481 istreambuf_iterator<_CharT, char_traits<_CharT> >,
482 _GLIBCXX_STD_C::_Deque_iterator<_CharT, _CharT&, _CharT*>);
485 template<
bool _IsMove,
typename _II,
typename _OI>
488 __copy_move_a2(_II __first, _II __last, _OI __result)
490 typedef typename iterator_traits<_II>::iterator_category _Category;
491#ifdef __cpp_lib_is_constant_evaluated
493 return std::__copy_move<_IsMove, false, _Category>::
494 __copy_m(__first, __last, __result);
496 return std::__copy_move<_IsMove, __memcpyable<_OI, _II>::__value,
497 _Category>::__copy_m(__first, __last, __result);
500 template<
bool _IsMove,
501 typename _Tp,
typename _Ref,
typename _Ptr,
typename _OI>
503 __copy_move_a1(_GLIBCXX_STD_C::_Deque_iterator<_Tp, _Ref, _Ptr>,
504 _GLIBCXX_STD_C::_Deque_iterator<_Tp, _Ref, _Ptr>,
507 template<
bool _IsMove,
508 typename _ITp,
typename _IRef,
typename _IPtr,
typename _OTp>
509 _GLIBCXX_STD_C::_Deque_iterator<_OTp, _OTp&, _OTp*>
510 __copy_move_a1(_GLIBCXX_STD_C::_Deque_iterator<_ITp, _IRef, _IPtr>,
511 _GLIBCXX_STD_C::_Deque_iterator<_ITp, _IRef, _IPtr>,
512 _GLIBCXX_STD_C::_Deque_iterator<_OTp, _OTp&, _OTp*>);
514 template<
bool _IsMove,
typename _II,
typename _Tp>
515 typename __gnu_cxx::__enable_if<
516 __is_random_access_iter<_II>::__value,
517 _GLIBCXX_STD_C::_Deque_iterator<_Tp, _Tp&, _Tp*> >::__type
518 __copy_move_a1(_II, _II, _GLIBCXX_STD_C::_Deque_iterator<_Tp, _Tp&, _Tp*>);
520 template<
bool _IsMove,
typename _II,
typename _OI>
523 __copy_move_a1(_II __first, _II __last, _OI __result)
524 {
return std::__copy_move_a2<_IsMove>(__first, __last, __result); }
526 template<
bool _IsMove,
typename _II,
typename _OI>
529 __copy_move_a(_II __first, _II __last, _OI __result)
531 return std::__niter_wrap(__result,
532 std::__copy_move_a1<_IsMove>(std::__niter_base(__first),
533 std::__niter_base(__last),
534 std::__niter_base(__result)));
537 template<
bool _IsMove,
538 typename _Ite,
typename _Seq,
typename _Cat,
typename _OI>
540 __copy_move_a(const ::__gnu_debug::_Safe_iterator<_Ite, _Seq, _Cat>&,
541 const ::__gnu_debug::_Safe_iterator<_Ite, _Seq, _Cat>&,
544 template<
bool _IsMove,
545 typename _II,
typename _Ite,
typename _Seq,
typename _Cat>
547 __copy_move_a(_II, _II,
548 const ::__gnu_debug::_Safe_iterator<_Ite, _Seq, _Cat>&);
550 template<
bool _IsMove,
551 typename _IIte,
typename _ISeq,
typename _ICat,
552 typename _OIte,
typename _OSeq,
typename _OCat>
554 __copy_move_a(const ::__gnu_debug::_Safe_iterator<_IIte, _ISeq, _ICat>&,
555 const ::__gnu_debug::_Safe_iterator<_IIte, _ISeq, _ICat>&,
556 const ::__gnu_debug::_Safe_iterator<_OIte, _OSeq, _OCat>&);
558 template<
typename _InputIterator,
typename _Size,
typename _OutputIterator>
561 __copy_n_a(_InputIterator __first, _Size __n, _OutputIterator __result,
568 *__result = *__first;
580 template<
typename _CharT,
typename _Size>
581 typename __gnu_cxx::__enable_if<
582 __is_char<_CharT>::__value, _CharT*>::__type
583 __copy_n_a(istreambuf_iterator<_CharT, char_traits<_CharT> >,
584 _Size, _CharT*,
bool);
586 template<
typename _CharT,
typename _Size>
587 typename __gnu_cxx::__enable_if<
588 __is_char<_CharT>::__value,
589 _GLIBCXX_STD_C::_Deque_iterator<_CharT, _CharT&, _CharT*> >::__type
590 __copy_n_a(istreambuf_iterator<_CharT, char_traits<_CharT> >, _Size,
591 _GLIBCXX_STD_C::_Deque_iterator<_CharT, _CharT&, _CharT*>,
612 template<
typename _II,
typename _OI>
615 copy(_II __first, _II __last, _OI __result)
618 __glibcxx_function_requires(_InputIteratorConcept<_II>)
619 __glibcxx_function_requires(_OutputIteratorConcept<_OI,
621 __glibcxx_requires_can_increment_range(__first, __last, __result);
623 return std::__copy_move_a<__is_move_iterator<_II>::__value>
624 (std::__miter_base(__first), std::__miter_base(__last), __result);
627#if __cplusplus >= 201103L
645 template<
typename _II,
typename _OI>
648 move(_II __first, _II __last, _OI __result)
651 __glibcxx_function_requires(_InputIteratorConcept<_II>)
652 __glibcxx_function_requires(_OutputIteratorConcept<_OI,
654 __glibcxx_requires_can_increment_range(__first, __last, __result);
656 return std::__copy_move_a<true>(std::__miter_base(__first),
657 std::__miter_base(__last), __result);
660#define _GLIBCXX_MOVE3(_Tp, _Up, _Vp) std::move(_Tp, _Up, _Vp)
662#define _GLIBCXX_MOVE3(_Tp, _Up, _Vp) std::copy(_Tp, _Up, _Vp)
665 template<
bool _IsMove,
bool _IsSimple,
typename _Category>
666 struct __copy_move_backward
668 template<
typename _BI1,
typename _BI2>
671 __copy_move_b(_BI1 __first, _BI1 __last, _BI2 __result)
673 while (__first != __last)
674 *--__result = *--__last;
679#if __cplusplus >= 201103L
680 template<
typename _Category>
681 struct __copy_move_backward<true, false, _Category>
683 template<
typename _BI1,
typename _BI2>
686 __copy_move_b(_BI1 __first, _BI1 __last, _BI2 __result)
688 while (__first != __last)
696 struct __copy_move_backward<false, false, random_access_iterator_tag>
698 template<
typename _BI1,
typename _BI2>
701 __copy_move_b(_BI1 __first, _BI1 __last, _BI2 __result)
703 typename iterator_traits<_BI1>::difference_type
704 __n = __last - __first;
705 for (; __n > 0; --__n)
706 *--__result = *--__last;
711#if __cplusplus >= 201103L
713 struct __copy_move_backward<true, false, random_access_iterator_tag>
715 template<
typename _BI1,
typename _BI2>
718 __copy_move_b(_BI1 __first, _BI1 __last, _BI2 __result)
720 typename iterator_traits<_BI1>::difference_type
721 __n = __last - __first;
722 for (; __n > 0; --__n)
729 template<
bool _IsMove>
730 struct __copy_move_backward<_IsMove, true, random_access_iterator_tag>
732 template<
typename _Tp>
735 __copy_move_b(
const _Tp* __first,
const _Tp* __last, _Tp* __result)
737#if __cplusplus >= 201103L
738 using __assignable = __conditional_t<_IsMove,
739 is_move_assignable<_Tp>,
740 is_copy_assignable<_Tp>>;
742 static_assert( __assignable::value,
"type must be assignable" );
744 const ptrdiff_t _Num = __last - __first;
746 __builtin_memmove(__result - _Num, __first,
sizeof(_Tp) * _Num);
747 return __result - _Num;
751 template<
bool _IsMove,
typename _BI1,
typename _BI2>
754 __copy_move_backward_a2(_BI1 __first, _BI1 __last, _BI2 __result)
756 typedef typename iterator_traits<_BI1>::iterator_category _Category;
757#ifdef __cpp_lib_is_constant_evaluated
759 return std::__copy_move_backward<_IsMove, false, _Category>::
760 __copy_move_b(__first, __last, __result);
762 return std::__copy_move_backward<_IsMove,
763 __memcpyable<_BI2, _BI1>::__value,
764 _Category>::__copy_move_b(__first,
769 template<
bool _IsMove,
typename _BI1,
typename _BI2>
772 __copy_move_backward_a1(_BI1 __first, _BI1 __last, _BI2 __result)
773 {
return std::__copy_move_backward_a2<_IsMove>(__first, __last, __result); }
775 template<
bool _IsMove,
776 typename _Tp,
typename _Ref,
typename _Ptr,
typename _OI>
778 __copy_move_backward_a1(_GLIBCXX_STD_C::_Deque_iterator<_Tp, _Ref, _Ptr>,
779 _GLIBCXX_STD_C::_Deque_iterator<_Tp, _Ref, _Ptr>,
782 template<
bool _IsMove,
783 typename _ITp,
typename _IRef,
typename _IPtr,
typename _OTp>
784 _GLIBCXX_STD_C::_Deque_iterator<_OTp, _OTp&, _OTp*>
785 __copy_move_backward_a1(
786 _GLIBCXX_STD_C::_Deque_iterator<_ITp, _IRef, _IPtr>,
787 _GLIBCXX_STD_C::_Deque_iterator<_ITp, _IRef, _IPtr>,
788 _GLIBCXX_STD_C::_Deque_iterator<_OTp, _OTp&, _OTp*>);
790 template<
bool _IsMove,
typename _II,
typename _Tp>
791 typename __gnu_cxx::__enable_if<
792 __is_random_access_iter<_II>::__value,
793 _GLIBCXX_STD_C::_Deque_iterator<_Tp, _Tp&, _Tp*> >::__type
794 __copy_move_backward_a1(_II, _II,
795 _GLIBCXX_STD_C::_Deque_iterator<_Tp, _Tp&, _Tp*>);
797 template<
bool _IsMove,
typename _II,
typename _OI>
800 __copy_move_backward_a(_II __first, _II __last, _OI __result)
802 return std::__niter_wrap(__result,
803 std::__copy_move_backward_a1<_IsMove>
804 (std::__niter_base(__first), std::__niter_base(__last),
805 std::__niter_base(__result)));
808 template<
bool _IsMove,
809 typename _Ite,
typename _Seq,
typename _Cat,
typename _OI>
811 __copy_move_backward_a(
812 const ::__gnu_debug::_Safe_iterator<_Ite, _Seq, _Cat>&,
813 const ::__gnu_debug::_Safe_iterator<_Ite, _Seq, _Cat>&,
816 template<
bool _IsMove,
817 typename _II,
typename _Ite,
typename _Seq,
typename _Cat>
819 __copy_move_backward_a(_II, _II,
820 const ::__gnu_debug::_Safe_iterator<_Ite, _Seq, _Cat>&);
822 template<
bool _IsMove,
823 typename _IIte,
typename _ISeq,
typename _ICat,
824 typename _OIte,
typename _OSeq,
typename _OCat>
826 __copy_move_backward_a(
827 const ::__gnu_debug::_Safe_iterator<_IIte, _ISeq, _ICat>&,
828 const ::__gnu_debug::_Safe_iterator<_IIte, _ISeq, _ICat>&,
829 const ::__gnu_debug::_Safe_iterator<_OIte, _OSeq, _OCat>&);
849 template<
typename _BI1,
typename _BI2>
852 copy_backward(_BI1 __first, _BI1 __last, _BI2 __result)
855 __glibcxx_function_requires(_BidirectionalIteratorConcept<_BI1>)
856 __glibcxx_function_requires(_Mutable_BidirectionalIteratorConcept<_BI2>)
857 __glibcxx_function_requires(_OutputIteratorConcept<_BI2,
859 __glibcxx_requires_can_decrement_range(__first, __last, __result);
861 return std::__copy_move_backward_a<__is_move_iterator<_BI1>::__value>
862 (std::__miter_base(__first), std::__miter_base(__last), __result);
865#if __cplusplus >= 201103L
884 template<
typename _BI1,
typename _BI2>
890 __glibcxx_function_requires(_BidirectionalIteratorConcept<_BI1>)
891 __glibcxx_function_requires(_Mutable_BidirectionalIteratorConcept<_BI2>)
892 __glibcxx_function_requires(_OutputIteratorConcept<_BI2,
894 __glibcxx_requires_can_decrement_range(__first, __last, __result);
896 return std::__copy_move_backward_a<true>(std::__miter_base(__first),
897 std::__miter_base(__last),
901#define _GLIBCXX_MOVE_BACKWARD3(_Tp, _Up, _Vp) std::move_backward(_Tp, _Up, _Vp)
903#define _GLIBCXX_MOVE_BACKWARD3(_Tp, _Up, _Vp) std::copy_backward(_Tp, _Up, _Vp)
906 template<
typename _ForwardIterator,
typename _Tp>
909 __gnu_cxx::__enable_if<!__is_scalar<_Tp>::__value,
void>::__type
910 __fill_a1(_ForwardIterator __first, _ForwardIterator __last,
913 for (; __first != __last; ++__first)
917 template<
typename _ForwardIterator,
typename _Tp>
920 __gnu_cxx::__enable_if<__is_scalar<_Tp>::__value,
void>::__type
921 __fill_a1(_ForwardIterator __first, _ForwardIterator __last,
924 const _Tp __tmp = __value;
925 for (; __first != __last; ++__first)
930 template<
typename _Tp>
933 __gnu_cxx::__enable_if<__is_byte<_Tp>::__value,
void>::__type
934 __fill_a1(_Tp* __first, _Tp* __last,
const _Tp& __c)
936 const _Tp __tmp = __c;
937#if __cpp_lib_is_constant_evaluated
940 for (; __first != __last; ++__first)
945 if (
const size_t __len = __last - __first)
946 __builtin_memset(__first,
static_cast<unsigned char>(__tmp), __len);
949 template<
typename _Ite,
typename _Cont,
typename _Tp>
952 __fill_a1(::__gnu_cxx::__normal_iterator<_Ite, _Cont> __first,
953 ::__gnu_cxx::__normal_iterator<_Ite, _Cont> __last,
955 { std::__fill_a1(__first.base(), __last.base(), __value); }
957 template<
typename _Tp,
typename _VTp>
959 __fill_a1(
const _GLIBCXX_STD_C::_Deque_iterator<_Tp, _Tp&, _Tp*>&,
960 const _GLIBCXX_STD_C::_Deque_iterator<_Tp, _Tp&, _Tp*>&,
965 __fill_a1(_GLIBCXX_STD_C::_Bit_iterator, _GLIBCXX_STD_C::_Bit_iterator,
968 template<
typename _FIte,
typename _Tp>
971 __fill_a(_FIte __first, _FIte __last,
const _Tp& __value)
972 { std::__fill_a1(__first, __last, __value); }
974 template<
typename _Ite,
typename _Seq,
typename _Cat,
typename _Tp>
976 __fill_a(const ::__gnu_debug::_Safe_iterator<_Ite, _Seq, _Cat>&,
977 const ::__gnu_debug::_Safe_iterator<_Ite, _Seq, _Cat>&,
992 template<
typename _ForwardIterator,
typename _Tp>
995 fill(_ForwardIterator __first, _ForwardIterator __last,
const _Tp& __value)
998 __glibcxx_function_requires(_Mutable_ForwardIteratorConcept<
1000 __glibcxx_requires_valid_range(__first, __last);
1002 std::__fill_a(__first, __last, __value);
1006 inline _GLIBCXX_CONSTEXPR
int
1007 __size_to_integer(
int __n) {
return __n; }
1008 inline _GLIBCXX_CONSTEXPR
unsigned
1009 __size_to_integer(
unsigned __n) {
return __n; }
1010 inline _GLIBCXX_CONSTEXPR
long
1011 __size_to_integer(
long __n) {
return __n; }
1012 inline _GLIBCXX_CONSTEXPR
unsigned long
1013 __size_to_integer(
unsigned long __n) {
return __n; }
1014 inline _GLIBCXX_CONSTEXPR
long long
1015 __size_to_integer(
long long __n) {
return __n; }
1016 inline _GLIBCXX_CONSTEXPR
unsigned long long
1017 __size_to_integer(
unsigned long long __n) {
return __n; }
1019#if defined(__GLIBCXX_TYPE_INT_N_0)
1020 __extension__
inline _GLIBCXX_CONSTEXPR __GLIBCXX_TYPE_INT_N_0
1021 __size_to_integer(__GLIBCXX_TYPE_INT_N_0 __n) {
return __n; }
1022 __extension__
inline _GLIBCXX_CONSTEXPR
unsigned __GLIBCXX_TYPE_INT_N_0
1023 __size_to_integer(
unsigned __GLIBCXX_TYPE_INT_N_0 __n) {
return __n; }
1025#if defined(__GLIBCXX_TYPE_INT_N_1)
1026 __extension__
inline _GLIBCXX_CONSTEXPR __GLIBCXX_TYPE_INT_N_1
1027 __size_to_integer(__GLIBCXX_TYPE_INT_N_1 __n) {
return __n; }
1028 __extension__
inline _GLIBCXX_CONSTEXPR
unsigned __GLIBCXX_TYPE_INT_N_1
1029 __size_to_integer(
unsigned __GLIBCXX_TYPE_INT_N_1 __n) {
return __n; }
1031#if defined(__GLIBCXX_TYPE_INT_N_2)
1032 __extension__
inline _GLIBCXX_CONSTEXPR __GLIBCXX_TYPE_INT_N_2
1033 __size_to_integer(__GLIBCXX_TYPE_INT_N_2 __n) {
return __n; }
1034 __extension__
inline _GLIBCXX_CONSTEXPR
unsigned __GLIBCXX_TYPE_INT_N_2
1035 __size_to_integer(
unsigned __GLIBCXX_TYPE_INT_N_2 __n) {
return __n; }
1037#if defined(__GLIBCXX_TYPE_INT_N_3)
1038 __extension__
inline _GLIBCXX_CONSTEXPR
unsigned __GLIBCXX_TYPE_INT_N_3
1039 __size_to_integer(__GLIBCXX_TYPE_INT_N_3 __n) {
return __n; }
1040 __extension__
inline _GLIBCXX_CONSTEXPR __GLIBCXX_TYPE_INT_N_3
1041 __size_to_integer(
unsigned __GLIBCXX_TYPE_INT_N_3 __n) {
return __n; }
1044 inline _GLIBCXX_CONSTEXPR
long long
1045 __size_to_integer(
float __n) {
return (
long long)__n; }
1046 inline _GLIBCXX_CONSTEXPR
long long
1047 __size_to_integer(
double __n) {
return (
long long)__n; }
1048 inline _GLIBCXX_CONSTEXPR
long long
1049 __size_to_integer(
long double __n) {
return (
long long)__n; }
1050#if !defined(__STRICT_ANSI__) && defined(_GLIBCXX_USE_FLOAT128)
1051 __extension__
inline _GLIBCXX_CONSTEXPR
long long
1052 __size_to_integer(__float128 __n) {
return (
long long)__n; }
1055 template<
typename _OutputIterator,
typename _Size,
typename _Tp>
1056 _GLIBCXX20_CONSTEXPR
1058 __gnu_cxx::__enable_if<!__is_scalar<_Tp>::__value, _OutputIterator>::__type
1059 __fill_n_a1(_OutputIterator __first, _Size __n,
const _Tp& __value)
1061 for (; __n > 0; --__n, (void) ++__first)
1066 template<
typename _OutputIterator,
typename _Size,
typename _Tp>
1067 _GLIBCXX20_CONSTEXPR
1069 __gnu_cxx::__enable_if<__is_scalar<_Tp>::__value, _OutputIterator>::__type
1070 __fill_n_a1(_OutputIterator __first, _Size __n,
const _Tp& __value)
1072 const _Tp __tmp = __value;
1073 for (; __n > 0; --__n, (void) ++__first)
1078 template<
typename _Ite,
typename _Seq,
typename _Cat,
typename _Size,
1081 __fill_n_a(const ::__gnu_debug::_Safe_iterator<_Ite, _Seq, _Cat>& __first,
1082 _Size __n,
const _Tp& __value,
1085 template<
typename _OutputIterator,
typename _Size,
typename _Tp>
1086 _GLIBCXX20_CONSTEXPR
1087 inline _OutputIterator
1088 __fill_n_a(_OutputIterator __first, _Size __n,
const _Tp& __value,
1091#if __cplusplus >= 201103L
1092 static_assert(is_integral<_Size>{},
"fill_n must pass integral size");
1094 return __fill_n_a1(__first, __n, __value);
1097 template<
typename _OutputIterator,
typename _Size,
typename _Tp>
1098 _GLIBCXX20_CONSTEXPR
1099 inline _OutputIterator
1100 __fill_n_a(_OutputIterator __first, _Size __n,
const _Tp& __value,
1103#if __cplusplus >= 201103L
1104 static_assert(is_integral<_Size>{},
"fill_n must pass integral size");
1106 return __fill_n_a1(__first, __n, __value);
1109 template<
typename _OutputIterator,
typename _Size,
typename _Tp>
1110 _GLIBCXX20_CONSTEXPR
1111 inline _OutputIterator
1112 __fill_n_a(_OutputIterator __first, _Size __n,
const _Tp& __value,
1115#if __cplusplus >= 201103L
1116 static_assert(is_integral<_Size>{},
"fill_n must pass integral size");
1121 __glibcxx_requires_can_increment(__first, __n);
1123 std::__fill_a(__first, __first + __n, __value);
1124 return __first + __n;
1144 template<
typename _OI,
typename _Size,
typename _Tp>
1145 _GLIBCXX20_CONSTEXPR
1147 fill_n(_OI __first, _Size __n,
const _Tp& __value)
1150 __glibcxx_function_requires(_OutputIteratorConcept<_OI, const _Tp&>)
1152 return std::__fill_n_a(__first, std::__size_to_integer(__n), __value,
1156 template<
bool _BoolType>
1159 template<
typename _II1,
typename _II2>
1160 _GLIBCXX20_CONSTEXPR
1162 equal(_II1 __first1, _II1 __last1, _II2 __first2)
1164 for (; __first1 != __last1; ++__first1, (void) ++__first2)
1165 if (!(*__first1 == *__first2))
1172 struct __equal<true>
1174 template<
typename _Tp>
1175 _GLIBCXX20_CONSTEXPR
1177 equal(
const _Tp* __first1,
const _Tp* __last1,
const _Tp* __first2)
1179 if (
const size_t __len = (__last1 - __first1))
1180 return !std::__memcmp(__first1, __first2, __len);
1185 template<
typename _Tp,
typename _Ref,
typename _Ptr,
typename _II>
1186 typename __gnu_cxx::__enable_if<
1187 __is_random_access_iter<_II>::__value,
bool>::__type
1188 __equal_aux1(_GLIBCXX_STD_C::_Deque_iterator<_Tp, _Ref, _Ptr>,
1189 _GLIBCXX_STD_C::_Deque_iterator<_Tp, _Ref, _Ptr>,
1192 template<
typename _Tp1,
typename _Ref1,
typename _Ptr1,
1193 typename _Tp2,
typename _Ref2,
typename _Ptr2>
1195 __equal_aux1(_GLIBCXX_STD_C::_Deque_iterator<_Tp1, _Ref1, _Ptr1>,
1196 _GLIBCXX_STD_C::_Deque_iterator<_Tp1, _Ref1, _Ptr1>,
1197 _GLIBCXX_STD_C::_Deque_iterator<_Tp2, _Ref2, _Ptr2>);
1199 template<
typename _II,
typename _Tp,
typename _Ref,
typename _Ptr>
1200 typename __gnu_cxx::__enable_if<
1201 __is_random_access_iter<_II>::__value,
bool>::__type
1202 __equal_aux1(_II, _II,
1203 _GLIBCXX_STD_C::_Deque_iterator<_Tp, _Ref, _Ptr>);
1205 template<
typename _II1,
typename _II2>
1206 _GLIBCXX20_CONSTEXPR
1208 __equal_aux1(_II1 __first1, _II1 __last1, _II2 __first2)
1210 typedef typename iterator_traits<_II1>::value_type _ValueType1;
1211 const bool __simple = ((__is_integer<_ValueType1>::__value
1212 || __is_pointer<_ValueType1>::__value)
1213 && __memcmpable<_II1, _II2>::__value);
1217 template<
typename _II1,
typename _II2>
1218 _GLIBCXX20_CONSTEXPR
1220 __equal_aux(_II1 __first1, _II1 __last1, _II2 __first2)
1222 return std::__equal_aux1(std::__niter_base(__first1),
1223 std::__niter_base(__last1),
1224 std::__niter_base(__first2));
1227 template<
typename _II1,
typename _Seq1,
typename _Cat1,
typename _II2>
1229 __equal_aux(const ::__gnu_debug::_Safe_iterator<_II1, _Seq1, _Cat1>&,
1230 const ::__gnu_debug::_Safe_iterator<_II1, _Seq1, _Cat1>&,
1233 template<
typename _II1,
typename _II2,
typename _Seq2,
typename _Cat2>
1235 __equal_aux(_II1, _II1,
1236 const ::__gnu_debug::_Safe_iterator<_II2, _Seq2, _Cat2>&);
1238 template<
typename _II1,
typename _Seq1,
typename _Cat1,
1239 typename _II2,
typename _Seq2,
typename _Cat2>
1241 __equal_aux(const ::__gnu_debug::_Safe_iterator<_II1, _Seq1, _Cat1>&,
1242 const ::__gnu_debug::_Safe_iterator<_II1, _Seq1, _Cat1>&,
1243 const ::__gnu_debug::_Safe_iterator<_II2, _Seq2, _Cat2>&);
1245 template<
typename,
typename>
1248 template<
typename _II1,
typename _II2>
1249 _GLIBCXX20_CONSTEXPR
1251 __newlast1(_II1, _II1 __last1, _II2, _II2)
1254 template<
typename _II>
1255 _GLIBCXX20_CONSTEXPR
1257 __cnd2(_II __first, _II __last)
1258 {
return __first != __last; }
1262 struct __lc_rai<random_access_iterator_tag, random_access_iterator_tag>
1264 template<
typename _RAI1,
typename _RAI2>
1265 _GLIBCXX20_CONSTEXPR
1267 __newlast1(_RAI1 __first1, _RAI1 __last1,
1268 _RAI2 __first2, _RAI2 __last2)
1270 const typename iterator_traits<_RAI1>::difference_type
1271 __diff1 = __last1 - __first1;
1272 const typename iterator_traits<_RAI2>::difference_type
1273 __diff2 = __last2 - __first2;
1274 return __diff2 < __diff1 ? __first1 + __diff2 : __last1;
1277 template<
typename _RAI>
1278 static _GLIBCXX20_CONSTEXPR
bool
1283 template<
typename _II1,
typename _II2,
typename _Compare>
1284 _GLIBCXX20_CONSTEXPR
1286 __lexicographical_compare_impl(_II1 __first1, _II1 __last1,
1287 _II2 __first2, _II2 __last2,
1290 typedef typename iterator_traits<_II1>::iterator_category _Category1;
1291 typedef typename iterator_traits<_II2>::iterator_category _Category2;
1292 typedef std::__lc_rai<_Category1, _Category2> __rai_type;
1294 __last1 = __rai_type::__newlast1(__first1, __last1, __first2, __last2);
1295 for (; __first1 != __last1 && __rai_type::__cnd2(__first2, __last2);
1296 ++__first1, (void)++__first2)
1298 if (__comp(__first1, __first2))
1300 if (__comp(__first2, __first1))
1303 return __first1 == __last1 && __first2 != __last2;
1306 template<
bool _BoolType>
1307 struct __lexicographical_compare
1309 template<
typename _II1,
typename _II2>
1310 _GLIBCXX20_CONSTEXPR
1312 __lc(_II1 __first1, _II1 __last1, _II2 __first2, _II2 __last2)
1314 using __gnu_cxx::__ops::__iter_less_iter;
1315 return std::__lexicographical_compare_impl(__first1, __last1,
1317 __iter_less_iter());
1320 template<
typename _II1,
typename _II2>
1321 _GLIBCXX20_CONSTEXPR
1323 __3way(_II1 __first1, _II1 __last1, _II2 __first2, _II2 __last2)
1325 while (__first1 != __last1)
1327 if (__first2 == __last2)
1329 if (*__first1 < *__first2)
1331 if (*__first2 < *__first1)
1336 return int(__first2 == __last2) - 1;
1341 struct __lexicographical_compare<true>
1343 template<
typename _Tp,
typename _Up>
1344 _GLIBCXX20_CONSTEXPR
1346 __lc(
const _Tp* __first1,
const _Tp* __last1,
1347 const _Up* __first2,
const _Up* __last2)
1348 {
return __3way(__first1, __last1, __first2, __last2) < 0; }
1350 template<
typename _Tp,
typename _Up>
1351 _GLIBCXX20_CONSTEXPR
1353 __3way(
const _Tp* __first1,
const _Tp* __last1,
1354 const _Up* __first2,
const _Up* __last2)
1356 const size_t __len1 = __last1 - __first1;
1357 const size_t __len2 = __last2 - __first2;
1358 if (
const size_t __len =
std::min(__len1, __len2))
1359 if (
int __result = std::__memcmp(__first1, __first2, __len))
1361 return ptrdiff_t(__len1 - __len2);
1365 template<
typename _II1,
typename _II2>
1366 _GLIBCXX20_CONSTEXPR
1368 __lexicographical_compare_aux1(_II1 __first1, _II1 __last1,
1369 _II2 __first2, _II2 __last2)
1371 typedef typename iterator_traits<_II1>::value_type _ValueType1;
1372 typedef typename iterator_traits<_II2>::value_type _ValueType2;
1373 const bool __simple =
1374 (__is_memcmp_ordered_with<_ValueType1, _ValueType2>::__value
1375 && __is_pointer<_II1>::__value
1376 && __is_pointer<_II2>::__value
1377#if __cplusplus > 201703L && __cpp_lib_concepts
1381 && !is_volatile_v<remove_reference_t<iter_reference_t<_II1>>>
1382 && !is_volatile_v<remove_reference_t<iter_reference_t<_II2>>>
1386 return std::__lexicographical_compare<__simple>::__lc(__first1, __last1,
1390 template<
typename _Tp1,
typename _Ref1,
typename _Ptr1,
1393 __lexicographical_compare_aux1(
1394 _GLIBCXX_STD_C::_Deque_iterator<_Tp1, _Ref1, _Ptr1>,
1395 _GLIBCXX_STD_C::_Deque_iterator<_Tp1, _Ref1, _Ptr1>,
1398 template<
typename _Tp1,
1399 typename _Tp2,
typename _Ref2,
typename _Ptr2>
1401 __lexicographical_compare_aux1(_Tp1*, _Tp1*,
1402 _GLIBCXX_STD_C::_Deque_iterator<_Tp2, _Ref2, _Ptr2>,
1403 _GLIBCXX_STD_C::_Deque_iterator<_Tp2, _Ref2, _Ptr2>);
1405 template<
typename _Tp1,
typename _Ref1,
typename _Ptr1,
1406 typename _Tp2,
typename _Ref2,
typename _Ptr2>
1408 __lexicographical_compare_aux1(
1409 _GLIBCXX_STD_C::_Deque_iterator<_Tp1, _Ref1, _Ptr1>,
1410 _GLIBCXX_STD_C::_Deque_iterator<_Tp1, _Ref1, _Ptr1>,
1411 _GLIBCXX_STD_C::_Deque_iterator<_Tp2, _Ref2, _Ptr2>,
1412 _GLIBCXX_STD_C::_Deque_iterator<_Tp2, _Ref2, _Ptr2>);
1414 template<
typename _II1,
typename _II2>
1415 _GLIBCXX20_CONSTEXPR
1417 __lexicographical_compare_aux(_II1 __first1, _II1 __last1,
1418 _II2 __first2, _II2 __last2)
1420 return std::__lexicographical_compare_aux1(std::__niter_base(__first1),
1421 std::__niter_base(__last1),
1422 std::__niter_base(__first2),
1423 std::__niter_base(__last2));
1426 template<
typename _Iter1,
typename _Seq1,
typename _Cat1,
1429 __lexicographical_compare_aux(
1430 const ::__gnu_debug::_Safe_iterator<_Iter1, _Seq1, _Cat1>&,
1431 const ::__gnu_debug::_Safe_iterator<_Iter1, _Seq1, _Cat1>&,
1434 template<
typename _II1,
1435 typename _Iter2,
typename _Seq2,
typename _Cat2>
1437 __lexicographical_compare_aux(
1439 const ::__gnu_debug::_Safe_iterator<_Iter2, _Seq2, _Cat2>&,
1440 const ::__gnu_debug::_Safe_iterator<_Iter2, _Seq2, _Cat2>&);
1442 template<
typename _Iter1,
typename _Seq1,
typename _Cat1,
1443 typename _Iter2,
typename _Seq2,
typename _Cat2>
1445 __lexicographical_compare_aux(
1446 const ::__gnu_debug::_Safe_iterator<_Iter1, _Seq1, _Cat1>&,
1447 const ::__gnu_debug::_Safe_iterator<_Iter1, _Seq1, _Cat1>&,
1448 const ::__gnu_debug::_Safe_iterator<_Iter2, _Seq2, _Cat2>&,
1449 const ::__gnu_debug::_Safe_iterator<_Iter2, _Seq2, _Cat2>&);
1451 template<
typename _ForwardIterator,
typename _Tp,
typename _Compare>
1452 _GLIBCXX20_CONSTEXPR
1454 __lower_bound(_ForwardIterator __first, _ForwardIterator __last,
1455 const _Tp& __val, _Compare __comp)
1457 typedef typename iterator_traits<_ForwardIterator>::difference_type
1464 _DistanceType __half = __len >> 1;
1465 _ForwardIterator __middle = __first;
1467 if (__comp(__middle, __val))
1471 __len = __len - __half - 1;
1490 template<
typename _ForwardIterator,
typename _Tp>
1491 _GLIBCXX20_CONSTEXPR
1492 inline _ForwardIterator
1493 lower_bound(_ForwardIterator __first, _ForwardIterator __last,
1497 __glibcxx_function_requires(_ForwardIteratorConcept<_ForwardIterator>)
1498 __glibcxx_function_requires(_LessThanOpConcept<
1500 __glibcxx_requires_partitioned_lower(__first, __last, __val);
1502 return std::__lower_bound(__first, __last, __val,
1503 __gnu_cxx::__ops::__iter_less_val());
1508 inline _GLIBCXX_CONSTEXPR
int
1510 {
return (
int)
sizeof(int) * __CHAR_BIT__ - 1 - __builtin_clz(__n); }
1512 inline _GLIBCXX_CONSTEXPR
unsigned
1514 {
return (
int)
sizeof(int) * __CHAR_BIT__ - 1 - __builtin_clz(__n); }
1516 inline _GLIBCXX_CONSTEXPR
long
1518 {
return (
int)
sizeof(long) * __CHAR_BIT__ - 1 - __builtin_clzl(__n); }
1520 inline _GLIBCXX_CONSTEXPR
unsigned long
1521 __lg(
unsigned long __n)
1522 {
return (
int)
sizeof(long) * __CHAR_BIT__ - 1 - __builtin_clzl(__n); }
1524 inline _GLIBCXX_CONSTEXPR
long long
1526 {
return (
int)
sizeof(
long long) * __CHAR_BIT__ - 1 - __builtin_clzll(__n); }
1528 inline _GLIBCXX_CONSTEXPR
unsigned long long
1529 __lg(
unsigned long long __n)
1530 {
return (
int)
sizeof(
long long) * __CHAR_BIT__ - 1 - __builtin_clzll(__n); }
1532_GLIBCXX_BEGIN_NAMESPACE_ALGO
1546 template<
typename _II1,
typename _II2>
1547 _GLIBCXX20_CONSTEXPR
1549 equal(_II1 __first1, _II1 __last1, _II2 __first2)
1552 __glibcxx_function_requires(_InputIteratorConcept<_II1>)
1553 __glibcxx_function_requires(_InputIteratorConcept<_II2>)
1554 __glibcxx_function_requires(_EqualOpConcept<
1557 __glibcxx_requires_can_increment_range(__first1, __last1, __first2);
1559 return std::__equal_aux(__first1, __last1, __first2);
1577 template<
typename _IIter1,
typename _IIter2,
typename _BinaryPredicate>
1578 _GLIBCXX20_CONSTEXPR
1580 equal(_IIter1 __first1, _IIter1 __last1,
1581 _IIter2 __first2, _BinaryPredicate __binary_pred)
1584 __glibcxx_function_requires(_InputIteratorConcept<_IIter1>)
1585 __glibcxx_function_requires(_InputIteratorConcept<_IIter2>)
1586 __glibcxx_requires_valid_range(__first1, __last1);
1588 for (; __first1 != __last1; ++__first1, (void)++__first2)
1589 if (!
bool(__binary_pred(*__first1, *__first2)))
1594#if __cplusplus >= 201103L
1596 template<
typename _II1,
typename _II2>
1597 _GLIBCXX20_CONSTEXPR
1599 __equal4(_II1 __first1, _II1 __last1, _II2 __first2, _II2 __last2)
1601 using _RATag = random_access_iterator_tag;
1602 using _Cat1 =
typename iterator_traits<_II1>::iterator_category;
1603 using _Cat2 =
typename iterator_traits<_II2>::iterator_category;
1604 using _RAIters = __and_<is_same<_Cat1, _RATag>, is_same<_Cat2, _RATag>>;
1614 for (; __first1 != __last1 && __first2 != __last2;
1615 ++__first1, (void)++__first2)
1616 if (!(*__first1 == *__first2))
1618 return __first1 == __last1 && __first2 == __last2;
1622 template<
typename _II1,
typename _II2,
typename _BinaryPredicate>
1623 _GLIBCXX20_CONSTEXPR
1625 __equal4(_II1 __first1, _II1 __last1, _II2 __first2, _II2 __last2,
1626 _BinaryPredicate __binary_pred)
1628 using _RATag = random_access_iterator_tag;
1629 using _Cat1 =
typename iterator_traits<_II1>::iterator_category;
1630 using _Cat2 =
typename iterator_traits<_II2>::iterator_category;
1631 using _RAIters = __and_<is_same<_Cat1, _RATag>, is_same<_Cat2, _RATag>>;
1642 for (; __first1 != __last1 && __first2 != __last2;
1643 ++__first1, (void)++__first2)
1644 if (!
bool(__binary_pred(*__first1, *__first2)))
1646 return __first1 == __last1 && __first2 == __last2;
1650#if __cplusplus > 201103L
1652#define __cpp_lib_robust_nonmodifying_seq_ops 201304L
1667 template<
typename _II1,
typename _II2>
1668 _GLIBCXX20_CONSTEXPR
1670 equal(_II1 __first1, _II1 __last1, _II2 __first2, _II2 __last2)
1673 __glibcxx_function_requires(_InputIteratorConcept<_II1>)
1674 __glibcxx_function_requires(_InputIteratorConcept<_II2>)
1675 __glibcxx_function_requires(_EqualOpConcept<
1678 __glibcxx_requires_valid_range(__first1, __last1);
1679 __glibcxx_requires_valid_range(__first2, __last2);
1681 return _GLIBCXX_STD_A::__equal4(__first1, __last1, __first2, __last2);
1700 template<
typename _IIter1,
typename _IIter2,
typename _BinaryPredicate>
1701 _GLIBCXX20_CONSTEXPR
1703 equal(_IIter1 __first1, _IIter1 __last1,
1704 _IIter2 __first2, _IIter2 __last2, _BinaryPredicate __binary_pred)
1707 __glibcxx_function_requires(_InputIteratorConcept<_IIter1>)
1708 __glibcxx_function_requires(_InputIteratorConcept<_IIter2>)
1709 __glibcxx_requires_valid_range(__first1, __last1);
1710 __glibcxx_requires_valid_range(__first2, __last2);
1712 return _GLIBCXX_STD_A::__equal4(__first1, __last1, __first2, __last2,
1732 template<
typename _II1,
typename _II2>
1733 _GLIBCXX20_CONSTEXPR
1735 lexicographical_compare(_II1 __first1, _II1 __last1,
1736 _II2 __first2, _II2 __last2)
1738#ifdef _GLIBCXX_CONCEPT_CHECKS
1743 __glibcxx_function_requires(_InputIteratorConcept<_II1>)
1744 __glibcxx_function_requires(_InputIteratorConcept<_II2>)
1745 __glibcxx_function_requires(_LessThanOpConcept<_ValueType1, _ValueType2>)
1746 __glibcxx_function_requires(_LessThanOpConcept<_ValueType2, _ValueType1>)
1747 __glibcxx_requires_valid_range(__first1, __last1);
1748 __glibcxx_requires_valid_range(__first2, __last2);
1750 return std::__lexicographical_compare_aux(__first1, __last1,
1767 template<
typename _II1,
typename _II2,
typename _Compare>
1768 _GLIBCXX20_CONSTEXPR
1770 lexicographical_compare(_II1 __first1, _II1 __last1,
1771 _II2 __first2, _II2 __last2, _Compare __comp)
1774 __glibcxx_function_requires(_InputIteratorConcept<_II1>)
1775 __glibcxx_function_requires(_InputIteratorConcept<_II2>)
1776 __glibcxx_requires_valid_range(__first1, __last1);
1777 __glibcxx_requires_valid_range(__first2, __last2);
1779 return std::__lexicographical_compare_impl
1780 (__first1, __last1, __first2, __last2,
1781 __gnu_cxx::__ops::__iter_comp_iter(__comp));
1784#if __cpp_lib_three_way_comparison
1787 template<
typename _Iter>
1788 concept __is_byte_iter = contiguous_iterator<_Iter>
1789 && __is_memcmp_ordered<iter_value_t<_Iter>>::__value;
1793 template<
typename _Tp>
1795 __min_cmp(_Tp __x, _Tp __y)
1799 decltype(__x <=> __y) _M_cmp;
1801 auto __c = __x <=> __y;
1803 return _Res{__y, __c};
1804 return _Res{__x, __c};
1818 template<
typename _InputIter1,
typename _InputIter2,
typename _Comp>
1820 lexicographical_compare_three_way(_InputIter1 __first1,
1821 _InputIter1 __last1,
1822 _InputIter2 __first2,
1823 _InputIter2 __last2,
1825 ->
decltype(__comp(*__first1, *__first2))
1828 __glibcxx_function_requires(_InputIteratorConcept<_InputIter1>)
1829 __glibcxx_function_requires(_InputIteratorConcept<_InputIter2>)
1830 __glibcxx_requires_valid_range(__first1, __last1);
1831 __glibcxx_requires_valid_range(__first2, __last2);
1833 using _Cat =
decltype(__comp(*__first1, *__first2));
1834 static_assert(same_as<common_comparison_category_t<_Cat>, _Cat>);
1836 if (!std::__is_constant_evaluated())
1837 if constexpr (same_as<_Comp, __detail::_Synth3way>
1838 || same_as<_Comp, compare_three_way>)
1839 if constexpr (__is_byte_iter<_InputIter1>)
1840 if constexpr (__is_byte_iter<_InputIter2>)
1842 const auto [__len, __lencmp] = _GLIBCXX_STD_A::
1843 __min_cmp(__last1 - __first1, __last2 - __first2);
1847 = __builtin_memcmp(&*__first1, &*__first2, __len) <=> 0;
1854 while (__first1 != __last1)
1856 if (__first2 == __last2)
1857 return strong_ordering::greater;
1858 if (
auto __cmp = __comp(*__first1, *__first2); __cmp != 0)
1863 return (__first2 == __last2) <=>
true;
1866 template<
typename _InputIter1,
typename _InputIter2>
1868 lexicographical_compare_three_way(_InputIter1 __first1,
1869 _InputIter1 __last1,
1870 _InputIter2 __first2,
1871 _InputIter2 __last2)
1873 return _GLIBCXX_STD_A::
1874 lexicographical_compare_three_way(__first1, __last1, __first2, __last2,
1875 compare_three_way{});
1879 template<
typename _InputIterator1,
typename _InputIterator2,
1880 typename _BinaryPredicate>
1881 _GLIBCXX20_CONSTEXPR
1882 pair<_InputIterator1, _InputIterator2>
1883 __mismatch(_InputIterator1 __first1, _InputIterator1 __last1,
1884 _InputIterator2 __first2, _BinaryPredicate __binary_pred)
1886 while (__first1 != __last1 && __binary_pred(__first1, __first2))
1891 return pair<_InputIterator1, _InputIterator2>(__first1, __first2);
1907 template<
typename _InputIterator1,
typename _InputIterator2>
1908 _GLIBCXX20_CONSTEXPR
1909 inline pair<_InputIterator1, _InputIterator2>
1910 mismatch(_InputIterator1 __first1, _InputIterator1 __last1,
1911 _InputIterator2 __first2)
1914 __glibcxx_function_requires(_InputIteratorConcept<_InputIterator1>)
1915 __glibcxx_function_requires(_InputIteratorConcept<_InputIterator2>)
1916 __glibcxx_function_requires(_EqualOpConcept<
1919 __glibcxx_requires_valid_range(__first1, __last1);
1921 return _GLIBCXX_STD_A::__mismatch(__first1, __last1, __first2,
1922 __gnu_cxx::__ops::__iter_equal_to_iter());
1941 template<
typename _InputIterator1,
typename _InputIterator2,
1942 typename _BinaryPredicate>
1943 _GLIBCXX20_CONSTEXPR
1944 inline pair<_InputIterator1, _InputIterator2>
1945 mismatch(_InputIterator1 __first1, _InputIterator1 __last1,
1946 _InputIterator2 __first2, _BinaryPredicate __binary_pred)
1949 __glibcxx_function_requires(_InputIteratorConcept<_InputIterator1>)
1950 __glibcxx_function_requires(_InputIteratorConcept<_InputIterator2>)
1951 __glibcxx_requires_valid_range(__first1, __last1);
1953 return _GLIBCXX_STD_A::__mismatch(__first1, __last1, __first2,
1954 __gnu_cxx::__ops::__iter_comp_iter(__binary_pred));
1957#if __cplusplus > 201103L
1959 template<
typename _InputIterator1,
typename _InputIterator2,
1960 typename _BinaryPredicate>
1961 _GLIBCXX20_CONSTEXPR
1962 pair<_InputIterator1, _InputIterator2>
1963 __mismatch(_InputIterator1 __first1, _InputIterator1 __last1,
1964 _InputIterator2 __first2, _InputIterator2 __last2,
1965 _BinaryPredicate __binary_pred)
1967 while (__first1 != __last1 && __first2 != __last2
1968 && __binary_pred(__first1, __first2))
1973 return pair<_InputIterator1, _InputIterator2>(__first1, __first2);
1990 template<
typename _InputIterator1,
typename _InputIterator2>
1991 _GLIBCXX20_CONSTEXPR
1992 inline pair<_InputIterator1, _InputIterator2>
1993 mismatch(_InputIterator1 __first1, _InputIterator1 __last1,
1994 _InputIterator2 __first2, _InputIterator2 __last2)
1997 __glibcxx_function_requires(_InputIteratorConcept<_InputIterator1>)
1998 __glibcxx_function_requires(_InputIteratorConcept<_InputIterator2>)
1999 __glibcxx_function_requires(_EqualOpConcept<
2002 __glibcxx_requires_valid_range(__first1, __last1);
2003 __glibcxx_requires_valid_range(__first2, __last2);
2005 return _GLIBCXX_STD_A::__mismatch(__first1, __last1, __first2, __last2,
2006 __gnu_cxx::__ops::__iter_equal_to_iter());
2026 template<
typename _InputIterator1,
typename _InputIterator2,
2027 typename _BinaryPredicate>
2028 _GLIBCXX20_CONSTEXPR
2029 inline pair<_InputIterator1, _InputIterator2>
2030 mismatch(_InputIterator1 __first1, _InputIterator1 __last1,
2031 _InputIterator2 __first2, _InputIterator2 __last2,
2032 _BinaryPredicate __binary_pred)
2035 __glibcxx_function_requires(_InputIteratorConcept<_InputIterator1>)
2036 __glibcxx_function_requires(_InputIteratorConcept<_InputIterator2>)
2037 __glibcxx_requires_valid_range(__first1, __last1);
2038 __glibcxx_requires_valid_range(__first2, __last2);
2040 return _GLIBCXX_STD_A::__mismatch(__first1, __last1, __first2, __last2,
2041 __gnu_cxx::__ops::__iter_comp_iter(__binary_pred));
2045_GLIBCXX_END_NAMESPACE_ALGO
2048 template<
typename _InputIterator,
typename _Predicate>
2049 _GLIBCXX20_CONSTEXPR
2050 inline _InputIterator
2054 while (__first != __last && !__pred(__first))
2060 template<
typename _RandomAccessIterator,
typename _Predicate>
2061 _GLIBCXX20_CONSTEXPR
2062 _RandomAccessIterator
2063 __find_if(_RandomAccessIterator __first, _RandomAccessIterator __last,
2067 __trip_count = (__last - __first) >> 2;
2069 for (; __trip_count > 0; --__trip_count)
2071 if (__pred(__first))
2075 if (__pred(__first))
2079 if (__pred(__first))
2083 if (__pred(__first))
2088 switch (__last - __first)
2091 if (__pred(__first))
2096 if (__pred(__first))
2101 if (__pred(__first))
2111 template<
typename _Iterator,
typename _Predicate>
2112 _GLIBCXX20_CONSTEXPR
2114 __find_if(_Iterator __first, _Iterator __last, _Predicate __pred)
2116 return __find_if(__first, __last, __pred,
2120 template<
typename _InputIterator,
typename _Predicate>
2121 _GLIBCXX20_CONSTEXPR
2122 typename iterator_traits<_InputIterator>::difference_type
2123 __count_if(_InputIterator __first, _InputIterator __last, _Predicate __pred)
2125 typename iterator_traits<_InputIterator>::difference_type __n = 0;
2126 for (; __first != __last; ++__first)
2127 if (__pred(__first))
2132 template<
typename _ForwardIterator,
typename _Predicate>
2133 _GLIBCXX20_CONSTEXPR
2135 __remove_if(_ForwardIterator __first, _ForwardIterator __last,
2139 if (__first == __last)
2141 _ForwardIterator __result = __first;
2143 for (; __first != __last; ++__first)
2144 if (!__pred(__first))
2146 *__result = _GLIBCXX_MOVE(*__first);
2152#if __cplusplus >= 201103L
2153 template<
typename _ForwardIterator1,
typename _ForwardIterator2,
2154 typename _BinaryPredicate>
2155 _GLIBCXX20_CONSTEXPR
2157 __is_permutation(_ForwardIterator1 __first1, _ForwardIterator1 __last1,
2158 _ForwardIterator2 __first2, _BinaryPredicate __pred)
2162 for (; __first1 != __last1; ++__first1, (void)++__first2)
2163 if (!__pred(__first1, __first2))
2166 if (__first1 == __last1)
2171 _ForwardIterator2 __last2 = __first2;
2173 for (_ForwardIterator1 __scan = __first1; __scan != __last1; ++__scan)
2176 __gnu_cxx::__ops::__iter_comp_iter(__pred, __scan)))
2180 = std::__count_if(__first2, __last2,
2181 __gnu_cxx::__ops::__iter_comp_iter(__pred, __scan));
2182 if (0 == __matches ||
2183 std::__count_if(__scan, __last1,
2184 __gnu_cxx::__ops::__iter_comp_iter(__pred, __scan))
2203 template<
typename _ForwardIterator1,
typename _ForwardIterator2>
2204 _GLIBCXX20_CONSTEXPR
2206 is_permutation(_ForwardIterator1 __first1, _ForwardIterator1 __last1,
2207 _ForwardIterator2 __first2)
2210 __glibcxx_function_requires(_ForwardIteratorConcept<_ForwardIterator1>)
2211 __glibcxx_function_requires(_ForwardIteratorConcept<_ForwardIterator2>)
2212 __glibcxx_function_requires(_EqualOpConcept<
2215 __glibcxx_requires_valid_range(__first1, __last1);
2217 return std::__is_permutation(__first1, __last1, __first2,
2218 __gnu_cxx::__ops::__iter_equal_to_iter());
2222_GLIBCXX_END_NAMESPACE_VERSION
2228#ifdef _GLIBCXX_PARALLEL
Parallel STL function calls corresponding to the stl_algobase.h header. The functions defined here ma...
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.
void swap(any &__x, any &__y) noexcept
Exchange the states of two any objects.
constexpr _OI copy(_II __first, _II __last, _OI __result)
Copies the range [first,last) into result.
constexpr _BI2 move_backward(_BI1 __first, _BI1 __last, _BI2 __result)
Moves the range [first,last) into result.
constexpr bool equal(_IIter1 __first1, _IIter1 __last1, _IIter2 __first2, _IIter2 __last2, _BinaryPredicate __binary_pred)
Tests a range for element-wise equality.
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 _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 int __lg(int __n)
This is a helper function for the sort routines and for random.tcc.
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.