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
99 if (std::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>
231 _GLIBCXX_NODISCARD _GLIBCXX14_CONSTEXPR
233 min(
const _Tp& __a,
const _Tp& __b)
236 __glibcxx_function_requires(_LessThanComparableConcept<_Tp>)
254 template<
typename _Tp>
255 _GLIBCXX_NODISCARD _GLIBCXX14_CONSTEXPR
257 max(
const _Tp& __a,
const _Tp& __b)
260 __glibcxx_function_requires(_LessThanComparableConcept<_Tp>)
278 template<
typename _Tp,
typename _Compare>
279 _GLIBCXX_NODISCARD _GLIBCXX14_CONSTEXPR
281 min(
const _Tp& __a,
const _Tp& __b, _Compare __comp)
284 if (__comp(__b, __a))
300 template<
typename _Tp,
typename _Compare>
301 _GLIBCXX_NODISCARD _GLIBCXX14_CONSTEXPR
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#if __cplusplus < 201103L
321 template<
typename _Ite,
typename _Seq>
323 __niter_base(const ::__gnu_debug::_Safe_iterator<_Ite, _Seq,
326 template<
typename _Ite,
typename _Cont,
typename _Seq>
328 __niter_base(const ::__gnu_debug::_Safe_iterator<
329 ::__gnu_cxx::__normal_iterator<_Ite, _Cont>, _Seq,
332 template<
typename _Ite,
typename _Seq>
334 decltype(std::__niter_base(std::declval<_Ite>()))
335 __niter_base(const ::__gnu_debug::_Safe_iterator<_Ite, _Seq,
337 noexcept(
std::is_nothrow_copy_constructible<_Ite>::value);
343 template<
typename _From,
typename _To>
346 __niter_wrap(_From __from, _To __res)
347 {
return __from + (std::__niter_base(__res) - std::__niter_base(__from)); }
350 template<
typename _Iterator>
353 __niter_wrap(
const _Iterator&, _Iterator __res)
362 template<
bool _IsMove,
bool _IsSimple,
typename _Category>
365 template<
typename _II,
typename _OI>
368 __copy_m(_II __first, _II __last, _OI __result)
370 for (; __first != __last; ++__result, (void)++__first)
371 *__result = *__first;
376#if __cplusplus >= 201103L
377 template<
typename _Category>
378 struct __copy_move<true, false, _Category>
380 template<
typename _II,
typename _OI>
383 __copy_m(_II __first, _II __last, _OI __result)
385 for (; __first != __last; ++__result, (void)++__first)
393 struct __copy_move<false, false, random_access_iterator_tag>
395 template<
typename _II,
typename _OI>
398 __copy_m(_II __first, _II __last, _OI __result)
400 typedef typename iterator_traits<_II>::difference_type _Distance;
401 for(_Distance __n = __last - __first; __n > 0; --__n)
403 *__result = *__first;
410 template<
typename _Tp,
typename _Up>
412 __assign_one(_Tp* __to, _Up* __from)
416#if __cplusplus >= 201103L
418 struct __copy_move<true, false, random_access_iterator_tag>
420 template<
typename _II,
typename _OI>
423 __copy_m(_II __first, _II __last, _OI __result)
425 typedef typename iterator_traits<_II>::difference_type _Distance;
426 for(_Distance __n = __last - __first; __n > 0; --__n)
435 template<
typename _Tp,
typename _Up>
437 __assign_one(_Tp* __to, _Up* __from)
442 template<
bool _IsMove>
443 struct __copy_move<_IsMove, true, random_access_iterator_tag>
445 template<
typename _Tp,
typename _Up>
448 __copy_m(_Tp* __first, _Tp* __last, _Up* __result)
450 const ptrdiff_t _Num = __last - __first;
451 if (__builtin_expect(_Num > 1,
true))
452 __builtin_memmove(__result, __first,
sizeof(_Tp) * _Num);
454 std::__copy_move<_IsMove, false, random_access_iterator_tag>::
455 __assign_one(__result, __first);
456 return __result + _Num;
460_GLIBCXX_BEGIN_NAMESPACE_CONTAINER
462 template<
typename _Tp,
typename _Ref,
typename _Ptr>
463 struct _Deque_iterator;
465 struct _Bit_iterator;
467_GLIBCXX_END_NAMESPACE_CONTAINER
472 template<
typename _CharT>
475 template<
typename _CharT,
typename _Traits>
476 class istreambuf_iterator;
478 template<
typename _CharT,
typename _Traits>
479 class ostreambuf_iterator;
481 template<
bool _IsMove,
typename _CharT>
482 typename __gnu_cxx::__enable_if<__is_char<_CharT>::__value,
483 ostreambuf_iterator<_CharT, char_traits<_CharT> > >::__type
484 __copy_move_a2(_CharT*, _CharT*,
485 ostreambuf_iterator<_CharT, char_traits<_CharT> >);
487 template<
bool _IsMove,
typename _CharT>
488 typename __gnu_cxx::__enable_if<__is_char<_CharT>::__value,
489 ostreambuf_iterator<_CharT, char_traits<_CharT> > >::__type
490 __copy_move_a2(
const _CharT*,
const _CharT*,
491 ostreambuf_iterator<_CharT, char_traits<_CharT> >);
493 template<
bool _IsMove,
typename _CharT>
494 typename __gnu_cxx::__enable_if<__is_char<_CharT>::__value,
496 __copy_move_a2(istreambuf_iterator<_CharT, char_traits<_CharT> >,
497 istreambuf_iterator<_CharT, char_traits<_CharT> >, _CharT*);
499 template<
bool _IsMove,
typename _CharT>
500 typename __gnu_cxx::__enable_if<
501 __is_char<_CharT>::__value,
502 _GLIBCXX_STD_C::_Deque_iterator<_CharT, _CharT&, _CharT*> >::__type
504 istreambuf_iterator<_CharT, char_traits<_CharT> >,
505 istreambuf_iterator<_CharT, char_traits<_CharT> >,
506 _GLIBCXX_STD_C::_Deque_iterator<_CharT, _CharT&, _CharT*>);
509 template<
bool _IsMove,
typename _II,
typename _OI>
512 __copy_move_a2(_II __first, _II __last, _OI __result)
514 typedef typename iterator_traits<_II>::iterator_category _Category;
515#ifdef __cpp_lib_is_constant_evaluated
516 if (std::is_constant_evaluated())
517 return std::__copy_move<_IsMove, false, _Category>::
518 __copy_m(__first, __last, __result);
520 return std::__copy_move<_IsMove, __memcpyable<_OI, _II>::__value,
521 _Category>::__copy_m(__first, __last, __result);
524 template<
bool _IsMove,
525 typename _Tp,
typename _Ref,
typename _Ptr,
typename _OI>
527 __copy_move_a1(_GLIBCXX_STD_C::_Deque_iterator<_Tp, _Ref, _Ptr>,
528 _GLIBCXX_STD_C::_Deque_iterator<_Tp, _Ref, _Ptr>,
531 template<
bool _IsMove,
532 typename _ITp,
typename _IRef,
typename _IPtr,
typename _OTp>
533 _GLIBCXX_STD_C::_Deque_iterator<_OTp, _OTp&, _OTp*>
534 __copy_move_a1(_GLIBCXX_STD_C::_Deque_iterator<_ITp, _IRef, _IPtr>,
535 _GLIBCXX_STD_C::_Deque_iterator<_ITp, _IRef, _IPtr>,
536 _GLIBCXX_STD_C::_Deque_iterator<_OTp, _OTp&, _OTp*>);
538 template<
bool _IsMove,
typename _II,
typename _Tp>
539 typename __gnu_cxx::__enable_if<
540 __is_random_access_iter<_II>::__value,
541 _GLIBCXX_STD_C::_Deque_iterator<_Tp, _Tp&, _Tp*> >::__type
542 __copy_move_a1(_II, _II, _GLIBCXX_STD_C::_Deque_iterator<_Tp, _Tp&, _Tp*>);
544 template<
bool _IsMove,
typename _II,
typename _OI>
547 __copy_move_a1(_II __first, _II __last, _OI __result)
548 {
return std::__copy_move_a2<_IsMove>(__first, __last, __result); }
550 template<
bool _IsMove,
typename _II,
typename _OI>
553 __copy_move_a(_II __first, _II __last, _OI __result)
555 return std::__niter_wrap(__result,
556 std::__copy_move_a1<_IsMove>(std::__niter_base(__first),
557 std::__niter_base(__last),
558 std::__niter_base(__result)));
561 template<
bool _IsMove,
562 typename _Ite,
typename _Seq,
typename _Cat,
typename _OI>
565 __copy_move_a(const ::__gnu_debug::_Safe_iterator<_Ite, _Seq, _Cat>&,
566 const ::__gnu_debug::_Safe_iterator<_Ite, _Seq, _Cat>&,
569 template<
bool _IsMove,
570 typename _II,
typename _Ite,
typename _Seq,
typename _Cat>
573 __copy_move_a(_II, _II,
574 const ::__gnu_debug::_Safe_iterator<_Ite, _Seq, _Cat>&);
576 template<
bool _IsMove,
577 typename _IIte,
typename _ISeq,
typename _ICat,
578 typename _OIte,
typename _OSeq,
typename _OCat>
580 ::__gnu_debug::_Safe_iterator<_OIte, _OSeq, _OCat>
581 __copy_move_a(const ::__gnu_debug::_Safe_iterator<_IIte, _ISeq, _ICat>&,
582 const ::__gnu_debug::_Safe_iterator<_IIte, _ISeq, _ICat>&,
583 const ::__gnu_debug::_Safe_iterator<_OIte, _OSeq, _OCat>&);
585 template<
typename _InputIterator,
typename _Size,
typename _OutputIterator>
588 __copy_n_a(_InputIterator __first, _Size __n, _OutputIterator __result,
595 *__result = *__first;
607 template<
typename _CharT,
typename _Size>
608 typename __gnu_cxx::__enable_if<
609 __is_char<_CharT>::__value, _CharT*>::__type
610 __copy_n_a(istreambuf_iterator<_CharT, char_traits<_CharT> >,
611 _Size, _CharT*,
bool);
613 template<
typename _CharT,
typename _Size>
614 typename __gnu_cxx::__enable_if<
615 __is_char<_CharT>::__value,
616 _GLIBCXX_STD_C::_Deque_iterator<_CharT, _CharT&, _CharT*> >::__type
617 __copy_n_a(istreambuf_iterator<_CharT, char_traits<_CharT> >, _Size,
618 _GLIBCXX_STD_C::_Deque_iterator<_CharT, _CharT&, _CharT*>,
639 template<
typename _II,
typename _OI>
642 copy(_II __first, _II __last, _OI __result)
645 __glibcxx_function_requires(_InputIteratorConcept<_II>)
646 __glibcxx_function_requires(_OutputIteratorConcept<_OI,
648 __glibcxx_requires_can_increment_range(__first, __last, __result);
650 return std::__copy_move_a<__is_move_iterator<_II>::__value>
651 (std::__miter_base(__first), std::__miter_base(__last), __result);
654#if __cplusplus >= 201103L
672 template<
typename _II,
typename _OI>
675 move(_II __first, _II __last, _OI __result)
678 __glibcxx_function_requires(_InputIteratorConcept<_II>)
679 __glibcxx_function_requires(_OutputIteratorConcept<_OI,
681 __glibcxx_requires_can_increment_range(__first, __last, __result);
683 return std::__copy_move_a<true>(std::__miter_base(__first),
684 std::__miter_base(__last), __result);
687#define _GLIBCXX_MOVE3(_Tp, _Up, _Vp) std::move(_Tp, _Up, _Vp)
689#define _GLIBCXX_MOVE3(_Tp, _Up, _Vp) std::copy(_Tp, _Up, _Vp)
692 template<
bool _IsMove,
bool _IsSimple,
typename _Category>
693 struct __copy_move_backward
695 template<
typename _BI1,
typename _BI2>
698 __copy_move_b(_BI1 __first, _BI1 __last, _BI2 __result)
700 while (__first != __last)
701 *--__result = *--__last;
706#if __cplusplus >= 201103L
707 template<
typename _Category>
708 struct __copy_move_backward<true, false, _Category>
710 template<
typename _BI1,
typename _BI2>
713 __copy_move_b(_BI1 __first, _BI1 __last, _BI2 __result)
715 while (__first != __last)
723 struct __copy_move_backward<false, false, random_access_iterator_tag>
725 template<
typename _BI1,
typename _BI2>
728 __copy_move_b(_BI1 __first, _BI1 __last, _BI2 __result)
730 typename iterator_traits<_BI1>::difference_type
731 __n = __last - __first;
732 for (; __n > 0; --__n)
733 *--__result = *--__last;
738#if __cplusplus >= 201103L
740 struct __copy_move_backward<true, false, random_access_iterator_tag>
742 template<
typename _BI1,
typename _BI2>
745 __copy_move_b(_BI1 __first, _BI1 __last, _BI2 __result)
747 typename iterator_traits<_BI1>::difference_type
748 __n = __last - __first;
749 for (; __n > 0; --__n)
756 template<
bool _IsMove>
757 struct __copy_move_backward<_IsMove, true, random_access_iterator_tag>
759 template<
typename _Tp,
typename _Up>
762 __copy_move_b(_Tp* __first, _Tp* __last, _Up* __result)
764 const ptrdiff_t _Num = __last - __first;
765 if (__builtin_expect(_Num > 1,
true))
766 __builtin_memmove(__result - _Num, __first,
sizeof(_Tp) * _Num);
768 std::__copy_move<_IsMove, false, random_access_iterator_tag>::
769 __assign_one(__result - 1, __first);
770 return __result - _Num;
774 template<
bool _IsMove,
typename _BI1,
typename _BI2>
777 __copy_move_backward_a2(_BI1 __first, _BI1 __last, _BI2 __result)
779 typedef typename iterator_traits<_BI1>::iterator_category _Category;
780#ifdef __cpp_lib_is_constant_evaluated
781 if (std::is_constant_evaluated())
782 return std::__copy_move_backward<_IsMove, false, _Category>::
783 __copy_move_b(__first, __last, __result);
785 return std::__copy_move_backward<_IsMove,
786 __memcpyable<_BI2, _BI1>::__value,
787 _Category>::__copy_move_b(__first,
792 template<
bool _IsMove,
typename _BI1,
typename _BI2>
795 __copy_move_backward_a1(_BI1 __first, _BI1 __last, _BI2 __result)
796 {
return std::__copy_move_backward_a2<_IsMove>(__first, __last, __result); }
798 template<
bool _IsMove,
799 typename _Tp,
typename _Ref,
typename _Ptr,
typename _OI>
801 __copy_move_backward_a1(_GLIBCXX_STD_C::_Deque_iterator<_Tp, _Ref, _Ptr>,
802 _GLIBCXX_STD_C::_Deque_iterator<_Tp, _Ref, _Ptr>,
805 template<
bool _IsMove,
806 typename _ITp,
typename _IRef,
typename _IPtr,
typename _OTp>
807 _GLIBCXX_STD_C::_Deque_iterator<_OTp, _OTp&, _OTp*>
808 __copy_move_backward_a1(
809 _GLIBCXX_STD_C::_Deque_iterator<_ITp, _IRef, _IPtr>,
810 _GLIBCXX_STD_C::_Deque_iterator<_ITp, _IRef, _IPtr>,
811 _GLIBCXX_STD_C::_Deque_iterator<_OTp, _OTp&, _OTp*>);
813 template<
bool _IsMove,
typename _II,
typename _Tp>
814 typename __gnu_cxx::__enable_if<
815 __is_random_access_iter<_II>::__value,
816 _GLIBCXX_STD_C::_Deque_iterator<_Tp, _Tp&, _Tp*> >::__type
817 __copy_move_backward_a1(_II, _II,
818 _GLIBCXX_STD_C::_Deque_iterator<_Tp, _Tp&, _Tp*>);
820 template<
bool _IsMove,
typename _II,
typename _OI>
823 __copy_move_backward_a(_II __first, _II __last, _OI __result)
825 return std::__niter_wrap(__result,
826 std::__copy_move_backward_a1<_IsMove>
827 (std::__niter_base(__first), std::__niter_base(__last),
828 std::__niter_base(__result)));
831 template<
bool _IsMove,
832 typename _Ite,
typename _Seq,
typename _Cat,
typename _OI>
835 __copy_move_backward_a(
836 const ::__gnu_debug::_Safe_iterator<_Ite, _Seq, _Cat>&,
837 const ::__gnu_debug::_Safe_iterator<_Ite, _Seq, _Cat>&,
840 template<
bool _IsMove,
841 typename _II,
typename _Ite,
typename _Seq,
typename _Cat>
844 __copy_move_backward_a(_II, _II,
845 const ::__gnu_debug::_Safe_iterator<_Ite, _Seq, _Cat>&);
847 template<
bool _IsMove,
848 typename _IIte,
typename _ISeq,
typename _ICat,
849 typename _OIte,
typename _OSeq,
typename _OCat>
851 ::__gnu_debug::_Safe_iterator<_OIte, _OSeq, _OCat>
852 __copy_move_backward_a(
853 const ::__gnu_debug::_Safe_iterator<_IIte, _ISeq, _ICat>&,
854 const ::__gnu_debug::_Safe_iterator<_IIte, _ISeq, _ICat>&,
855 const ::__gnu_debug::_Safe_iterator<_OIte, _OSeq, _OCat>&);
875 template<
typename _BI1,
typename _BI2>
878 copy_backward(_BI1 __first, _BI1 __last, _BI2 __result)
881 __glibcxx_function_requires(_BidirectionalIteratorConcept<_BI1>)
882 __glibcxx_function_requires(_Mutable_BidirectionalIteratorConcept<_BI2>)
883 __glibcxx_function_requires(_OutputIteratorConcept<_BI2,
885 __glibcxx_requires_can_decrement_range(__first, __last, __result);
887 return std::__copy_move_backward_a<__is_move_iterator<_BI1>::__value>
888 (std::__miter_base(__first), std::__miter_base(__last), __result);
891#if __cplusplus >= 201103L
910 template<
typename _BI1,
typename _BI2>
916 __glibcxx_function_requires(_BidirectionalIteratorConcept<_BI1>)
917 __glibcxx_function_requires(_Mutable_BidirectionalIteratorConcept<_BI2>)
918 __glibcxx_function_requires(_OutputIteratorConcept<_BI2,
920 __glibcxx_requires_can_decrement_range(__first, __last, __result);
922 return std::__copy_move_backward_a<true>(std::__miter_base(__first),
923 std::__miter_base(__last),
927#define _GLIBCXX_MOVE_BACKWARD3(_Tp, _Up, _Vp) std::move_backward(_Tp, _Up, _Vp)
929#define _GLIBCXX_MOVE_BACKWARD3(_Tp, _Up, _Vp) std::copy_backward(_Tp, _Up, _Vp)
932#pragma GCC diagnostic push
933#pragma GCC diagnostic ignored "-Wc++17-extensions"
934 template<
typename _ForwardIterator,
typename _Tp>
937 __fill_a1(_ForwardIterator __first, _ForwardIterator __last,
944 const bool __load_outside_loop =
945#if __has_builtin(__is_trivially_constructible) \
946 && __has_builtin(__is_trivially_assignable)
947 __is_trivially_constructible(_Tp,
const _Tp&)
948 && __is_trivially_assignable(__decltype(*__first),
const _Tp&)
950 __is_trivially_copyable(_Tp)
951 && __is_same(_Tp, __typeof__(*__first))
953 &&
sizeof(_Tp) <=
sizeof(
long long);
957 typedef typename __gnu_cxx::__conditional_type<__load_outside_loop,
959 const _Tp&>::__type _Up;
961 for (; __first != __last; ++__first)
964#pragma GCC diagnostic pop
967 template<
typename _Tp>
970 __gnu_cxx::__enable_if<__is_byte<_Tp>::__value,
void>::__type
971 __fill_a1(_Tp* __first, _Tp* __last,
const _Tp& __c)
973 const _Tp __tmp = __c;
974#if __cpp_lib_is_constant_evaluated
975 if (std::is_constant_evaluated())
977 for (; __first != __last; ++__first)
982 if (
const size_t __len = __last - __first)
983 __builtin_memset(__first,
static_cast<unsigned char>(__tmp), __len);
986 template<
typename _Ite,
typename _Cont,
typename _Tp>
989 __fill_a1(::__gnu_cxx::__normal_iterator<_Ite, _Cont> __first,
990 ::__gnu_cxx::__normal_iterator<_Ite, _Cont> __last,
992 { std::__fill_a1(__first.base(), __last.base(), __value); }
994 template<
typename _Tp,
typename _VTp>
996 __fill_a1(
const _GLIBCXX_STD_C::_Deque_iterator<_Tp, _Tp&, _Tp*>&,
997 const _GLIBCXX_STD_C::_Deque_iterator<_Tp, _Tp&, _Tp*>&,
1000 _GLIBCXX20_CONSTEXPR
1002 __fill_a1(_GLIBCXX_STD_C::_Bit_iterator, _GLIBCXX_STD_C::_Bit_iterator,
1005 template<
typename _FIte,
typename _Tp>
1006 _GLIBCXX20_CONSTEXPR
1008 __fill_a(_FIte __first, _FIte __last,
const _Tp& __value)
1009 { std::__fill_a1(__first, __last, __value); }
1011 template<
typename _Ite,
typename _Seq,
typename _Cat,
typename _Tp>
1012 _GLIBCXX20_CONSTEXPR
1014 __fill_a(const ::__gnu_debug::_Safe_iterator<_Ite, _Seq, _Cat>&,
1015 const ::__gnu_debug::_Safe_iterator<_Ite, _Seq, _Cat>&,
1030 template<
typename _ForwardIterator,
typename _Tp>
1031 _GLIBCXX20_CONSTEXPR
1033 fill(_ForwardIterator __first, _ForwardIterator __last,
const _Tp& __value)
1036 __glibcxx_function_requires(_Mutable_ForwardIteratorConcept<
1038 __glibcxx_requires_valid_range(__first, __last);
1040 std::__fill_a(__first, __last, __value);
1044 inline _GLIBCXX_CONSTEXPR
int
1045 __size_to_integer(
int __n) {
return __n; }
1046 inline _GLIBCXX_CONSTEXPR
unsigned
1047 __size_to_integer(
unsigned __n) {
return __n; }
1048 inline _GLIBCXX_CONSTEXPR
long
1049 __size_to_integer(
long __n) {
return __n; }
1050 inline _GLIBCXX_CONSTEXPR
unsigned long
1051 __size_to_integer(
unsigned long __n) {
return __n; }
1052 inline _GLIBCXX_CONSTEXPR
long long
1053 __size_to_integer(
long long __n) {
return __n; }
1054 inline _GLIBCXX_CONSTEXPR
unsigned long long
1055 __size_to_integer(
unsigned long long __n) {
return __n; }
1057#if defined(__GLIBCXX_TYPE_INT_N_0)
1058 __extension__
inline _GLIBCXX_CONSTEXPR __GLIBCXX_TYPE_INT_N_0
1059 __size_to_integer(__GLIBCXX_TYPE_INT_N_0 __n) {
return __n; }
1060 __extension__
inline _GLIBCXX_CONSTEXPR
unsigned __GLIBCXX_TYPE_INT_N_0
1061 __size_to_integer(
unsigned __GLIBCXX_TYPE_INT_N_0 __n) {
return __n; }
1063#if defined(__GLIBCXX_TYPE_INT_N_1)
1064 __extension__
inline _GLIBCXX_CONSTEXPR __GLIBCXX_TYPE_INT_N_1
1065 __size_to_integer(__GLIBCXX_TYPE_INT_N_1 __n) {
return __n; }
1066 __extension__
inline _GLIBCXX_CONSTEXPR
unsigned __GLIBCXX_TYPE_INT_N_1
1067 __size_to_integer(
unsigned __GLIBCXX_TYPE_INT_N_1 __n) {
return __n; }
1069#if defined(__GLIBCXX_TYPE_INT_N_2)
1070 __extension__
inline _GLIBCXX_CONSTEXPR __GLIBCXX_TYPE_INT_N_2
1071 __size_to_integer(__GLIBCXX_TYPE_INT_N_2 __n) {
return __n; }
1072 __extension__
inline _GLIBCXX_CONSTEXPR
unsigned __GLIBCXX_TYPE_INT_N_2
1073 __size_to_integer(
unsigned __GLIBCXX_TYPE_INT_N_2 __n) {
return __n; }
1075#if defined(__GLIBCXX_TYPE_INT_N_3)
1076 __extension__
inline _GLIBCXX_CONSTEXPR
unsigned __GLIBCXX_TYPE_INT_N_3
1077 __size_to_integer(__GLIBCXX_TYPE_INT_N_3 __n) {
return __n; }
1078 __extension__
inline _GLIBCXX_CONSTEXPR __GLIBCXX_TYPE_INT_N_3
1079 __size_to_integer(
unsigned __GLIBCXX_TYPE_INT_N_3 __n) {
return __n; }
1082 inline _GLIBCXX_CONSTEXPR
long long
1083 __size_to_integer(
float __n) {
return (
long long)__n; }
1084 inline _GLIBCXX_CONSTEXPR
long long
1085 __size_to_integer(
double __n) {
return (
long long)__n; }
1086 inline _GLIBCXX_CONSTEXPR
long long
1087 __size_to_integer(
long double __n) {
return (
long long)__n; }
1088#if !defined(__STRICT_ANSI__) && defined(_GLIBCXX_USE_FLOAT128)
1089 __extension__
inline _GLIBCXX_CONSTEXPR
long long
1090 __size_to_integer(__float128 __n) {
return (
long long)__n; }
1093#pragma GCC diagnostic push
1094#pragma GCC diagnostic ignored "-Wc++17-extensions"
1095 template<
typename _OutputIterator,
typename _Size,
typename _Tp>
1096 _GLIBCXX20_CONSTEXPR
1097 inline _OutputIterator
1098 __fill_n_a1(_OutputIterator __first, _Size __n,
const _Tp& __value)
1101 const bool __load_outside_loop =
1102#if __has_builtin(__is_trivially_constructible) \
1103 && __has_builtin(__is_trivially_assignable)
1104 __is_trivially_constructible(_Tp,
const _Tp&)
1105 && __is_trivially_assignable(__decltype(*__first),
const _Tp&)
1107 __is_trivially_copyable(_Tp)
1108 && __is_same(_Tp, __typeof__(*__first))
1110 &&
sizeof(_Tp) <=
sizeof(
long long);
1114 typedef typename __gnu_cxx::__conditional_type<__load_outside_loop,
1116 const _Tp&>::__type _Up;
1118 for (; __n > 0; --__n, (void) ++__first)
1122#pragma GCC diagnostic pop
1124 template<
typename _Ite,
typename _Seq,
typename _Cat,
typename _Size,
1126 _GLIBCXX20_CONSTEXPR
1127 ::__gnu_debug::_Safe_iterator<_Ite, _Seq, _Cat>
1128 __fill_n_a(const ::__gnu_debug::_Safe_iterator<_Ite, _Seq, _Cat>& __first,
1129 _Size __n,
const _Tp& __value,
1132 template<
typename _OutputIterator,
typename _Size,
typename _Tp>
1133 _GLIBCXX20_CONSTEXPR
1134 inline _OutputIterator
1135 __fill_n_a(_OutputIterator __first, _Size __n,
const _Tp& __value,
1138#if __cplusplus >= 201103L
1139 static_assert(is_integral<_Size>{},
"fill_n must pass integral size");
1141 return __fill_n_a1(__first, __n, __value);
1144 template<
typename _OutputIterator,
typename _Size,
typename _Tp>
1145 _GLIBCXX20_CONSTEXPR
1146 inline _OutputIterator
1147 __fill_n_a(_OutputIterator __first, _Size __n,
const _Tp& __value,
1150#if __cplusplus >= 201103L
1151 static_assert(is_integral<_Size>{},
"fill_n must pass integral size");
1153 return __fill_n_a1(__first, __n, __value);
1156 template<
typename _OutputIterator,
typename _Size,
typename _Tp>
1157 _GLIBCXX20_CONSTEXPR
1158 inline _OutputIterator
1159 __fill_n_a(_OutputIterator __first, _Size __n,
const _Tp& __value,
1162#if __cplusplus >= 201103L
1163 static_assert(is_integral<_Size>{},
"fill_n must pass integral size");
1168 __glibcxx_requires_can_increment(__first, __n);
1170 std::__fill_a(__first, __first + __n, __value);
1171 return __first + __n;
1191 template<
typename _OI,
typename _Size,
typename _Tp>
1192 _GLIBCXX20_CONSTEXPR
1194 fill_n(_OI __first, _Size __n,
const _Tp& __value)
1197 __glibcxx_function_requires(_OutputIteratorConcept<_OI, const _Tp&>)
1199 return std::__fill_n_a(__first, std::__size_to_integer(__n), __value,
1203 template<
bool _BoolType>
1206 template<
typename _II1,
typename _II2>
1207 _GLIBCXX20_CONSTEXPR
1209 equal(_II1 __first1, _II1 __last1, _II2 __first2)
1211 for (; __first1 != __last1; ++__first1, (void) ++__first2)
1212 if (!(*__first1 == *__first2))
1219 struct __equal<true>
1221 template<
typename _Tp>
1222 _GLIBCXX20_CONSTEXPR
1224 equal(
const _Tp* __first1,
const _Tp* __last1,
const _Tp* __first2)
1226 if (
const size_t __len = (__last1 - __first1))
1227 return !std::__memcmp(__first1, __first2, __len);
1232 template<
typename _Tp,
typename _Ref,
typename _Ptr,
typename _II>
1233 typename __gnu_cxx::__enable_if<
1234 __is_random_access_iter<_II>::__value,
bool>::__type
1235 __equal_aux1(_GLIBCXX_STD_C::_Deque_iterator<_Tp, _Ref, _Ptr>,
1236 _GLIBCXX_STD_C::_Deque_iterator<_Tp, _Ref, _Ptr>,
1239 template<
typename _Tp1,
typename _Ref1,
typename _Ptr1,
1240 typename _Tp2,
typename _Ref2,
typename _Ptr2>
1242 __equal_aux1(_GLIBCXX_STD_C::_Deque_iterator<_Tp1, _Ref1, _Ptr1>,
1243 _GLIBCXX_STD_C::_Deque_iterator<_Tp1, _Ref1, _Ptr1>,
1244 _GLIBCXX_STD_C::_Deque_iterator<_Tp2, _Ref2, _Ptr2>);
1246 template<
typename _II,
typename _Tp,
typename _Ref,
typename _Ptr>
1247 typename __gnu_cxx::__enable_if<
1248 __is_random_access_iter<_II>::__value,
bool>::__type
1249 __equal_aux1(_II, _II,
1250 _GLIBCXX_STD_C::_Deque_iterator<_Tp, _Ref, _Ptr>);
1252 template<
typename _II1,
typename _II2>
1253 _GLIBCXX20_CONSTEXPR
1255 __equal_aux1(_II1 __first1, _II1 __last1, _II2 __first2)
1257 typedef typename iterator_traits<_II1>::value_type _ValueType1;
1258 const bool __simple = ((__is_integer<_ValueType1>::__value
1259#if _GLIBCXX_USE_BUILTIN_TRAIT(__is_pointer)
1260 || __is_pointer(_ValueType1)
1262#if __glibcxx_byte && __glibcxx_type_trait_variable_templates
1264 || is_same_v<_ValueType1, byte>
1266 ) && __memcmpable<_II1, _II2>::__value);
1267 return std::__equal<__simple>::equal(__first1, __last1, __first2);
1270 template<
typename _II1,
typename _II2>
1271 _GLIBCXX20_CONSTEXPR
1273 __equal_aux(_II1 __first1, _II1 __last1, _II2 __first2)
1275 return std::__equal_aux1(std::__niter_base(__first1),
1276 std::__niter_base(__last1),
1277 std::__niter_base(__first2));
1280 template<
typename _II1,
typename _Seq1,
typename _Cat1,
typename _II2>
1281 _GLIBCXX20_CONSTEXPR
1283 __equal_aux(const ::__gnu_debug::_Safe_iterator<_II1, _Seq1, _Cat1>&,
1284 const ::__gnu_debug::_Safe_iterator<_II1, _Seq1, _Cat1>&,
1287 template<
typename _II1,
typename _II2,
typename _Seq2,
typename _Cat2>
1288 _GLIBCXX20_CONSTEXPR
1290 __equal_aux(_II1, _II1,
1291 const ::__gnu_debug::_Safe_iterator<_II2, _Seq2, _Cat2>&);
1293 template<
typename _II1,
typename _Seq1,
typename _Cat1,
1294 typename _II2,
typename _Seq2,
typename _Cat2>
1295 _GLIBCXX20_CONSTEXPR
1297 __equal_aux(const ::__gnu_debug::_Safe_iterator<_II1, _Seq1, _Cat1>&,
1298 const ::__gnu_debug::_Safe_iterator<_II1, _Seq1, _Cat1>&,
1299 const ::__gnu_debug::_Safe_iterator<_II2, _Seq2, _Cat2>&);
1301 template<
typename,
typename>
1304 template<
typename _II1,
typename _II2>
1305 _GLIBCXX20_CONSTEXPR
1307 __newlast1(_II1, _II1 __last1, _II2, _II2)
1310 template<
typename _II>
1311 _GLIBCXX20_CONSTEXPR
1313 __cnd2(_II __first, _II __last)
1314 {
return __first != __last; }
1318 struct __lc_rai<random_access_iterator_tag, random_access_iterator_tag>
1320 template<
typename _RAI1,
typename _RAI2>
1321 _GLIBCXX20_CONSTEXPR
1323 __newlast1(_RAI1 __first1, _RAI1 __last1,
1324 _RAI2 __first2, _RAI2 __last2)
1326 const typename iterator_traits<_RAI1>::difference_type
1327 __diff1 = __last1 - __first1;
1328 const typename iterator_traits<_RAI2>::difference_type
1329 __diff2 = __last2 - __first2;
1330 return __diff2 < __diff1 ? __first1 + __diff2 : __last1;
1333 template<
typename _RAI>
1334 static _GLIBCXX20_CONSTEXPR
bool
1339 template<
typename _II1,
typename _II2,
typename _Compare>
1340 _GLIBCXX20_CONSTEXPR
1342 __lexicographical_compare_impl(_II1 __first1, _II1 __last1,
1343 _II2 __first2, _II2 __last2,
1346 typedef typename iterator_traits<_II1>::iterator_category _Category1;
1347 typedef typename iterator_traits<_II2>::iterator_category _Category2;
1348 typedef std::__lc_rai<_Category1, _Category2> __rai_type;
1350 __last1 = __rai_type::__newlast1(__first1, __last1, __first2, __last2);
1351 for (; __first1 != __last1 && __rai_type::__cnd2(__first2, __last2);
1352 ++__first1, (void)++__first2)
1354 if (__comp(__first1, __first2))
1356 if (__comp(__first2, __first1))
1359 return __first1 == __last1 && __first2 != __last2;
1362 template<
bool _BoolType>
1363 struct __lexicographical_compare
1365 template<
typename _II1,
typename _II2>
1366 _GLIBCXX20_CONSTEXPR
1368 __lc(_II1 __first1, _II1 __last1, _II2 __first2, _II2 __last2)
1370 using __gnu_cxx::__ops::__iter_less_iter;
1371 return std::__lexicographical_compare_impl(__first1, __last1,
1373 __iter_less_iter());
1376 template<
typename _II1,
typename _II2>
1377 _GLIBCXX20_CONSTEXPR
1379 __3way(_II1 __first1, _II1 __last1, _II2 __first2, _II2 __last2)
1381 while (__first1 != __last1)
1383 if (__first2 == __last2)
1385 if (*__first1 < *__first2)
1387 if (*__first2 < *__first1)
1392 return int(__first2 == __last2) - 1;
1397 struct __lexicographical_compare<true>
1399 template<
typename _Tp,
typename _Up>
1400 _GLIBCXX20_CONSTEXPR
1402 __lc(
const _Tp* __first1,
const _Tp* __last1,
1403 const _Up* __first2,
const _Up* __last2)
1404 {
return __3way(__first1, __last1, __first2, __last2) < 0; }
1406 template<
typename _Tp,
typename _Up>
1407 _GLIBCXX20_CONSTEXPR
1409 __3way(
const _Tp* __first1,
const _Tp* __last1,
1410 const _Up* __first2,
const _Up* __last2)
1412 const size_t __len1 = __last1 - __first1;
1413 const size_t __len2 = __last2 - __first2;
1414 if (
const size_t __len =
std::min(__len1, __len2))
1415 if (
int __result = std::__memcmp(__first1, __first2, __len))
1417 return ptrdiff_t(__len1 - __len2);
1421 template<
typename _II1,
typename _II2>
1422 _GLIBCXX20_CONSTEXPR
1424 __lexicographical_compare_aux1(_II1 __first1, _II1 __last1,
1425 _II2 __first2, _II2 __last2)
1427 typedef typename iterator_traits<_II1>::value_type _ValueType1;
1428 typedef typename iterator_traits<_II2>::value_type _ValueType2;
1429#if _GLIBCXX_USE_BUILTIN_TRAIT(__is_pointer)
1430 const bool __simple =
1431 (__is_memcmp_ordered_with<_ValueType1, _ValueType2>::__value
1432 && __is_pointer(_II1) && __is_pointer(_II2)
1433#if __cplusplus > 201703L && __glibcxx_concepts
1437 && !is_volatile_v<remove_reference_t<iter_reference_t<_II1>>>
1438 && !is_volatile_v<remove_reference_t<iter_reference_t<_II2>>>
1442 const bool __simple =
false;
1445 return std::__lexicographical_compare<__simple>::__lc(__first1, __last1,
1449 template<
typename _Tp1,
typename _Ref1,
typename _Ptr1,
1452 __lexicographical_compare_aux1(
1453 _GLIBCXX_STD_C::_Deque_iterator<_Tp1, _Ref1, _Ptr1>,
1454 _GLIBCXX_STD_C::_Deque_iterator<_Tp1, _Ref1, _Ptr1>,
1457 template<
typename _Tp1,
1458 typename _Tp2,
typename _Ref2,
typename _Ptr2>
1460 __lexicographical_compare_aux1(_Tp1*, _Tp1*,
1461 _GLIBCXX_STD_C::_Deque_iterator<_Tp2, _Ref2, _Ptr2>,
1462 _GLIBCXX_STD_C::_Deque_iterator<_Tp2, _Ref2, _Ptr2>);
1464 template<
typename _Tp1,
typename _Ref1,
typename _Ptr1,
1465 typename _Tp2,
typename _Ref2,
typename _Ptr2>
1467 __lexicographical_compare_aux1(
1468 _GLIBCXX_STD_C::_Deque_iterator<_Tp1, _Ref1, _Ptr1>,
1469 _GLIBCXX_STD_C::_Deque_iterator<_Tp1, _Ref1, _Ptr1>,
1470 _GLIBCXX_STD_C::_Deque_iterator<_Tp2, _Ref2, _Ptr2>,
1471 _GLIBCXX_STD_C::_Deque_iterator<_Tp2, _Ref2, _Ptr2>);
1473 template<
typename _II1,
typename _II2>
1474 _GLIBCXX20_CONSTEXPR
1476 __lexicographical_compare_aux(_II1 __first1, _II1 __last1,
1477 _II2 __first2, _II2 __last2)
1479 return std::__lexicographical_compare_aux1(std::__niter_base(__first1),
1480 std::__niter_base(__last1),
1481 std::__niter_base(__first2),
1482 std::__niter_base(__last2));
1485 template<
typename _Iter1,
typename _Seq1,
typename _Cat1,
1487 _GLIBCXX20_CONSTEXPR
1489 __lexicographical_compare_aux(
1490 const ::__gnu_debug::_Safe_iterator<_Iter1, _Seq1, _Cat1>&,
1491 const ::__gnu_debug::_Safe_iterator<_Iter1, _Seq1, _Cat1>&,
1494 template<
typename _II1,
1495 typename _Iter2,
typename _Seq2,
typename _Cat2>
1496 _GLIBCXX20_CONSTEXPR
1498 __lexicographical_compare_aux(
1500 const ::__gnu_debug::_Safe_iterator<_Iter2, _Seq2, _Cat2>&,
1501 const ::__gnu_debug::_Safe_iterator<_Iter2, _Seq2, _Cat2>&);
1503 template<
typename _Iter1,
typename _Seq1,
typename _Cat1,
1504 typename _Iter2,
typename _Seq2,
typename _Cat2>
1505 _GLIBCXX20_CONSTEXPR
1507 __lexicographical_compare_aux(
1508 const ::__gnu_debug::_Safe_iterator<_Iter1, _Seq1, _Cat1>&,
1509 const ::__gnu_debug::_Safe_iterator<_Iter1, _Seq1, _Cat1>&,
1510 const ::__gnu_debug::_Safe_iterator<_Iter2, _Seq2, _Cat2>&,
1511 const ::__gnu_debug::_Safe_iterator<_Iter2, _Seq2, _Cat2>&);
1513 template<
typename _ForwardIterator,
typename _Tp,
typename _Compare>
1514 _GLIBCXX20_CONSTEXPR
1516 __lower_bound(_ForwardIterator __first, _ForwardIterator __last,
1517 const _Tp& __val, _Compare __comp)
1519 typedef typename iterator_traits<_ForwardIterator>::difference_type
1526 _DistanceType __half = __len >> 1;
1527 _ForwardIterator __middle = __first;
1529 if (__comp(__middle, __val))
1533 __len = __len - __half - 1;
1552 template<
typename _ForwardIterator,
typename _Tp>
1553 _GLIBCXX_NODISCARD _GLIBCXX20_CONSTEXPR
1554 inline _ForwardIterator
1555 lower_bound(_ForwardIterator __first, _ForwardIterator __last,
1559 __glibcxx_function_requires(_ForwardIteratorConcept<_ForwardIterator>)
1560 __glibcxx_function_requires(_LessThanOpConcept<
1562 __glibcxx_requires_partitioned_lower(__first, __last, __val);
1564 return std::__lower_bound(__first, __last, __val,
1565 __gnu_cxx::__ops::__iter_less_val());
1570 template<
typename _Tp>
1571 inline _GLIBCXX_CONSTEXPR _Tp
1574#if __cplusplus >= 201402L
1578 return (
sizeof(+__n) * __CHAR_BIT__ - 1)
1579 - (
sizeof(+__n) ==
sizeof(
long long)
1580 ? __builtin_clzll(+__n)
1581 : (
sizeof(+__n) ==
sizeof(
long)
1582 ? __builtin_clzl(+__n)
1583 : __builtin_clz(+__n)));
1587_GLIBCXX_BEGIN_NAMESPACE_ALGO
1601 template<
typename _II1,
typename _II2>
1602 _GLIBCXX_NODISCARD _GLIBCXX20_CONSTEXPR
1604 equal(_II1 __first1, _II1 __last1, _II2 __first2)
1607 __glibcxx_function_requires(_InputIteratorConcept<_II1>)
1608 __glibcxx_function_requires(_InputIteratorConcept<_II2>)
1609 __glibcxx_function_requires(_EqualOpConcept<
1612 __glibcxx_requires_can_increment_range(__first1, __last1, __first2);
1614 return std::__equal_aux(__first1, __last1, __first2);
1632 template<
typename _IIter1,
typename _IIter2,
typename _BinaryPredicate>
1633 _GLIBCXX_NODISCARD _GLIBCXX20_CONSTEXPR
1635 equal(_IIter1 __first1, _IIter1 __last1,
1636 _IIter2 __first2, _BinaryPredicate __binary_pred)
1639 __glibcxx_function_requires(_InputIteratorConcept<_IIter1>)
1640 __glibcxx_function_requires(_InputIteratorConcept<_IIter2>)
1641 __glibcxx_requires_valid_range(__first1, __last1);
1643 for (; __first1 != __last1; ++__first1, (void)++__first2)
1644 if (!
bool(__binary_pred(*__first1, *__first2)))
1649#if __cplusplus >= 201103L
1651 template<
typename _II1,
typename _II2>
1652 _GLIBCXX20_CONSTEXPR
1654 __equal4(_II1 __first1, _II1 __last1, _II2 __first2, _II2 __last2)
1656 using _RATag = random_access_iterator_tag;
1657 using _Cat1 =
typename iterator_traits<_II1>::iterator_category;
1658 using _Cat2 =
typename iterator_traits<_II2>::iterator_category;
1659 using _RAIters = __and_<is_same<_Cat1, _RATag>, is_same<_Cat2, _RATag>>;
1666 return _GLIBCXX_STD_A::equal(__first1, __last1, __first2);
1669 for (; __first1 != __last1 && __first2 != __last2;
1670 ++__first1, (void)++__first2)
1671 if (!(*__first1 == *__first2))
1673 return __first1 == __last1 && __first2 == __last2;
1677 template<
typename _II1,
typename _II2,
typename _BinaryPredicate>
1678 _GLIBCXX20_CONSTEXPR
1680 __equal4(_II1 __first1, _II1 __last1, _II2 __first2, _II2 __last2,
1681 _BinaryPredicate __binary_pred)
1683 using _RATag = random_access_iterator_tag;
1684 using _Cat1 =
typename iterator_traits<_II1>::iterator_category;
1685 using _Cat2 =
typename iterator_traits<_II2>::iterator_category;
1686 using _RAIters = __and_<is_same<_Cat1, _RATag>, is_same<_Cat2, _RATag>>;
1693 return _GLIBCXX_STD_A::equal(__first1, __last1, __first2,
1697 for (; __first1 != __last1 && __first2 != __last2;
1698 ++__first1, (void)++__first2)
1699 if (!
bool(__binary_pred(*__first1, *__first2)))
1701 return __first1 == __last1 && __first2 == __last2;
1705#ifdef __glibcxx_robust_nonmodifying_seq_ops
1719 template<
typename _II1,
typename _II2>
1720 _GLIBCXX_NODISCARD _GLIBCXX20_CONSTEXPR
1722 equal(_II1 __first1, _II1 __last1, _II2 __first2, _II2 __last2)
1725 __glibcxx_function_requires(_InputIteratorConcept<_II1>)
1726 __glibcxx_function_requires(_InputIteratorConcept<_II2>)
1727 __glibcxx_function_requires(_EqualOpConcept<
1730 __glibcxx_requires_valid_range(__first1, __last1);
1731 __glibcxx_requires_valid_range(__first2, __last2);
1733 return _GLIBCXX_STD_A::__equal4(__first1, __last1, __first2, __last2);
1752 template<
typename _IIter1,
typename _IIter2,
typename _BinaryPredicate>
1753 _GLIBCXX_NODISCARD _GLIBCXX20_CONSTEXPR
1755 equal(_IIter1 __first1, _IIter1 __last1,
1756 _IIter2 __first2, _IIter2 __last2, _BinaryPredicate __binary_pred)
1759 __glibcxx_function_requires(_InputIteratorConcept<_IIter1>)
1760 __glibcxx_function_requires(_InputIteratorConcept<_IIter2>)
1761 __glibcxx_requires_valid_range(__first1, __last1);
1762 __glibcxx_requires_valid_range(__first2, __last2);
1764 return _GLIBCXX_STD_A::__equal4(__first1, __last1, __first2, __last2,
1784 template<
typename _II1,
typename _II2>
1785 _GLIBCXX_NODISCARD _GLIBCXX20_CONSTEXPR
1787 lexicographical_compare(_II1 __first1, _II1 __last1,
1788 _II2 __first2, _II2 __last2)
1790#ifdef _GLIBCXX_CONCEPT_CHECKS
1795 __glibcxx_function_requires(_InputIteratorConcept<_II1>)
1796 __glibcxx_function_requires(_InputIteratorConcept<_II2>)
1797 __glibcxx_function_requires(_LessThanOpConcept<_ValueType1, _ValueType2>)
1798 __glibcxx_function_requires(_LessThanOpConcept<_ValueType2, _ValueType1>)
1799 __glibcxx_requires_valid_range(__first1, __last1);
1800 __glibcxx_requires_valid_range(__first2, __last2);
1802 return std::__lexicographical_compare_aux(__first1, __last1,
1819 template<
typename _II1,
typename _II2,
typename _Compare>
1820 _GLIBCXX_NODISCARD _GLIBCXX20_CONSTEXPR
1822 lexicographical_compare(_II1 __first1, _II1 __last1,
1823 _II2 __first2, _II2 __last2, _Compare __comp)
1826 __glibcxx_function_requires(_InputIteratorConcept<_II1>)
1827 __glibcxx_function_requires(_InputIteratorConcept<_II2>)
1828 __glibcxx_requires_valid_range(__first1, __last1);
1829 __glibcxx_requires_valid_range(__first2, __last2);
1831 return std::__lexicographical_compare_impl
1832 (__first1, __last1, __first2, __last2,
1833 __gnu_cxx::__ops::__iter_comp_iter(__comp));
1836#if __cpp_lib_three_way_comparison
1840 template<
typename _Iter1,
typename _Iter2>
1841 concept __memcmp_ordered_with
1842 = (__is_memcmp_ordered_with<iter_value_t<_Iter1>,
1843 iter_value_t<_Iter2>>::__value)
1844 && contiguous_iterator<_Iter1> && contiguous_iterator<_Iter2>;
1848 template<
typename _Tp>
1850 __min_cmp(_Tp __x, _Tp __y)
1854 decltype(__x <=> __y) _M_cmp;
1856 auto __c = __x <=> __y;
1858 return _Res{__y, __c};
1859 return _Res{__x, __c};
1873 template<
typename _InputIter1,
typename _InputIter2,
typename _Comp>
1874 [[nodiscard]]
constexpr auto
1876 _InputIter1 __last1,
1877 _InputIter2 __first2,
1878 _InputIter2 __last2,
1880 ->
decltype(__comp(*__first1, *__first2))
1883 __glibcxx_function_requires(_InputIteratorConcept<_InputIter1>)
1884 __glibcxx_function_requires(_InputIteratorConcept<_InputIter2>)
1885 __glibcxx_requires_valid_range(__first1, __last1);
1886 __glibcxx_requires_valid_range(__first2, __last2);
1888 using _Cat =
decltype(__comp(*__first1, *__first2));
1889 static_assert(same_as<common_comparison_category_t<_Cat>, _Cat>);
1891 if (!std::__is_constant_evaluated())
1892 if constexpr (same_as<_Comp, __detail::_Synth3way>
1893 || same_as<_Comp, compare_three_way>)
1894 if constexpr (__memcmp_ordered_with<_InputIter1, _InputIter2>)
1896 const auto [__len, __lencmp] = _GLIBCXX_STD_A::
1897 __min_cmp(__last1 - __first1, __last2 - __first2);
1900 const auto __blen = __len *
sizeof(*__first1);
1902 = __builtin_memcmp(&*__first1, &*__first2, __blen) <=> 0;
1909 while (__first1 != __last1)
1911 if (__first2 == __last2)
1912 return strong_ordering::greater;
1913 if (
auto __cmp = __comp(*__first1, *__first2); __cmp != 0)
1918 return (__first2 == __last2) <=>
true;
1921 template<
typename _InputIter1,
typename _InputIter2>
1924 _InputIter1 __last1,
1925 _InputIter2 __first2,
1926 _InputIter2 __last2)
1928 return _GLIBCXX_STD_A::
1929 lexicographical_compare_three_way(__first1, __last1, __first2, __last2,
1930 compare_three_way{});
1934 template<
typename _InputIterator1,
typename _InputIterator2,
1935 typename _BinaryPredicate>
1936 _GLIBCXX20_CONSTEXPR
1937 pair<_InputIterator1, _InputIterator2>
1938 __mismatch(_InputIterator1 __first1, _InputIterator1 __last1,
1939 _InputIterator2 __first2, _BinaryPredicate __binary_pred)
1941 while (__first1 != __last1 && __binary_pred(__first1, __first2))
1946 return pair<_InputIterator1, _InputIterator2>(__first1, __first2);
1962 template<
typename _InputIterator1,
typename _InputIterator2>
1963 _GLIBCXX_NODISCARD _GLIBCXX20_CONSTEXPR
1964 inline pair<_InputIterator1, _InputIterator2>
1965 mismatch(_InputIterator1 __first1, _InputIterator1 __last1,
1966 _InputIterator2 __first2)
1969 __glibcxx_function_requires(_InputIteratorConcept<_InputIterator1>)
1970 __glibcxx_function_requires(_InputIteratorConcept<_InputIterator2>)
1971 __glibcxx_function_requires(_EqualOpConcept<
1974 __glibcxx_requires_valid_range(__first1, __last1);
1976 return _GLIBCXX_STD_A::__mismatch(__first1, __last1, __first2,
1977 __gnu_cxx::__ops::__iter_equal_to_iter());
1996 template<
typename _InputIterator1,
typename _InputIterator2,
1997 typename _BinaryPredicate>
1998 _GLIBCXX_NODISCARD _GLIBCXX20_CONSTEXPR
1999 inline pair<_InputIterator1, _InputIterator2>
2000 mismatch(_InputIterator1 __first1, _InputIterator1 __last1,
2001 _InputIterator2 __first2, _BinaryPredicate __binary_pred)
2004 __glibcxx_function_requires(_InputIteratorConcept<_InputIterator1>)
2005 __glibcxx_function_requires(_InputIteratorConcept<_InputIterator2>)
2006 __glibcxx_requires_valid_range(__first1, __last1);
2008 return _GLIBCXX_STD_A::__mismatch(__first1, __last1, __first2,
2009 __gnu_cxx::__ops::__iter_comp_iter(__binary_pred));
2012#if __glibcxx_robust_nonmodifying_seq_ops
2013 template<
typename _InputIterator1,
typename _InputIterator2,
2014 typename _BinaryPredicate>
2015 _GLIBCXX20_CONSTEXPR
2016 pair<_InputIterator1, _InputIterator2>
2017 __mismatch(_InputIterator1 __first1, _InputIterator1 __last1,
2018 _InputIterator2 __first2, _InputIterator2 __last2,
2019 _BinaryPredicate __binary_pred)
2021 while (__first1 != __last1 && __first2 != __last2
2022 && __binary_pred(__first1, __first2))
2027 return pair<_InputIterator1, _InputIterator2>(__first1, __first2);
2044 template<
typename _InputIterator1,
typename _InputIterator2>
2045 _GLIBCXX_NODISCARD _GLIBCXX20_CONSTEXPR
2046 inline pair<_InputIterator1, _InputIterator2>
2047 mismatch(_InputIterator1 __first1, _InputIterator1 __last1,
2048 _InputIterator2 __first2, _InputIterator2 __last2)
2051 __glibcxx_function_requires(_InputIteratorConcept<_InputIterator1>)
2052 __glibcxx_function_requires(_InputIteratorConcept<_InputIterator2>)
2053 __glibcxx_function_requires(_EqualOpConcept<
2056 __glibcxx_requires_valid_range(__first1, __last1);
2057 __glibcxx_requires_valid_range(__first2, __last2);
2059 return _GLIBCXX_STD_A::__mismatch(__first1, __last1, __first2, __last2,
2060 __gnu_cxx::__ops::__iter_equal_to_iter());
2080 template<
typename _InputIterator1,
typename _InputIterator2,
2081 typename _BinaryPredicate>
2082 _GLIBCXX_NODISCARD _GLIBCXX20_CONSTEXPR
2083 inline pair<_InputIterator1, _InputIterator2>
2084 mismatch(_InputIterator1 __first1, _InputIterator1 __last1,
2085 _InputIterator2 __first2, _InputIterator2 __last2,
2086 _BinaryPredicate __binary_pred)
2089 __glibcxx_function_requires(_InputIteratorConcept<_InputIterator1>)
2090 __glibcxx_function_requires(_InputIteratorConcept<_InputIterator2>)
2091 __glibcxx_requires_valid_range(__first1, __last1);
2092 __glibcxx_requires_valid_range(__first2, __last2);
2094 return _GLIBCXX_STD_A::__mismatch(__first1, __last1, __first2, __last2,
2095 __gnu_cxx::__ops::__iter_comp_iter(__binary_pred));
2099_GLIBCXX_END_NAMESPACE_ALGO
2102 template<
typename _Iterator,
typename _Predicate>
2103 _GLIBCXX20_CONSTEXPR
2105 __find_if(_Iterator __first, _Iterator __last, _Predicate __pred)
2107 while (__first != __last && !__pred(__first))
2112 template<
typename _InputIterator,
typename _Predicate>
2113 _GLIBCXX20_CONSTEXPR
2114 typename iterator_traits<_InputIterator>::difference_type
2115 __count_if(_InputIterator __first, _InputIterator __last, _Predicate __pred)
2117 typename iterator_traits<_InputIterator>::difference_type __n = 0;
2118 for (; __first != __last; ++__first)
2119 if (__pred(__first))
2124 template<
typename _ForwardIterator,
typename _Predicate>
2125 _GLIBCXX20_CONSTEXPR
2127 __remove_if(_ForwardIterator __first, _ForwardIterator __last,
2130 __first = std::__find_if(__first, __last, __pred);
2131 if (__first == __last)
2133 _ForwardIterator __result = __first;
2135 for (; __first != __last; ++__first)
2136 if (!__pred(__first))
2138 *__result = _GLIBCXX_MOVE(*__first);
2144 template<
typename _ForwardIterator1,
typename _ForwardIterator2,
2145 typename _BinaryPredicate>
2146 _GLIBCXX20_CONSTEXPR
2148 __search(_ForwardIterator1 __first1, _ForwardIterator1 __last1,
2149 _ForwardIterator2 __first2, _ForwardIterator2 __last2,
2150 _BinaryPredicate __predicate)
2153 if (__first1 == __last1 || __first2 == __last2)
2157 _ForwardIterator2 __p1(__first2);
2158 if (++__p1 == __last2)
2159 return std::__find_if(__first1, __last1,
2160 __gnu_cxx::__ops::__iter_comp_iter(__predicate, __first2));
2163 _ForwardIterator1 __current = __first1;
2168 std::__find_if(__first1, __last1,
2169 __gnu_cxx::__ops::__iter_comp_iter(__predicate, __first2));
2171 if (__first1 == __last1)
2174 _ForwardIterator2 __p = __p1;
2175 __current = __first1;
2176 if (++__current == __last1)
2179 while (__predicate(__current, __p))
2181 if (++__p == __last2)
2183 if (++__current == __last1)
2191#if __cplusplus >= 201103L
2192 template<
typename _ForwardIterator1,
typename _ForwardIterator2,
2193 typename _BinaryPredicate>
2194 _GLIBCXX20_CONSTEXPR
2196 __is_permutation(_ForwardIterator1 __first1, _ForwardIterator1 __last1,
2197 _ForwardIterator2 __first2, _BinaryPredicate __pred)
2201 for (; __first1 != __last1; ++__first1, (void)++__first2)
2202 if (!__pred(__first1, __first2))
2205 if (__first1 == __last1)
2210 _ForwardIterator2 __last2 = __first2;
2212 for (_ForwardIterator1 __scan = __first1; __scan != __last1; ++__scan)
2214 if (__scan != std::__find_if(__first1, __scan,
2215 __gnu_cxx::__ops::__iter_comp_iter(__pred, __scan)))
2219 = std::__count_if(__first2, __last2,
2220 __gnu_cxx::__ops::__iter_comp_iter(__pred, __scan));
2221 if (0 == __matches ||
2222 std::__count_if(__scan, __last1,
2223 __gnu_cxx::__ops::__iter_comp_iter(__pred, __scan))
2242 template<
typename _ForwardIterator1,
typename _ForwardIterator2>
2243 _GLIBCXX20_CONSTEXPR
2245 is_permutation(_ForwardIterator1 __first1, _ForwardIterator1 __last1,
2246 _ForwardIterator2 __first2)
2249 __glibcxx_function_requires(_ForwardIteratorConcept<_ForwardIterator1>)
2250 __glibcxx_function_requires(_ForwardIteratorConcept<_ForwardIterator2>)
2251 __glibcxx_function_requires(_EqualOpConcept<
2254 __glibcxx_requires_valid_range(__first1, __last1);
2256 return std::__is_permutation(__first1, __last1, __first2,
2257 __gnu_cxx::__ops::__iter_equal_to_iter());
2261_GLIBCXX_BEGIN_NAMESPACE_ALGO
2284 template<
typename _ForwardIterator1,
typename _ForwardIterator2,
2285 typename _BinaryPredicate>
2286 _GLIBCXX20_CONSTEXPR
2287 inline _ForwardIterator1
2288 search(_ForwardIterator1 __first1, _ForwardIterator1 __last1,
2289 _ForwardIterator2 __first2, _ForwardIterator2 __last2,
2290 _BinaryPredicate __predicate)
2293 __glibcxx_function_requires(_ForwardIteratorConcept<_ForwardIterator1>)
2294 __glibcxx_function_requires(_ForwardIteratorConcept<_ForwardIterator2>)
2295 __glibcxx_function_requires(_BinaryPredicateConcept<_BinaryPredicate,
2298 __glibcxx_requires_valid_range(__first1, __last1);
2299 __glibcxx_requires_valid_range(__first2, __last2);
2301 return std::__search(__first1, __last1, __first2, __last2,
2302 __gnu_cxx::__ops::__iter_comp_iter(__predicate));
2305_GLIBCXX_END_NAMESPACE_ALGO
2306_GLIBCXX_END_NAMESPACE_VERSION
2312#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 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 auto lexicographical_compare_three_way(_InputIter1 __first1, _InputIter1 __last1, _InputIter2 __first2, _InputIter2 __last2, _Comp __comp) -> decltype(__comp(*__first1, *__first2))
Performs dictionary comparison on ranges.
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 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.