56#ifndef _STL_ALGOBASE_H
57#define _STL_ALGOBASE_H 1
71#if __cplusplus >= 201103L
74#if __cplusplus >= 201402L
77#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)
151 template<
typename _ForwardIterator1,
typename _ForwardIterator2>
154 iter_swap(_ForwardIterator1 __a, _ForwardIterator2 __b)
157 __glibcxx_function_requires(_Mutable_ForwardIteratorConcept<
159 __glibcxx_function_requires(_Mutable_ForwardIteratorConcept<
162#if __cplusplus < 201103L
168 __glibcxx_function_requires(_ConvertibleConcept<_ValueType1,
170 __glibcxx_function_requires(_ConvertibleConcept<_ValueType2,
177 std::__iter_swap<__are_same<_ValueType1, _ValueType2>::__value
178 && __are_same<_ValueType1&, _ReferenceType1>::__value
179 && __are_same<_ValueType2&, _ReferenceType2>::__value>::
200 template<
typename _ForwardIterator1,
typename _ForwardIterator2>
203 swap_ranges(_ForwardIterator1 __first1, _ForwardIterator1 __last1,
204 _ForwardIterator2 __first2)
207 __glibcxx_function_requires(_Mutable_ForwardIteratorConcept<
209 __glibcxx_function_requires(_Mutable_ForwardIteratorConcept<
211 __glibcxx_requires_valid_range(__first1, __last1);
213 for (; __first1 != __last1; ++__first1, (void)++__first2)
214 std::iter_swap(__first1, __first2);
229 template<
typename _Tp>
230 _GLIBCXX_NODISCARD _GLIBCXX14_CONSTEXPR
232 min(
const _Tp& __a,
const _Tp& __b)
235 __glibcxx_function_requires(_LessThanComparableConcept<_Tp>)
253 template<
typename _Tp>
254 _GLIBCXX_NODISCARD _GLIBCXX14_CONSTEXPR
256 max(
const _Tp& __a,
const _Tp& __b)
259 __glibcxx_function_requires(_LessThanComparableConcept<_Tp>)
277 template<
typename _Tp,
typename _Compare>
278 _GLIBCXX_NODISCARD _GLIBCXX14_CONSTEXPR
280 min(
const _Tp& __a,
const _Tp& __b, _Compare __comp)
283 if (__comp(__b, __a))
299 template<
typename _Tp,
typename _Compare>
300 _GLIBCXX_NODISCARD _GLIBCXX14_CONSTEXPR
302 max(
const _Tp& __a,
const _Tp& __b, _Compare __comp)
305 if (__comp(__a, __b))
310_GLIBCXX_BEGIN_NAMESPACE_CONTAINER
312 template<
typename _Tp,
typename _Ref,
typename _Ptr>
313 struct _Deque_iterator;
315 struct _Bit_iterator;
317_GLIBCXX_END_NAMESPACE_CONTAINER
322 template<
typename _CharT>
325 template<
typename _CharT,
typename _Traits>
326 class istreambuf_iterator;
328 template<
typename _CharT,
typename _Traits>
329 class ostreambuf_iterator;
331 template<
bool _IsMove,
typename _CharT>
332 typename __gnu_cxx::__enable_if<__is_char<_CharT>::__value,
333 ostreambuf_iterator<_CharT, char_traits<_CharT> > >::__type
334 __copy_move_a2(_CharT*, _CharT*,
335 ostreambuf_iterator<_CharT, char_traits<_CharT> >);
337 template<
bool _IsMove,
typename _CharT>
338 typename __gnu_cxx::__enable_if<__is_char<_CharT>::__value,
339 ostreambuf_iterator<_CharT, char_traits<_CharT> > >::__type
340 __copy_move_a2(
const _CharT*,
const _CharT*,
341 ostreambuf_iterator<_CharT, char_traits<_CharT> >);
343 template<
bool _IsMove,
typename _CharT>
344 typename __gnu_cxx::__enable_if<__is_char<_CharT>::__value,
346 __copy_move_a2(istreambuf_iterator<_CharT, char_traits<_CharT> >,
347 istreambuf_iterator<_CharT, char_traits<_CharT> >, _CharT*);
349 template<
bool _IsMove,
typename _CharT>
351 typename __gnu_cxx::__enable_if<
352 __is_char<_CharT>::__value,
353 _GLIBCXX_STD_C::_Deque_iterator<_CharT, _CharT&, _CharT*> >::__type
355 istreambuf_iterator<_CharT, char_traits<_CharT> >,
356 istreambuf_iterator<_CharT, char_traits<_CharT> >,
357 _GLIBCXX_STD_C::_Deque_iterator<_CharT, _CharT&, _CharT*>);
360#if __cpp_lib_concepts
361 template<
typename _OutIter,
typename _InIter,
typename _Sent = _InIter>
362 concept __memcpyable_iterators
363 = contiguous_iterator<_OutIter> && contiguous_iterator<_InIter>
364 && sized_sentinel_for<_Sent, _InIter>
365 &&
requires (_OutIter __o, _InIter __i) {
371#if __cplusplus < 201103L
376 template<
typename _Iter> __attribute__((__always_inline__))
377 inline void* __ptr_or_null(_Iter) {
return 0; }
378 template<
typename _Tp> __attribute__((__always_inline__))
379 inline void* __ptr_or_null(_Tp* __p) {
return (
void*)__p; }
380# define _GLIBCXX_TO_ADDR(P) std::__ptr_or_null(P)
382 template<
typename _Iter> __attribute__((__always_inline__))
383 inline void __ptr_advance(_Iter&, ptrdiff_t) { }
384 template<
typename _Tp> __attribute__((__always_inline__))
385 inline void __ptr_advance(_Tp*& __p, ptrdiff_t __n) { __p += __n; }
386# define _GLIBCXX_ADVANCE(P, N) std::__ptr_advance(P, N)
390# define _GLIBCXX_TO_ADDR(P) P
391# define _GLIBCXX_ADVANCE(P, N) P += N
394#pragma GCC diagnostic push
395#pragma GCC diagnostic ignored "-Wc++17-extensions"
396 template<
bool _IsMove,
typename _OutIter,
typename _InIter>
397 __attribute__((__always_inline__)) _GLIBCXX20_CONSTEXPR
399 __assign_one(_OutIter& __out, _InIter& __in)
401#if __cplusplus >= 201103L
402 if constexpr (_IsMove)
409 template<
bool _IsMove,
typename _InIter,
typename _Sent,
typename _OutIter>
412 __copy_move_a2(_InIter __first, _Sent __last, _OutIter __result)
414 typedef __decltype(*__first) _InRef;
415 typedef __decltype(*__result) _OutRef;
416 if _GLIBCXX_CONSTEXPR (!__is_trivially_assignable(_OutRef, _InRef))
418 else if (std::__is_constant_evaluated())
420 else if _GLIBCXX_CONSTEXPR (__memcpyable<_OutIter, _InIter>::__value)
423 if (__builtin_expect(__n > 1,
true))
425 __builtin_memmove(_GLIBCXX_TO_ADDR(__result),
426 _GLIBCXX_TO_ADDR(__first),
427 __n *
sizeof(*__first));
428 _GLIBCXX_ADVANCE(__result, __n);
432 std::__assign_one<_IsMove>(__result, __first);
437#if __cpp_lib_concepts
438 else if constexpr (__memcpyable_iterators<_OutIter, _InIter, _Sent>)
440 if (
auto __n = __last - __first; __n > 1) [[likely]]
444 size_t __nbytes = __n *
sizeof(iter_value_t<_InIter>);
449 __builtin_memmove(__dest, __src, __nbytes);
453 std::__assign_one<_IsMove>(__result, __first);
460 for (; __first != __last; ++__result, (void)++__first)
461 std::__assign_one<_IsMove>(__result, __first);
464#pragma GCC diagnostic pop
466 template<
bool _IsMove,
467 typename _Tp,
typename _Ref,
typename _Ptr,
typename _OI>
468 _GLIBCXX26_CONSTEXPR _OI
469 __copy_move_a1(_GLIBCXX_STD_C::_Deque_iterator<_Tp, _Ref, _Ptr>,
470 _GLIBCXX_STD_C::_Deque_iterator<_Tp, _Ref, _Ptr>,
473 template<
bool _IsMove,
474 typename _ITp,
typename _IRef,
typename _IPtr,
typename _OTp>
476 _GLIBCXX_STD_C::_Deque_iterator<_OTp, _OTp&, _OTp*>
477 __copy_move_a1(_GLIBCXX_STD_C::_Deque_iterator<_ITp, _IRef, _IPtr>,
478 _GLIBCXX_STD_C::_Deque_iterator<_ITp, _IRef, _IPtr>,
479 _GLIBCXX_STD_C::_Deque_iterator<_OTp, _OTp&, _OTp*>);
481 template<
bool _IsMove,
typename _II,
typename _Tp>
483 typename __gnu_cxx::__enable_if<
484 __is_any_random_access_iter<_II>::__value,
485 _GLIBCXX_STD_C::_Deque_iterator<_Tp, _Tp&, _Tp*> >::__type
486 __copy_move_a1(_II, _II, _GLIBCXX_STD_C::_Deque_iterator<_Tp, _Tp&, _Tp*>);
488 template<
bool _IsMove,
typename _II,
typename _OI>
489 __attribute__((__always_inline__))
492 __copy_move_a1(_II __first, _II __last, _OI __result)
493 {
return std::__copy_move_a2<_IsMove>(__first, __last, __result); }
495 template<
bool _IsMove,
typename _II,
typename _OI>
496 __attribute__((__always_inline__))
499 __copy_move_a(_II __first, _II __last, _OI __result)
501 return std::__niter_wrap(__result,
502 std::__copy_move_a1<_IsMove>(std::__niter_base(__first),
503 std::__niter_base(__last),
504 std::__niter_base(__result)));
507 template<
bool _IsMove,
508 typename _Ite,
typename _Seq,
typename _Cat,
typename _OI>
511 __copy_move_a(const ::__gnu_debug::_Safe_iterator<_Ite, _Seq, _Cat>&,
512 const ::__gnu_debug::_Safe_iterator<_Ite, _Seq, _Cat>&,
515 template<
bool _IsMove,
516 typename _II,
typename _Ite,
typename _Seq,
typename _Cat>
518 __gnu_debug::_Safe_iterator<_Ite, _Seq, _Cat>
519 __copy_move_a(_II, _II,
520 const ::__gnu_debug::_Safe_iterator<_Ite, _Seq, _Cat>&);
522 template<
bool _IsMove,
523 typename _IIte,
typename _ISeq,
typename _ICat,
524 typename _OIte,
typename _OSeq,
typename _OCat>
526 ::__gnu_debug::_Safe_iterator<_OIte, _OSeq, _OCat>
527 __copy_move_a(const ::__gnu_debug::_Safe_iterator<_IIte, _ISeq, _ICat>&,
528 const ::__gnu_debug::_Safe_iterator<_IIte, _ISeq, _ICat>&,
529 const ::__gnu_debug::_Safe_iterator<_OIte, _OSeq, _OCat>&);
531#pragma GCC diagnostic push
532#pragma GCC diagnostic ignored "-Wc++17-extensions"
533 template<
typename _InputIterator,
typename _Size,
typename _OutputIterator>
536 __copy_n_a(_InputIterator __first, _Size __n, _OutputIterator __result,
539 typedef __decltype(*__first) _InRef;
540 typedef __decltype(*__result) _OutRef;
541 if _GLIBCXX_CONSTEXPR (!__is_trivially_assignable(_OutRef, _InRef))
543#ifdef __cpp_lib_is_constant_evaluated
544 else if (std::is_constant_evaluated())
547 else if _GLIBCXX_CONSTEXPR (__memcpyable<_OutputIterator,
548 _InputIterator>::__value)
550 if (__builtin_expect(__n > 1,
true))
552 __builtin_memmove(_GLIBCXX_TO_ADDR(__result),
553 _GLIBCXX_TO_ADDR(__first),
554 __n *
sizeof(*__first));
555 _GLIBCXX_ADVANCE(__result, __n);
558 *__result++ = *__first;
561#if __cpp_lib_concepts
562 else if constexpr (__memcpyable_iterators<_OutputIterator,
565 if (__n > 1) [[likely]]
569 size_t __nbytes = __n *
sizeof(iter_value_t<_InputIterator>);
574 __builtin_memmove(__dest, __src, __nbytes);
577 *__result++ = *__first;
586 *__result = *__first;
596#pragma GCC diagnostic pop
599 template<
typename _CharT,
typename _Size>
600 typename __gnu_cxx::__enable_if<
601 __is_char<_CharT>::__value, _CharT*>::__type
603 _Size, _CharT*,
bool);
605 template<
typename _CharT,
typename _Size>
607 typename __gnu_cxx::__enable_if<
608 __is_char<_CharT>::__value,
609 _GLIBCXX_STD_C::_Deque_iterator<_CharT, _CharT&, _CharT*> >::__type
611 _GLIBCXX_STD_C::_Deque_iterator<_CharT, _CharT&, _CharT*>,
632 template<
typename _II,
typename _OI>
635 copy(_II __first, _II __last, _OI __result)
638 __glibcxx_function_requires(_InputIteratorConcept<_II>)
639 __glibcxx_function_requires(_OutputIteratorConcept<_OI,
641 __glibcxx_requires_can_increment_range(__first, __last, __result);
643 return std::__copy_move_a<__is_move_iterator<_II>::__value>
644 (std::__miter_base(__first), std::__miter_base(__last), __result);
647#if __cplusplus >= 201103L
665 template<
typename _II,
typename _OI>
668 move(_II __first, _II __last, _OI __result)
671 __glibcxx_function_requires(_InputIteratorConcept<_II>)
672 __glibcxx_function_requires(_OutputIteratorConcept<_OI,
674 __glibcxx_requires_can_increment_range(__first, __last, __result);
676 return std::__copy_move_a<true>(std::__miter_base(__first),
677 std::__miter_base(__last), __result);
680#define _GLIBCXX_MOVE3(_Tp, _Up, _Vp) std::move(_Tp, _Up, _Vp)
682#define _GLIBCXX_MOVE3(_Tp, _Up, _Vp) std::copy(_Tp, _Up, _Vp)
685#pragma GCC diagnostic push
686#pragma GCC diagnostic ignored "-Wc++17-extensions"
687 template<
bool _IsMove,
typename _BI1,
typename _BI2>
690 __copy_move_backward_a2(_BI1 __first, _BI1 __last, _BI2 __result)
692 typedef __decltype(*__first) _InRef;
693 typedef __decltype(*__result) _OutRef;
694 if _GLIBCXX_CONSTEXPR (!__is_trivially_assignable(_OutRef, _InRef))
696#ifdef __cpp_lib_is_constant_evaluated
697 else if (std::is_constant_evaluated())
700 else if _GLIBCXX_CONSTEXPR (__memcpyable<_BI2, _BI1>::__value)
704 if (__builtin_expect(__n > 1,
true))
706 __builtin_memmove(_GLIBCXX_TO_ADDR(__result),
707 _GLIBCXX_TO_ADDR(__first),
708 __n *
sizeof(*__first));
711 std::__assign_one<_IsMove>(__result, __first);
714#if __cpp_lib_concepts
715 else if constexpr (__memcpyable_iterators<_BI2, _BI1>)
717 if (
auto __n = __last - __first; __n > 1) [[likely]]
725 size_t __nbytes = __n *
sizeof(iter_value_t<_BI1>);
726 __builtin_memmove(__dest, __src, __nbytes);
731 std::__assign_one<_IsMove>(__result, __first);
737 while (__first != __last)
741 std::__assign_one<_IsMove>(__result, __last);
745#pragma GCC diagnostic pop
747#undef _GLIBCXX_TO_ADDR
748#undef _GLIBCXX_ADVANCE
750 template<
bool _IsMove,
typename _BI1,
typename _BI2>
751 __attribute__((__always_inline__))
754 __copy_move_backward_a1(_BI1 __first, _BI1 __last, _BI2 __result)
755 {
return std::__copy_move_backward_a2<_IsMove>(__first, __last, __result); }
757 template<
bool _IsMove,
758 typename _Tp,
typename _Ref,
typename _Ptr,
typename _OI>
759 _GLIBCXX26_CONSTEXPR _OI
760 __copy_move_backward_a1(_GLIBCXX_STD_C::_Deque_iterator<_Tp, _Ref, _Ptr>,
761 _GLIBCXX_STD_C::_Deque_iterator<_Tp, _Ref, _Ptr>,
764 template<
bool _IsMove,
765 typename _ITp,
typename _IRef,
typename _IPtr,
typename _OTp>
767 _GLIBCXX_STD_C::_Deque_iterator<_OTp, _OTp&, _OTp*>
768 __copy_move_backward_a1(
769 _GLIBCXX_STD_C::_Deque_iterator<_ITp, _IRef, _IPtr>,
770 _GLIBCXX_STD_C::_Deque_iterator<_ITp, _IRef, _IPtr>,
771 _GLIBCXX_STD_C::_Deque_iterator<_OTp, _OTp&, _OTp*>);
773 template<
bool _IsMove,
typename _II,
typename _Tp>
775 typename __gnu_cxx::__enable_if<
776 __is_any_random_access_iter<_II>::__value,
777 _GLIBCXX_STD_C::_Deque_iterator<_Tp, _Tp&, _Tp*> >::__type
778 __copy_move_backward_a1(_II, _II,
779 _GLIBCXX_STD_C::_Deque_iterator<_Tp, _Tp&, _Tp*>);
781 template<
bool _IsMove,
typename _II,
typename _OI>
782 __attribute__((__always_inline__))
785 __copy_move_backward_a(_II __first, _II __last, _OI __result)
787 return std::__niter_wrap(__result,
788 std::__copy_move_backward_a1<_IsMove>
789 (std::__niter_base(__first), std::__niter_base(__last),
790 std::__niter_base(__result)));
793 template<
bool _IsMove,
794 typename _Ite,
typename _Seq,
typename _Cat,
typename _OI>
797 __copy_move_backward_a(
798 const ::__gnu_debug::_Safe_iterator<_Ite, _Seq, _Cat>&,
799 const ::__gnu_debug::_Safe_iterator<_Ite, _Seq, _Cat>&,
802 template<
bool _IsMove,
803 typename _II,
typename _Ite,
typename _Seq,
typename _Cat>
805 __gnu_debug::_Safe_iterator<_Ite, _Seq, _Cat>
806 __copy_move_backward_a(_II, _II,
807 const ::__gnu_debug::_Safe_iterator<_Ite, _Seq, _Cat>&);
809 template<
bool _IsMove,
810 typename _IIte,
typename _ISeq,
typename _ICat,
811 typename _OIte,
typename _OSeq,
typename _OCat>
813 ::__gnu_debug::_Safe_iterator<_OIte, _OSeq, _OCat>
814 __copy_move_backward_a(
815 const ::__gnu_debug::_Safe_iterator<_IIte, _ISeq, _ICat>&,
816 const ::__gnu_debug::_Safe_iterator<_IIte, _ISeq, _ICat>&,
817 const ::__gnu_debug::_Safe_iterator<_OIte, _OSeq, _OCat>&);
837 template<
typename _BI1,
typename _BI2>
838 __attribute__((__always_inline__))
841 copy_backward(_BI1 __first, _BI1 __last, _BI2 __result)
844 __glibcxx_function_requires(_BidirectionalIteratorConcept<_BI1>)
845 __glibcxx_function_requires(_Mutable_BidirectionalIteratorConcept<_BI2>)
846 __glibcxx_function_requires(_OutputIteratorConcept<_BI2,
848 __glibcxx_requires_can_decrement_range(__first, __last, __result);
850 return std::__copy_move_backward_a<__is_move_iterator<_BI1>::__value>
851 (std::__miter_base(__first), std::__miter_base(__last), __result);
854#if __cplusplus >= 201103L
873 template<
typename _BI1,
typename _BI2>
874 __attribute__((__always_inline__))
880 __glibcxx_function_requires(_BidirectionalIteratorConcept<_BI1>)
881 __glibcxx_function_requires(_Mutable_BidirectionalIteratorConcept<_BI2>)
882 __glibcxx_function_requires(_OutputIteratorConcept<_BI2,
884 __glibcxx_requires_can_decrement_range(__first, __last, __result);
886 return std::__copy_move_backward_a<true>(std::__miter_base(__first),
887 std::__miter_base(__last),
891#define _GLIBCXX_MOVE_BACKWARD3(_Tp, _Up, _Vp) std::move_backward(_Tp, _Up, _Vp)
893#define _GLIBCXX_MOVE_BACKWARD3(_Tp, _Up, _Vp) std::copy_backward(_Tp, _Up, _Vp)
896#pragma GCC diagnostic push
897#pragma GCC diagnostic ignored "-Wc++17-extensions"
898 template<
typename _ForwardIterator,
typename _Tp>
901 __fill_a1(_ForwardIterator __first, _ForwardIterator __last,
904#pragma GCC diagnostic push
905#pragma GCC diagnostic ignored "-Wlong-long"
910 const bool __load_outside_loop =
911#if __has_builtin(__is_trivially_constructible) \
912 && __has_builtin(__is_trivially_assignable)
913 __is_trivially_constructible(_Tp,
const _Tp&)
914 && __is_trivially_assignable(__decltype(*__first),
const _Tp&)
916 __is_trivially_copyable(_Tp)
917 && __is_same(_Tp, __typeof__(*__first))
919 &&
sizeof(_Tp) <=
sizeof(
long long);
920#pragma GCC diagnostic pop
924 typedef typename __gnu_cxx::__conditional_type<__load_outside_loop,
926 const _Tp&>::__type _Up;
928 for (; __first != __last; ++__first)
931#pragma GCC diagnostic pop
934 template<
typename _Up,
typename _Tp>
937 __gnu_cxx::__enable_if<__is_byte<_Up>::__value
938 && (__are_same<_Up, _Tp>::__value
939 || __memcpyable_integer<_Tp>::__width),
941 __fill_a1(_Up* __first, _Up* __last,
const _Tp& __x)
945 const _Up __val = __x;
946#if __cpp_lib_is_constant_evaluated
947 if (std::is_constant_evaluated())
949 for (; __first != __last; ++__first)
954 if (
const size_t __len = __last - __first)
955 __builtin_memset(__first,
static_cast<unsigned char>(__val), __len);
958 template<
typename _Ite,
typename _Cont,
typename _Tp>
959 __attribute__((__always_inline__))
962 __fill_a1(::__gnu_cxx::__normal_iterator<_Ite, _Cont> __first,
963 ::__gnu_cxx::__normal_iterator<_Ite, _Cont> __last,
965 { std::__fill_a1(__first.base(), __last.base(), __value); }
967 template<
typename _Tp,
typename _VTp>
968 _GLIBCXX26_CONSTEXPR
void
969 __fill_a1(
const _GLIBCXX_STD_C::_Deque_iterator<_Tp, _Tp&, _Tp*>&,
970 const _GLIBCXX_STD_C::_Deque_iterator<_Tp, _Tp&, _Tp*>&,
975 __fill_a1(_GLIBCXX_STD_C::_Bit_iterator, _GLIBCXX_STD_C::_Bit_iterator,
978 template<
typename _FIte,
typename _Tp>
979 __attribute__((__always_inline__))
982 __fill_a(_FIte __first, _FIte __last,
const _Tp& __value)
983 { std::__fill_a1(__first, __last, __value); }
985 template<
typename _Ite,
typename _Seq,
typename _Cat,
typename _Tp>
988 __fill_a(const ::__gnu_debug::_Safe_iterator<_Ite, _Seq, _Cat>&,
989 const ::__gnu_debug::_Safe_iterator<_Ite, _Seq, _Cat>&,
1003 template<
typename _ForwardIterator,
typename _Tp>
1004 __attribute__((__always_inline__))
1005 _GLIBCXX20_CONSTEXPR
1007 fill(_ForwardIterator __first, _ForwardIterator __last,
const _Tp& __value)
1010 __glibcxx_function_requires(_Mutable_ForwardIteratorConcept<
1012 __glibcxx_requires_valid_range(__first, __last);
1014 std::__fill_a(__first, __last, __value);
1017#pragma GCC diagnostic push
1018#pragma GCC diagnostic ignored "-Wlong-long"
1020 inline _GLIBCXX_CONSTEXPR
int
1021 __size_to_integer(
int __n) {
return __n; }
1022 inline _GLIBCXX_CONSTEXPR
unsigned
1023 __size_to_integer(
unsigned __n) {
return __n; }
1024 inline _GLIBCXX_CONSTEXPR
long
1025 __size_to_integer(
long __n) {
return __n; }
1026 inline _GLIBCXX_CONSTEXPR
unsigned long
1027 __size_to_integer(
unsigned long __n) {
return __n; }
1028 inline _GLIBCXX_CONSTEXPR
long long
1029 __size_to_integer(
long long __n) {
return __n; }
1030 inline _GLIBCXX_CONSTEXPR
unsigned long long
1031 __size_to_integer(
unsigned long long __n) {
return __n; }
1033#if defined(__GLIBCXX_TYPE_INT_N_0)
1034 __extension__
inline _GLIBCXX_CONSTEXPR __GLIBCXX_TYPE_INT_N_0
1035 __size_to_integer(__GLIBCXX_TYPE_INT_N_0 __n) {
return __n; }
1036 __extension__
inline _GLIBCXX_CONSTEXPR
unsigned __GLIBCXX_TYPE_INT_N_0
1037 __size_to_integer(
unsigned __GLIBCXX_TYPE_INT_N_0 __n) {
return __n; }
1039#if defined(__GLIBCXX_TYPE_INT_N_1)
1040 __extension__
inline _GLIBCXX_CONSTEXPR __GLIBCXX_TYPE_INT_N_1
1041 __size_to_integer(__GLIBCXX_TYPE_INT_N_1 __n) {
return __n; }
1042 __extension__
inline _GLIBCXX_CONSTEXPR
unsigned __GLIBCXX_TYPE_INT_N_1
1043 __size_to_integer(
unsigned __GLIBCXX_TYPE_INT_N_1 __n) {
return __n; }
1045#if defined(__GLIBCXX_TYPE_INT_N_2)
1046 __extension__
inline _GLIBCXX_CONSTEXPR __GLIBCXX_TYPE_INT_N_2
1047 __size_to_integer(__GLIBCXX_TYPE_INT_N_2 __n) {
return __n; }
1048 __extension__
inline _GLIBCXX_CONSTEXPR
unsigned __GLIBCXX_TYPE_INT_N_2
1049 __size_to_integer(
unsigned __GLIBCXX_TYPE_INT_N_2 __n) {
return __n; }
1051#if defined(__GLIBCXX_TYPE_INT_N_3)
1052 __extension__
inline _GLIBCXX_CONSTEXPR __GLIBCXX_TYPE_INT_N_3
1053 __size_to_integer(__GLIBCXX_TYPE_INT_N_3 __n) {
return __n; }
1054 __extension__
inline _GLIBCXX_CONSTEXPR
unsigned __GLIBCXX_TYPE_INT_N_3
1055 __size_to_integer(
unsigned __GLIBCXX_TYPE_INT_N_3 __n) {
return __n; }
1058#if defined(__STRICT_ANSI__) && defined(__SIZEOF_INT128__)
1059 __extension__
inline _GLIBCXX_CONSTEXPR __int128
1060 __size_to_integer(__int128 __n) {
return __n; }
1061 __extension__
inline _GLIBCXX_CONSTEXPR
unsigned __int128
1062 __size_to_integer(
unsigned __int128 __n) {
return __n; }
1065 inline _GLIBCXX_CONSTEXPR
long long
1066 __size_to_integer(
float __n) {
return (
long long)__n; }
1067 inline _GLIBCXX_CONSTEXPR
long long
1068 __size_to_integer(
double __n) {
return (
long long)__n; }
1069 inline _GLIBCXX_CONSTEXPR
long long
1070 __size_to_integer(
long double __n) {
return (
long long)__n; }
1071#ifdef _GLIBCXX_USE_FLOAT128
1072 __extension__
inline _GLIBCXX_CONSTEXPR
long long
1073 __size_to_integer(__float128 __n) {
return (
long long)__n; }
1075#pragma GCC diagnostic pop
1077#pragma GCC diagnostic push
1078#pragma GCC diagnostic ignored "-Wc++17-extensions"
1079#pragma GCC diagnostic ignored "-Wlong-long"
1080 template<
typename _OutputIterator,
typename _Size,
typename _Tp>
1081 _GLIBCXX20_CONSTEXPR
1082 inline _OutputIterator
1083 __fill_n_a1(_OutputIterator __first, _Size __n,
const _Tp& __value)
1086 const bool __load_outside_loop =
1087#if __has_builtin(__is_trivially_constructible) \
1088 && __has_builtin(__is_trivially_assignable)
1089 __is_trivially_constructible(_Tp,
const _Tp&)
1090 && __is_trivially_assignable(__decltype(*__first),
const _Tp&)
1092 __is_trivially_copyable(_Tp)
1093 && __is_same(_Tp, __typeof__(*__first))
1095 &&
sizeof(_Tp) <=
sizeof(
long long);
1099 typedef typename __gnu_cxx::__conditional_type<__load_outside_loop,
1101 const _Tp&>::__type _Up;
1103 for (; __n > 0; --__n, (void) ++__first)
1107#pragma GCC diagnostic pop
1109 template<
typename _Ite,
typename _Seq,
typename _Cat,
typename _Size,
1111 _GLIBCXX20_CONSTEXPR
1112 ::__gnu_debug::_Safe_iterator<_Ite, _Seq, _Cat>
1113 __fill_n_a(const ::__gnu_debug::_Safe_iterator<_Ite, _Seq, _Cat>& __first,
1114 _Size __n,
const _Tp& __value,
1115 std::input_iterator_tag);
1117 template<
typename _OutputIterator,
typename _Size,
typename _Tp>
1118 __attribute__((__always_inline__))
1119 _GLIBCXX20_CONSTEXPR
1120 inline _OutputIterator
1121 __fill_n_a(_OutputIterator __first, _Size __n,
const _Tp& __value,
1122 std::output_iterator_tag)
1124#if __cplusplus >= 201103L
1127 return __fill_n_a1(__first, __n, __value);
1130 template<
typename _OutputIterator,
typename _Size,
typename _Tp>
1131 __attribute__((__always_inline__))
1132 _GLIBCXX20_CONSTEXPR
1133 inline _OutputIterator
1134 __fill_n_a(_OutputIterator __first, _Size __n,
const _Tp& __value,
1135 std::input_iterator_tag)
1137#if __cplusplus >= 201103L
1140 return __fill_n_a1(__first, __n, __value);
1143 template<
typename _OutputIterator,
typename _Size,
typename _Tp>
1144 __attribute__((__always_inline__))
1145 _GLIBCXX20_CONSTEXPR
1146 inline _OutputIterator
1147 __fill_n_a(_OutputIterator __first, _Size __n,
const _Tp& __value,
1148 std::random_access_iterator_tag)
1150#if __cplusplus >= 201103L
1157 __glibcxx_requires_can_increment(__first, __d);
1159 _OutputIterator __last = __first + __d;
1160 std::__fill_a(__first, __last, __value);
1181 template<
typename _OI,
typename _Size,
typename _Tp>
1182 __attribute__((__always_inline__))
1183 _GLIBCXX20_CONSTEXPR
1185 fill_n(_OI __first, _Size __n,
const _Tp& __value)
1188 __glibcxx_function_requires(_OutputIteratorConcept<_OI, const _Tp&>)
1190 return std::__fill_n_a(__first, std::__size_to_integer(__n), __value,
1191 std::__iterator_category(__first));
1194 template<
bool _BoolType>
1197 template<
typename _II1,
typename _II2>
1198 _GLIBCXX20_CONSTEXPR
1200 equal(_II1 __first1, _II1 __last1, _II2 __first2)
1202 for (; __first1 != __last1; ++__first1, (void) ++__first2)
1203 if (!(*__first1 == *__first2))
1210 struct __equal<true>
1212 template<
typename _Tp>
1213 _GLIBCXX20_CONSTEXPR
1215 equal(
const _Tp* __first1,
const _Tp* __last1,
const _Tp* __first2)
1217 if (
const size_t __len = (__last1 - __first1))
1218 return !std::__memcmp(__first1, __first2, __len);
1223 template<
typename _Tp,
typename _Ref,
typename _Ptr,
typename _II>
1224 _GLIBCXX26_CONSTEXPR
1225 typename __gnu_cxx::__enable_if<
1226 __is_any_random_access_iter<_II>::__value,
bool>::__type
1227 __equal_aux1(_GLIBCXX_STD_C::_Deque_iterator<_Tp, _Ref, _Ptr>,
1228 _GLIBCXX_STD_C::_Deque_iterator<_Tp, _Ref, _Ptr>,
1231 template<
typename _Tp1,
typename _Ref1,
typename _Ptr1,
1232 typename _Tp2,
typename _Ref2,
typename _Ptr2>
1233 _GLIBCXX26_CONSTEXPR
bool
1234 __equal_aux1(_GLIBCXX_STD_C::_Deque_iterator<_Tp1, _Ref1, _Ptr1>,
1235 _GLIBCXX_STD_C::_Deque_iterator<_Tp1, _Ref1, _Ptr1>,
1236 _GLIBCXX_STD_C::_Deque_iterator<_Tp2, _Ref2, _Ptr2>);
1238 template<
typename _II,
typename _Tp,
typename _Ref,
typename _Ptr>
1239 _GLIBCXX26_CONSTEXPR
1240 typename __gnu_cxx::__enable_if<
1241 __is_any_random_access_iter<_II>::__value,
bool>::__type
1242 __equal_aux1(_II, _II,
1243 _GLIBCXX_STD_C::_Deque_iterator<_Tp, _Ref, _Ptr>);
1245 template<
typename _II1,
typename _II2>
1246 _GLIBCXX20_CONSTEXPR
1248 __equal_aux1(_II1 __first1, _II1 __last1, _II2 __first2)
1251 const bool __simple = ((__is_integer<_ValueType1>::__value
1252#if _GLIBCXX_USE_BUILTIN_TRAIT(__is_pointer)
1253 || __is_pointer(_ValueType1)
1255#if __glibcxx_byte && __glibcxx_type_trait_variable_templates
1257 || is_same_v<_ValueType1, byte>
1259 ) && __memcmpable<_II1, _II2>::__value);
1260 return std::__equal<__simple>::equal(__first1, __last1, __first2);
1263 template<
typename _II1,
typename _II2>
1264 __attribute__((__always_inline__))
1265 _GLIBCXX20_CONSTEXPR
1267 __equal_aux(_II1 __first1, _II1 __last1, _II2 __first2)
1269 return std::__equal_aux1(std::__niter_base(__first1),
1270 std::__niter_base(__last1),
1271 std::__niter_base(__first2));
1274 template<
typename _II1,
typename _Seq1,
typename _Cat1,
typename _II2>
1275 _GLIBCXX20_CONSTEXPR
1277 __equal_aux(const ::__gnu_debug::_Safe_iterator<_II1, _Seq1, _Cat1>&,
1278 const ::__gnu_debug::_Safe_iterator<_II1, _Seq1, _Cat1>&,
1281 template<
typename _II1,
typename _II2,
typename _Seq2,
typename _Cat2>
1282 _GLIBCXX20_CONSTEXPR
1284 __equal_aux(_II1, _II1,
1285 const ::__gnu_debug::_Safe_iterator<_II2, _Seq2, _Cat2>&);
1287 template<
typename _II1,
typename _Seq1,
typename _Cat1,
1288 typename _II2,
typename _Seq2,
typename _Cat2>
1289 _GLIBCXX20_CONSTEXPR
1291 __equal_aux(const ::__gnu_debug::_Safe_iterator<_II1, _Seq1, _Cat1>&,
1292 const ::__gnu_debug::_Safe_iterator<_II1, _Seq1, _Cat1>&,
1293 const ::__gnu_debug::_Safe_iterator<_II2, _Seq2, _Cat2>&);
1295 template<
typename,
typename>
1298 template<
typename _II1,
typename _II2>
1299 _GLIBCXX20_CONSTEXPR
1301 __newlast1(_II1, _II1 __last1, _II2, _II2)
1304 template<
typename _II>
1305 _GLIBCXX20_CONSTEXPR
1307 __cnd2(_II __first, _II __last)
1308 {
return __first != __last; }
1314 template<
typename _RAI1,
typename _RAI2>
1315 _GLIBCXX20_CONSTEXPR
1317 __newlast1(_RAI1 __first1, _RAI1 __last1,
1318 _RAI2 __first2, _RAI2 __last2)
1320 typedef typename iterator_traits<_RAI1>::difference_type _Diff1;
1321 typedef typename iterator_traits<_RAI2>::difference_type _Diff2;
1322 const _Diff1 __diff1 = __last1 - __first1;
1323 const _Diff2 __diff2 = __last2 - __first2;
1324 return __diff2 < __diff1 ? __first1 + _Diff1(__diff2) : __last1;
1327 template<
typename _RAI>
1328 static _GLIBCXX20_CONSTEXPR
bool
1333 template<
typename _II1,
typename _II2,
typename _Compare>
1334 _GLIBCXX20_CONSTEXPR
1336 __lexicographical_compare_impl(_II1 __first1, _II1 __last1,
1337 _II2 __first2, _II2 __last2,
1340 typedef __decltype(std::__iter_concept_or_category<_II1>()) _Category1;
1341 typedef __decltype(std::__iter_concept_or_category<_II2>()) _Category2;
1342 typedef std::__lc_rai<_Category1, _Category2> __rai_type;
1344 __last1 = __rai_type::__newlast1(__first1, __last1, __first2, __last2);
1345 for (; __first1 != __last1 && __rai_type::__cnd2(__first2, __last2);
1346 ++__first1, (
void)++__first2)
1348 if (__comp(*__first1, *__first2))
1350 if (__comp(*__first2, *__first1))
1353 return __first1 == __last1 && __first2 != __last2;
1356 template<
bool _BoolType>
1357 struct __lexicographical_compare
1359 template<
typename _II1,
typename _II2>
1360 _GLIBCXX20_CONSTEXPR
1362 __lc(_II1 __first1, _II1 __last1, _II2 __first2, _II2 __last2)
1364 using __gnu_cxx::__ops::less;
1365 return std::__lexicographical_compare_impl(__first1, __last1,
1370 template<
typename _II1,
typename _II2>
1371 _GLIBCXX20_CONSTEXPR
1373 __3way(_II1 __first1, _II1 __last1, _II2 __first2, _II2 __last2)
1375 while (__first1 != __last1)
1377 if (__first2 == __last2)
1379 if (*__first1 < *__first2)
1381 if (*__first2 < *__first1)
1386 return int(__first2 == __last2) - 1;
1391 struct __lexicographical_compare<true>
1393 template<
typename _Tp,
typename _Up>
1394 _GLIBCXX20_CONSTEXPR
1396 __lc(
const _Tp* __first1,
const _Tp* __last1,
1397 const _Up* __first2,
const _Up* __last2)
1398 {
return __3way(__first1, __last1, __first2, __last2) < 0; }
1400 template<
typename _Tp,
typename _Up>
1401 _GLIBCXX20_CONSTEXPR
1403 __3way(
const _Tp* __first1,
const _Tp* __last1,
1404 const _Up* __first2,
const _Up* __last2)
1406 const size_t __len1 = __last1 - __first1;
1407 const size_t __len2 = __last2 - __first2;
1408 if (
const size_t __len =
std::min(__len1, __len2))
1409 if (
int __result = std::__memcmp(__first1, __first2, __len))
1411 return ptrdiff_t(__len1 - __len2);
1415 template<
typename _II1,
typename _II2>
1416 _GLIBCXX20_CONSTEXPR
1418 __lexicographical_compare_aux1(_II1 __first1, _II1 __last1,
1419 _II2 __first2, _II2 __last2)
1423#if _GLIBCXX_USE_BUILTIN_TRAIT(__is_pointer)
1424 const bool __simple =
1425 (__is_memcmp_ordered_with<_ValueType1, _ValueType2>::__value
1426 && __is_pointer(_II1) && __is_pointer(_II2)
1427#if __cplusplus > 201703L && __glibcxx_concepts
1431 && !is_volatile_v<remove_reference_t<iter_reference_t<_II1>>>
1432 && !is_volatile_v<remove_reference_t<iter_reference_t<_II2>>>
1436 const bool __simple =
false;
1439 return std::__lexicographical_compare<__simple>::__lc(__first1, __last1,
1443 template<
typename _Tp1,
typename _Ref1,
typename _Ptr1,
1445 _GLIBCXX26_CONSTEXPR
bool
1446 __lexicographical_compare_aux1(
1447 _GLIBCXX_STD_C::_Deque_iterator<_Tp1, _Ref1, _Ptr1>,
1448 _GLIBCXX_STD_C::_Deque_iterator<_Tp1, _Ref1, _Ptr1>,
1451 template<
typename _Tp1,
1452 typename _Tp2,
typename _Ref2,
typename _Ptr2>
1453 _GLIBCXX26_CONSTEXPR
bool
1454 __lexicographical_compare_aux1(_Tp1*, _Tp1*,
1455 _GLIBCXX_STD_C::_Deque_iterator<_Tp2, _Ref2, _Ptr2>,
1456 _GLIBCXX_STD_C::_Deque_iterator<_Tp2, _Ref2, _Ptr2>);
1458 template<
typename _Tp1,
typename _Ref1,
typename _Ptr1,
1459 typename _Tp2,
typename _Ref2,
typename _Ptr2>
1460 _GLIBCXX26_CONSTEXPR
bool
1461 __lexicographical_compare_aux1(
1462 _GLIBCXX_STD_C::_Deque_iterator<_Tp1, _Ref1, _Ptr1>,
1463 _GLIBCXX_STD_C::_Deque_iterator<_Tp1, _Ref1, _Ptr1>,
1464 _GLIBCXX_STD_C::_Deque_iterator<_Tp2, _Ref2, _Ptr2>,
1465 _GLIBCXX_STD_C::_Deque_iterator<_Tp2, _Ref2, _Ptr2>);
1467 template<
typename _II1,
typename _II2>
1468 _GLIBCXX20_CONSTEXPR
1470 __lexicographical_compare_aux(_II1 __first1, _II1 __last1,
1471 _II2 __first2, _II2 __last2)
1473 return std::__lexicographical_compare_aux1(std::__niter_base(__first1),
1474 std::__niter_base(__last1),
1475 std::__niter_base(__first2),
1476 std::__niter_base(__last2));
1479 template<
typename _Iter1,
typename _Seq1,
typename _Cat1,
1481 _GLIBCXX20_CONSTEXPR
1483 __lexicographical_compare_aux(
1484 const ::__gnu_debug::_Safe_iterator<_Iter1, _Seq1, _Cat1>&,
1485 const ::__gnu_debug::_Safe_iterator<_Iter1, _Seq1, _Cat1>&,
1488 template<
typename _II1,
1489 typename _Iter2,
typename _Seq2,
typename _Cat2>
1490 _GLIBCXX20_CONSTEXPR
1492 __lexicographical_compare_aux(
1494 const ::__gnu_debug::_Safe_iterator<_Iter2, _Seq2, _Cat2>&,
1495 const ::__gnu_debug::_Safe_iterator<_Iter2, _Seq2, _Cat2>&);
1497 template<
typename _Iter1,
typename _Seq1,
typename _Cat1,
1498 typename _Iter2,
typename _Seq2,
typename _Cat2>
1499 _GLIBCXX20_CONSTEXPR
1501 __lexicographical_compare_aux(
1502 const ::__gnu_debug::_Safe_iterator<_Iter1, _Seq1, _Cat1>&,
1503 const ::__gnu_debug::_Safe_iterator<_Iter1, _Seq1, _Cat1>&,
1504 const ::__gnu_debug::_Safe_iterator<_Iter2, _Seq2, _Cat2>&,
1505 const ::__gnu_debug::_Safe_iterator<_Iter2, _Seq2, _Cat2>&);
1507 template<
typename _ForwardIterator,
typename _Tp,
typename _Compare>
1508 _GLIBCXX20_CONSTEXPR
1510 __lower_bound(_ForwardIterator __first, _ForwardIterator __last,
1511 const _Tp& __val, _Compare __comp)
1520 _DistanceType __half = __len >> 1;
1521 _ForwardIterator __middle = __first;
1523 if (__comp(*__middle, __val))
1527 __len = __len - __half - 1;
1546 template<
typename _ForwardIterator,
typename _Tp>
1547 _GLIBCXX_NODISCARD _GLIBCXX20_CONSTEXPR
1548 inline _ForwardIterator
1549 lower_bound(_ForwardIterator __first, _ForwardIterator __last,
1553 __glibcxx_function_requires(_ForwardIteratorConcept<_ForwardIterator>)
1554 __glibcxx_function_requires(_LessThanOpConcept<
1556 __glibcxx_requires_partitioned_lower(__first, __last, __val);
1558 return std::__lower_bound(__first, __last, __val,
1559 __gnu_cxx::__ops::less());
1564 template<
typename _Tp>
1565 inline _GLIBCXX_CONSTEXPR _Tp
1568#if __cplusplus >= 201402L
1571#pragma GCC diagnostic push
1572#pragma GCC diagnostic ignored "-Wlong-long"
1574 return (
sizeof(+__n) * __CHAR_BIT__ - 1)
1575 - (
sizeof(+__n) ==
sizeof(
long long)
1576 ? __builtin_clzll(+__n)
1577 : (
sizeof(+__n) ==
sizeof(long)
1578 ? __builtin_clzl(+__n)
1579 : __builtin_clz(+__n)));
1580#pragma GCC diagnostic pop
1584_GLIBCXX_BEGIN_NAMESPACE_ALGO
1598 template<
typename _II1,
typename _II2>
1599 _GLIBCXX_NODISCARD _GLIBCXX20_CONSTEXPR
1601 equal(_II1 __first1, _II1 __last1, _II2 __first2)
1604 __glibcxx_function_requires(_InputIteratorConcept<_II1>)
1605 __glibcxx_function_requires(_InputIteratorConcept<_II2>)
1606 __glibcxx_function_requires(_EqualOpConcept<
1609 __glibcxx_requires_can_increment_range(__first1, __last1, __first2);
1611 return std::__equal_aux(__first1, __last1, __first2);
1629 template<
typename _IIter1,
typename _IIter2,
typename _BinaryPredicate>
1630 _GLIBCXX_NODISCARD _GLIBCXX20_CONSTEXPR
1632 equal(_IIter1 __first1, _IIter1 __last1,
1633 _IIter2 __first2, _BinaryPredicate __binary_pred)
1636 __glibcxx_function_requires(_InputIteratorConcept<_IIter1>)
1637 __glibcxx_function_requires(_InputIteratorConcept<_IIter2>)
1638 __glibcxx_requires_valid_range(__first1, __last1);
1640 for (; __first1 != __last1; ++__first1, (void)++__first2)
1641 if (!
bool(__binary_pred(*__first1, *__first2)))
1646#if __cplusplus >= 201103L
1647#pragma GCC diagnostic push
1648#pragma GCC diagnostic ignored "-Wc++17-extensions"
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 =
decltype(std::__iter_concept_or_category<_II1>());
1658 using _Cat2 =
decltype(std::__iter_concept_or_category<_II2>());
1659 using _RAIters = __and_<is_same<_Cat1, _RATag>, is_same<_Cat2, _RATag>>;
1660 if constexpr (_RAIters::value)
1662 if ((__last1 - __first1) != (__last2 - __first2))
1664 return _GLIBCXX_STD_A::equal(__first1, __last1, __first2);
1668 for (; __first1 != __last1 && __first2 != __last2;
1669 ++__first1, (void)++__first2)
1670 if (!(*__first1 == *__first2))
1672 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)
1684 using _Cat1 =
decltype(std::__iter_concept_or_category<_II1>());
1685 using _Cat2 =
decltype(std::__iter_concept_or_category<_II2>());
1687 if constexpr (_RAIters::value)
1689 if ((__last1 - __first1) != (__last2 - __first2))
1691 return _GLIBCXX_STD_A::equal(__first1, __last1, __first2,
1696 for (; __first1 != __last1 && __first2 != __last2;
1697 ++__first1, (void)++__first2)
1698 if (!
bool(__binary_pred(*__first1, *__first2)))
1700 return __first1 == __last1 && __first2 == __last2;
1703#pragma GCC diagnostic pop
1706#ifdef __glibcxx_robust_nonmodifying_seq_ops
1720 template<
typename _II1,
typename _II2>
1721 _GLIBCXX_NODISCARD _GLIBCXX20_CONSTEXPR
1723 equal(_II1 __first1, _II1 __last1, _II2 __first2, _II2 __last2)
1726 __glibcxx_function_requires(_InputIteratorConcept<_II1>)
1727 __glibcxx_function_requires(_InputIteratorConcept<_II2>)
1728 __glibcxx_function_requires(_EqualOpConcept<
1731 __glibcxx_requires_valid_range(__first1, __last1);
1732 __glibcxx_requires_valid_range(__first2, __last2);
1734 return _GLIBCXX_STD_A::__equal4(__first1, __last1, __first2, __last2);
1753 template<
typename _IIter1,
typename _IIter2,
typename _BinaryPredicate>
1754 _GLIBCXX_NODISCARD _GLIBCXX20_CONSTEXPR
1756 equal(_IIter1 __first1, _IIter1 __last1,
1757 _IIter2 __first2, _IIter2 __last2, _BinaryPredicate __binary_pred)
1760 __glibcxx_function_requires(_InputIteratorConcept<_IIter1>)
1761 __glibcxx_function_requires(_InputIteratorConcept<_IIter2>)
1762 __glibcxx_requires_valid_range(__first1, __last1);
1763 __glibcxx_requires_valid_range(__first2, __last2);
1765 return _GLIBCXX_STD_A::__equal4(__first1, __last1, __first2, __last2,
1785 template<
typename _II1,
typename _II2>
1786 _GLIBCXX_NODISCARD _GLIBCXX20_CONSTEXPR
1788 lexicographical_compare(_II1 __first1, _II1 __last1,
1789 _II2 __first2, _II2 __last2)
1791#ifdef _GLIBCXX_CONCEPT_CHECKS
1796 __glibcxx_function_requires(_InputIteratorConcept<_II1>)
1797 __glibcxx_function_requires(_InputIteratorConcept<_II2>)
1798 __glibcxx_function_requires(_LessThanOpConcept<_ValueType1, _ValueType2>)
1799 __glibcxx_function_requires(_LessThanOpConcept<_ValueType2, _ValueType1>)
1800 __glibcxx_requires_valid_range(__first1, __last1);
1801 __glibcxx_requires_valid_range(__first2, __last2);
1803 return std::__lexicographical_compare_aux(__first1, __last1,
1820 template<
typename _II1,
typename _II2,
typename _Compare>
1821 _GLIBCXX_NODISCARD _GLIBCXX20_CONSTEXPR
1823 lexicographical_compare(_II1 __first1, _II1 __last1,
1824 _II2 __first2, _II2 __last2, _Compare __comp)
1827 __glibcxx_function_requires(_InputIteratorConcept<_II1>)
1828 __glibcxx_function_requires(_InputIteratorConcept<_II2>)
1829 __glibcxx_requires_valid_range(__first1, __last1);
1830 __glibcxx_requires_valid_range(__first2, __last2);
1832 return std::__lexicographical_compare_impl
1833 (__first1, __last1, __first2, __last2, __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));
1891 if (!std::__is_constant_evaluated())
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
1938 __mismatch(_InputIterator1 __first1, _InputIterator1 __last1,
1939 _InputIterator2 __first2, _BinaryPredicate __binary_pred)
1941 while (__first1 != __last1 &&
bool(__binary_pred(*__first1, *__first2)))
1962 template<
typename _InputIterator1,
typename _InputIterator2>
1963 _GLIBCXX_NODISCARD _GLIBCXX20_CONSTEXPR
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::equal_to());
1996 template<
typename _InputIterator1,
typename _InputIterator2,
1997 typename _BinaryPredicate>
1998 _GLIBCXX_NODISCARD _GLIBCXX20_CONSTEXPR
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,
2012#if __glibcxx_robust_nonmodifying_seq_ops
2013 template<
typename _InputIterator1,
typename _InputIterator2,
2014 typename _BinaryPredicate>
2015 _GLIBCXX20_CONSTEXPR
2017 __mismatch(_InputIterator1 __first1, _InputIterator1 __last1,
2018 _InputIterator2 __first2, _InputIterator2 __last2,
2019 _BinaryPredicate __binary_pred)
2021 while (__first1 != __last1 && __first2 != __last2
2022 &&
bool(__binary_pred(*__first1, *__first2)))
2044 template<
typename _InputIterator1,
typename _InputIterator2>
2045 _GLIBCXX_NODISCARD _GLIBCXX20_CONSTEXPR
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::equal_to());
2080 template<
typename _InputIterator1,
typename _InputIterator2,
2081 typename _BinaryPredicate>
2082 _GLIBCXX_NODISCARD _GLIBCXX20_CONSTEXPR
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,
2099_GLIBCXX_END_NAMESPACE_ALGO
2102 template<
typename _Iterator,
typename _Predicate>
2103 _GLIBCXX20_CONSTEXPR
2105 __find_if(_Iterator __first, _Iterator __last, _Predicate __pred)
2108 while (__first != __last && !
bool(__pred(*__first)))
2113 template<
typename _InputIterator,
typename _Predicate>
2114 _GLIBCXX20_CONSTEXPR
2116 __count_if(_InputIterator __first, _InputIterator __last, _Predicate __pred)
2119 for (; __first != __last; ++__first)
2120 if (__pred(*__first))
2125 template<
typename _ForwardIterator,
typename _Predicate>
2126 _GLIBCXX20_CONSTEXPR
2128 __remove_if(_ForwardIterator __first, _ForwardIterator __last,
2131 __first = std::__find_if(__first, __last, __pred);
2132 if (__first == __last)
2134 _ForwardIterator __result = __first;
2136 for (; __first != __last; ++__first)
2137 if (!__pred(*__first))
2139 *__result = _GLIBCXX_MOVE(*__first);
2145 template<
typename _ForwardIterator1,
typename _ForwardIterator2,
2146 typename _BinaryPredicate>
2147 _GLIBCXX20_CONSTEXPR
2149 __search(_ForwardIterator1 __first1, _ForwardIterator1 __last1,
2150 _ForwardIterator2 __first2, _ForwardIterator2 __last2,
2151 _BinaryPredicate __predicate)
2154 if (__first1 == __last1 || __first2 == __last2)
2157 __decltype(*__first2) __first2_val(*__first2);
2158 __decltype(__gnu_cxx::__ops::bind2nd(__predicate, __first2_val))
2159 __match_first = __gnu_cxx::__ops::bind2nd(__predicate, __first2_val);
2162 _ForwardIterator2 __p1(__first2);
2163 if (++__p1 == __last2)
2164 return std::__find_if(__first1, __last1, __match_first);
2167 _ForwardIterator1 __current = __first1;
2171 __first1 = std::__find_if(__first1, __last1, __match_first);
2173 if (__first1 == __last1)
2176 _ForwardIterator2 __p = __p1;
2177 __current = __first1;
2178 if (++__current == __last1)
2181 while (__predicate(*__current, *__p))
2183 if (++__p == __last2)
2185 if (++__current == __last1)
2194#if __cplusplus >= 201103L
2195 template<
typename _ForwardIterator1,
typename _ForwardIterator2,
2196 typename _BinaryPredicate>
2197 _GLIBCXX20_CONSTEXPR
2199 __is_permutation(_ForwardIterator1 __first1, _ForwardIterator1 __last1,
2200 _ForwardIterator2 __first2, _BinaryPredicate __pred)
2204 for (; __first1 != __last1; ++__first1, (void)++__first2)
2205 if (!__pred(*__first1, *__first2))
2208 if (__first1 == __last1)
2213 _ForwardIterator2 __last2 = __first2;
2215 for (_ForwardIterator1 __scan = __first1; __scan != __last1; ++__scan)
2217 auto&& __scan_val = *__scan;
2218 auto __scaneq = __gnu_cxx::__ops::bind1st(__pred, __scan_val);
2219 if (__scan != std::__find_if(__first1, __scan, __scaneq))
2222 auto __matches = std::__count_if(__first2, __last2, __scaneq);
2224 || std::__count_if(__scan, __last1, __scaneq) != __matches)
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::equal_to());
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, __predicate);
2304_GLIBCXX_END_NAMESPACE_ALGO
2305_GLIBCXX_END_NAMESPACE_VERSION
2311#ifdef _GLIBCXX_PARALLEL
Parallel STL function calls corresponding to the stl_algobase.h header. The functions defined here ma...
constexpr _Tp * to_address(_Tp *__ptr) noexcept
Obtain address referenced by a pointer to an object.
typename make_unsigned< _Tp >::type make_unsigned_t
Alias template for make_unsigned.
pair(_T1, _T2) -> pair< _T1, _T2 >
Two pairs are equal iff their members are equal.
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.
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.
Basis for explicit traits specializations.
Provides input iterator semantics for streambufs.
Traits class for iterators.
Struct holding two objects (or references) of arbitrary type.
Random-access iterators support a superset of bidirectional iterator operations.
[concept.same], concept same_as