56#ifndef _STL_ALGOBASE_H
57#define _STL_ALGOBASE_H 1
72#if __cplusplus >= 201103L
75#if __cplusplus >= 201402L
78#if __cplusplus >= 202002L
83namespace std _GLIBCXX_VISIBILITY(default)
85_GLIBCXX_BEGIN_NAMESPACE_VERSION
91 template<
typename _Tp,
typename _Up>
94 __memcmp(
const _Tp* __first1,
const _Up* __first2,
size_t __num)
96#if __cplusplus >= 201103L
97 static_assert(
sizeof(_Tp) ==
sizeof(_Up),
"can be compared with memcmp");
99#ifdef __cpp_lib_is_constant_evaluated
100 if (std::is_constant_evaluated())
102 for(; __num > 0; ++__first1, ++__first2, --__num)
103 if (*__first1 != *__first2)
104 return *__first1 < *__first2 ? -1 : 1;
109 return __builtin_memcmp(__first1, __first2,
sizeof(_Tp) * __num);
112#if __cplusplus < 201103L
116 template<
bool _BoolType>
119 template<
typename _ForwardIterator1,
typename _ForwardIterator2>
121 iter_swap(_ForwardIterator1 __a, _ForwardIterator2 __b)
123 typedef typename iterator_traits<_ForwardIterator1>::value_type
125 _ValueType1 __tmp = *__a;
132 struct __iter_swap<true>
134 template<
typename _ForwardIterator1,
typename _ForwardIterator2>
136 iter_swap(_ForwardIterator1 __a, _ForwardIterator2 __b)
153 template<
typename _ForwardIterator1,
typename _ForwardIterator2>
156 iter_swap(_ForwardIterator1 __a, _ForwardIterator2 __b)
159 __glibcxx_function_requires(_Mutable_ForwardIteratorConcept<
161 __glibcxx_function_requires(_Mutable_ForwardIteratorConcept<
164#if __cplusplus < 201103L
170 __glibcxx_function_requires(_ConvertibleConcept<_ValueType1,
172 __glibcxx_function_requires(_ConvertibleConcept<_ValueType2,
179 std::__iter_swap<__are_same<_ValueType1, _ValueType2>::__value
180 && __are_same<_ValueType1&, _ReferenceType1>::__value
181 && __are_same<_ValueType2&, _ReferenceType2>::__value>::
202 template<
typename _ForwardIterator1,
typename _ForwardIterator2>
205 swap_ranges(_ForwardIterator1 __first1, _ForwardIterator1 __last1,
206 _ForwardIterator2 __first2)
209 __glibcxx_function_requires(_Mutable_ForwardIteratorConcept<
211 __glibcxx_function_requires(_Mutable_ForwardIteratorConcept<
213 __glibcxx_requires_valid_range(__first1, __last1);
215 for (; __first1 != __last1; ++__first1, (void)++__first2)
216 std::iter_swap(__first1, __first2);
231 template<
typename _Tp>
232 _GLIBCXX_NODISCARD _GLIBCXX14_CONSTEXPR
234 min(
const _Tp& __a,
const _Tp& __b)
237 __glibcxx_function_requires(_LessThanComparableConcept<_Tp>)
255 template<
typename _Tp>
256 _GLIBCXX_NODISCARD _GLIBCXX14_CONSTEXPR
258 max(
const _Tp& __a,
const _Tp& __b)
261 __glibcxx_function_requires(_LessThanComparableConcept<_Tp>)
279 template<
typename _Tp,
typename _Compare>
280 _GLIBCXX_NODISCARD _GLIBCXX14_CONSTEXPR
282 min(
const _Tp& __a,
const _Tp& __b, _Compare __comp)
285 if (__comp(__b, __a))
301 template<
typename _Tp,
typename _Compare>
302 _GLIBCXX_NODISCARD _GLIBCXX14_CONSTEXPR
304 max(
const _Tp& __a,
const _Tp& __b, _Compare __comp)
307 if (__comp(__a, __b))
312_GLIBCXX_BEGIN_NAMESPACE_CONTAINER
314 template<
typename _Tp,
typename _Ref,
typename _Ptr>
315 struct _Deque_iterator;
317 struct _Bit_iterator;
319_GLIBCXX_END_NAMESPACE_CONTAINER
324 template<
typename _CharT>
327 template<
typename _CharT,
typename _Traits>
328 class istreambuf_iterator;
330 template<
typename _CharT,
typename _Traits>
331 class ostreambuf_iterator;
333 template<
bool _IsMove,
typename _CharT>
334 typename __gnu_cxx::__enable_if<__is_char<_CharT>::__value,
335 ostreambuf_iterator<_CharT, char_traits<_CharT> > >::__type
336 __copy_move_a2(_CharT*, _CharT*,
337 ostreambuf_iterator<_CharT, char_traits<_CharT> >);
339 template<
bool _IsMove,
typename _CharT>
340 typename __gnu_cxx::__enable_if<__is_char<_CharT>::__value,
341 ostreambuf_iterator<_CharT, char_traits<_CharT> > >::__type
342 __copy_move_a2(
const _CharT*,
const _CharT*,
343 ostreambuf_iterator<_CharT, char_traits<_CharT> >);
345 template<
bool _IsMove,
typename _CharT>
346 typename __gnu_cxx::__enable_if<__is_char<_CharT>::__value,
348 __copy_move_a2(istreambuf_iterator<_CharT, char_traits<_CharT> >,
349 istreambuf_iterator<_CharT, char_traits<_CharT> >, _CharT*);
351 template<
bool _IsMove,
typename _CharT>
352 typename __gnu_cxx::__enable_if<
353 __is_char<_CharT>::__value,
354 _GLIBCXX_STD_C::_Deque_iterator<_CharT, _CharT&, _CharT*> >::__type
356 istreambuf_iterator<_CharT, char_traits<_CharT> >,
357 istreambuf_iterator<_CharT, char_traits<_CharT> >,
358 _GLIBCXX_STD_C::_Deque_iterator<_CharT, _CharT&, _CharT*>);
361#if __cpp_lib_concepts
362 template<
typename _OutIter,
typename _InIter,
typename _Sent = _InIter>
363 concept __memcpyable_iterators
364 = contiguous_iterator<_OutIter> && contiguous_iterator<_InIter>
365 && sized_sentinel_for<_Sent, _InIter>
366 &&
requires (_OutIter __o, _InIter __i) {
372#if __cplusplus < 201103L
377 template<
typename _Iter> __attribute__((__always_inline__))
378 inline void* __ptr_or_null(_Iter) {
return 0; }
379 template<
typename _Tp> __attribute__((__always_inline__))
380 inline void* __ptr_or_null(_Tp* __p) {
return (
void*)__p; }
381# define _GLIBCXX_TO_ADDR(P) std::__ptr_or_null(P)
383 template<
typename _Iter> __attribute__((__always_inline__))
384 inline void __ptr_advance(_Iter&, ptrdiff_t) { }
385 template<
typename _Tp> __attribute__((__always_inline__))
386 inline void __ptr_advance(_Tp*& __p, ptrdiff_t __n) { __p += __n; }
387# define _GLIBCXX_ADVANCE(P, N) std::__ptr_advance(P, N)
391# define _GLIBCXX_TO_ADDR(P) P
392# define _GLIBCXX_ADVANCE(P, N) P += N
395#pragma GCC diagnostic push
396#pragma GCC diagnostic ignored "-Wc++17-extensions"
397 template<
bool _IsMove,
typename _OutIter,
typename _InIter>
398 __attribute__((__always_inline__)) _GLIBCXX20_CONSTEXPR
400 __assign_one(_OutIter& __out, _InIter& __in)
402#if __cplusplus >= 201103L
403 if constexpr (_IsMove)
410 template<
bool _IsMove,
typename _InIter,
typename _Sent,
typename _OutIter>
413 __copy_move_a2(_InIter __first, _Sent __last, _OutIter __result)
415 typedef __decltype(*__first) _InRef;
416 typedef __decltype(*__result) _OutRef;
417 if _GLIBCXX_CONSTEXPR (!__is_trivially_assignable(_OutRef, _InRef))
419 else if (std::__is_constant_evaluated())
421 else if _GLIBCXX_CONSTEXPR (__memcpyable<_OutIter, _InIter>::__value)
424 if (__builtin_expect(__n > 1,
true))
426 __builtin_memmove(_GLIBCXX_TO_ADDR(__result),
427 _GLIBCXX_TO_ADDR(__first),
428 __n *
sizeof(*__first));
429 _GLIBCXX_ADVANCE(__result, __n);
433 std::__assign_one<_IsMove>(__result, __first);
438#if __cpp_lib_concepts
439 else if constexpr (__memcpyable_iterators<_OutIter, _InIter, _Sent>)
441 if (
auto __n = __last - __first; __n > 1) [[likely]]
445 size_t __nbytes = __n *
sizeof(iter_value_t<_InIter>);
450 __builtin_memmove(__dest, __src, __nbytes);
454 std::__assign_one<_IsMove>(__result, __first);
461 for (; __first != __last; ++__result, (void)++__first)
462 std::__assign_one<_IsMove>(__result, __first);
465#pragma GCC diagnostic pop
467 template<
bool _IsMove,
468 typename _Tp,
typename _Ref,
typename _Ptr,
typename _OI>
470 __copy_move_a1(_GLIBCXX_STD_C::_Deque_iterator<_Tp, _Ref, _Ptr>,
471 _GLIBCXX_STD_C::_Deque_iterator<_Tp, _Ref, _Ptr>,
474 template<
bool _IsMove,
475 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>
482 typename __gnu_cxx::__enable_if<
483 __is_random_access_iter<_II>::__value,
484 _GLIBCXX_STD_C::_Deque_iterator<_Tp, _Tp&, _Tp*> >::__type
485 __copy_move_a1(_II, _II, _GLIBCXX_STD_C::_Deque_iterator<_Tp, _Tp&, _Tp*>);
487 template<
bool _IsMove,
typename _II,
typename _OI>
488 __attribute__((__always_inline__))
491 __copy_move_a1(_II __first, _II __last, _OI __result)
492 {
return std::__copy_move_a2<_IsMove>(__first, __last, __result); }
494 template<
bool _IsMove,
typename _II,
typename _OI>
495 __attribute__((__always_inline__))
498 __copy_move_a(_II __first, _II __last, _OI __result)
500 return std::__niter_wrap(__result,
501 std::__copy_move_a1<_IsMove>(std::__niter_base(__first),
502 std::__niter_base(__last),
503 std::__niter_base(__result)));
506 template<
bool _IsMove,
507 typename _Ite,
typename _Seq,
typename _Cat,
typename _OI>
510 __copy_move_a(const ::__gnu_debug::_Safe_iterator<_Ite, _Seq, _Cat>&,
511 const ::__gnu_debug::_Safe_iterator<_Ite, _Seq, _Cat>&,
514 template<
bool _IsMove,
515 typename _II,
typename _Ite,
typename _Seq,
typename _Cat>
517 __gnu_debug::_Safe_iterator<_Ite, _Seq, _Cat>
518 __copy_move_a(_II, _II,
519 const ::__gnu_debug::_Safe_iterator<_Ite, _Seq, _Cat>&);
521 template<
bool _IsMove,
522 typename _IIte,
typename _ISeq,
typename _ICat,
523 typename _OIte,
typename _OSeq,
typename _OCat>
525 ::__gnu_debug::_Safe_iterator<_OIte, _OSeq, _OCat>
526 __copy_move_a(const ::__gnu_debug::_Safe_iterator<_IIte, _ISeq, _ICat>&,
527 const ::__gnu_debug::_Safe_iterator<_IIte, _ISeq, _ICat>&,
528 const ::__gnu_debug::_Safe_iterator<_OIte, _OSeq, _OCat>&);
530#pragma GCC diagnostic push
531#pragma GCC diagnostic ignored "-Wc++17-extensions"
532 template<
typename _InputIterator,
typename _Size,
typename _OutputIterator>
535 __copy_n_a(_InputIterator __first, _Size __n, _OutputIterator __result,
538 typedef __decltype(*__first) _InRef;
539 typedef __decltype(*__result) _OutRef;
540 if _GLIBCXX_CONSTEXPR (!__is_trivially_assignable(_OutRef, _InRef))
542#ifdef __cpp_lib_is_constant_evaluated
543 else if (std::is_constant_evaluated())
546 else if _GLIBCXX_CONSTEXPR (__memcpyable<_OutputIterator,
547 _InputIterator>::__value)
549 if (__builtin_expect(__n > 1,
true))
551 __builtin_memmove(_GLIBCXX_TO_ADDR(__result),
552 _GLIBCXX_TO_ADDR(__first),
553 __n *
sizeof(*__first));
554 _GLIBCXX_ADVANCE(__result, __n);
557 *__result++ = *__first;
560#if __cpp_lib_concepts
561 else if constexpr (__memcpyable_iterators<_OutputIterator,
564 if (__n > 1) [[likely]]
568 size_t __nbytes = __n *
sizeof(iter_value_t<_InputIterator>);
573 __builtin_memmove(__dest, __src, __nbytes);
576 *__result++ = *__first;
585 *__result = *__first;
595#pragma GCC diagnostic pop
598 template<
typename _CharT,
typename _Size>
599 typename __gnu_cxx::__enable_if<
600 __is_char<_CharT>::__value, _CharT*>::__type
602 _Size, _CharT*,
bool);
604 template<
typename _CharT,
typename _Size>
605 typename __gnu_cxx::__enable_if<
606 __is_char<_CharT>::__value,
607 _GLIBCXX_STD_C::_Deque_iterator<_CharT, _CharT&, _CharT*> >::__type
609 _GLIBCXX_STD_C::_Deque_iterator<_CharT, _CharT&, _CharT*>,
630 template<
typename _II,
typename _OI>
633 copy(_II __first, _II __last, _OI __result)
636 __glibcxx_function_requires(_InputIteratorConcept<_II>)
637 __glibcxx_function_requires(_OutputIteratorConcept<_OI,
639 __glibcxx_requires_can_increment_range(__first, __last, __result);
641 return std::__copy_move_a<__is_move_iterator<_II>::__value>
642 (std::__miter_base(__first), std::__miter_base(__last), __result);
645#if __cplusplus >= 201103L
663 template<
typename _II,
typename _OI>
666 move(_II __first, _II __last, _OI __result)
669 __glibcxx_function_requires(_InputIteratorConcept<_II>)
670 __glibcxx_function_requires(_OutputIteratorConcept<_OI,
672 __glibcxx_requires_can_increment_range(__first, __last, __result);
674 return std::__copy_move_a<true>(std::__miter_base(__first),
675 std::__miter_base(__last), __result);
678#define _GLIBCXX_MOVE3(_Tp, _Up, _Vp) std::move(_Tp, _Up, _Vp)
680#define _GLIBCXX_MOVE3(_Tp, _Up, _Vp) std::copy(_Tp, _Up, _Vp)
683#pragma GCC diagnostic push
684#pragma GCC diagnostic ignored "-Wc++17-extensions"
685 template<
bool _IsMove,
typename _BI1,
typename _BI2>
688 __copy_move_backward_a2(_BI1 __first, _BI1 __last, _BI2 __result)
690 typedef __decltype(*__first) _InRef;
691 typedef __decltype(*__result) _OutRef;
692 if _GLIBCXX_CONSTEXPR (!__is_trivially_assignable(_OutRef, _InRef))
694#ifdef __cpp_lib_is_constant_evaluated
695 else if (std::is_constant_evaluated())
698 else if _GLIBCXX_CONSTEXPR (__memcpyable<_BI2, _BI1>::__value)
702 if (__builtin_expect(__n > 1,
true))
704 __builtin_memmove(_GLIBCXX_TO_ADDR(__result),
705 _GLIBCXX_TO_ADDR(__first),
706 __n *
sizeof(*__first));
709 std::__assign_one<_IsMove>(__result, __first);
712#if __cpp_lib_concepts
713 else if constexpr (__memcpyable_iterators<_BI2, _BI1>)
715 if (
auto __n = __last - __first; __n > 1) [[likely]]
723 size_t __nbytes = __n *
sizeof(iter_value_t<_BI1>);
724 __builtin_memmove(__dest, __src, __nbytes);
729 std::__assign_one<_IsMove>(__result, __first);
735 while (__first != __last)
739 std::__assign_one<_IsMove>(__result, __last);
743#pragma GCC diagnostic pop
745#undef _GLIBCXX_TO_ADDR
746#undef _GLIBCXX_ADVANCE
748 template<
bool _IsMove,
typename _BI1,
typename _BI2>
749 __attribute__((__always_inline__))
752 __copy_move_backward_a1(_BI1 __first, _BI1 __last, _BI2 __result)
753 {
return std::__copy_move_backward_a2<_IsMove>(__first, __last, __result); }
755 template<
bool _IsMove,
756 typename _Tp,
typename _Ref,
typename _Ptr,
typename _OI>
758 __copy_move_backward_a1(_GLIBCXX_STD_C::_Deque_iterator<_Tp, _Ref, _Ptr>,
759 _GLIBCXX_STD_C::_Deque_iterator<_Tp, _Ref, _Ptr>,
762 template<
bool _IsMove,
763 typename _ITp,
typename _IRef,
typename _IPtr,
typename _OTp>
764 _GLIBCXX_STD_C::_Deque_iterator<_OTp, _OTp&, _OTp*>
765 __copy_move_backward_a1(
766 _GLIBCXX_STD_C::_Deque_iterator<_ITp, _IRef, _IPtr>,
767 _GLIBCXX_STD_C::_Deque_iterator<_ITp, _IRef, _IPtr>,
768 _GLIBCXX_STD_C::_Deque_iterator<_OTp, _OTp&, _OTp*>);
770 template<
bool _IsMove,
typename _II,
typename _Tp>
771 typename __gnu_cxx::__enable_if<
772 __is_random_access_iter<_II>::__value,
773 _GLIBCXX_STD_C::_Deque_iterator<_Tp, _Tp&, _Tp*> >::__type
774 __copy_move_backward_a1(_II, _II,
775 _GLIBCXX_STD_C::_Deque_iterator<_Tp, _Tp&, _Tp*>);
777 template<
bool _IsMove,
typename _II,
typename _OI>
778 __attribute__((__always_inline__))
781 __copy_move_backward_a(_II __first, _II __last, _OI __result)
783 return std::__niter_wrap(__result,
784 std::__copy_move_backward_a1<_IsMove>
785 (std::__niter_base(__first), std::__niter_base(__last),
786 std::__niter_base(__result)));
789 template<
bool _IsMove,
790 typename _Ite,
typename _Seq,
typename _Cat,
typename _OI>
793 __copy_move_backward_a(
794 const ::__gnu_debug::_Safe_iterator<_Ite, _Seq, _Cat>&,
795 const ::__gnu_debug::_Safe_iterator<_Ite, _Seq, _Cat>&,
798 template<
bool _IsMove,
799 typename _II,
typename _Ite,
typename _Seq,
typename _Cat>
801 __gnu_debug::_Safe_iterator<_Ite, _Seq, _Cat>
802 __copy_move_backward_a(_II, _II,
803 const ::__gnu_debug::_Safe_iterator<_Ite, _Seq, _Cat>&);
805 template<
bool _IsMove,
806 typename _IIte,
typename _ISeq,
typename _ICat,
807 typename _OIte,
typename _OSeq,
typename _OCat>
809 ::__gnu_debug::_Safe_iterator<_OIte, _OSeq, _OCat>
810 __copy_move_backward_a(
811 const ::__gnu_debug::_Safe_iterator<_IIte, _ISeq, _ICat>&,
812 const ::__gnu_debug::_Safe_iterator<_IIte, _ISeq, _ICat>&,
813 const ::__gnu_debug::_Safe_iterator<_OIte, _OSeq, _OCat>&);
833 template<
typename _BI1,
typename _BI2>
834 __attribute__((__always_inline__))
837 copy_backward(_BI1 __first, _BI1 __last, _BI2 __result)
840 __glibcxx_function_requires(_BidirectionalIteratorConcept<_BI1>)
841 __glibcxx_function_requires(_Mutable_BidirectionalIteratorConcept<_BI2>)
842 __glibcxx_function_requires(_OutputIteratorConcept<_BI2,
844 __glibcxx_requires_can_decrement_range(__first, __last, __result);
846 return std::__copy_move_backward_a<__is_move_iterator<_BI1>::__value>
847 (std::__miter_base(__first), std::__miter_base(__last), __result);
850#if __cplusplus >= 201103L
869 template<
typename _BI1,
typename _BI2>
870 __attribute__((__always_inline__))
876 __glibcxx_function_requires(_BidirectionalIteratorConcept<_BI1>)
877 __glibcxx_function_requires(_Mutable_BidirectionalIteratorConcept<_BI2>)
878 __glibcxx_function_requires(_OutputIteratorConcept<_BI2,
880 __glibcxx_requires_can_decrement_range(__first, __last, __result);
882 return std::__copy_move_backward_a<true>(std::__miter_base(__first),
883 std::__miter_base(__last),
887#define _GLIBCXX_MOVE_BACKWARD3(_Tp, _Up, _Vp) std::move_backward(_Tp, _Up, _Vp)
889#define _GLIBCXX_MOVE_BACKWARD3(_Tp, _Up, _Vp) std::copy_backward(_Tp, _Up, _Vp)
892#pragma GCC diagnostic push
893#pragma GCC diagnostic ignored "-Wc++17-extensions"
894 template<
typename _ForwardIterator,
typename _Tp>
897 __fill_a1(_ForwardIterator __first, _ForwardIterator __last,
900#pragma GCC diagnostic push
901#pragma GCC diagnostic ignored "-Wlong-long"
906 const bool __load_outside_loop =
907#if __has_builtin(__is_trivially_constructible) \
908 && __has_builtin(__is_trivially_assignable)
909 __is_trivially_constructible(_Tp,
const _Tp&)
910 && __is_trivially_assignable(__decltype(*__first),
const _Tp&)
912 __is_trivially_copyable(_Tp)
913 && __is_same(_Tp, __typeof__(*__first))
915 &&
sizeof(_Tp) <=
sizeof(
long long);
916#pragma GCC diagnostic pop
920 typedef typename __gnu_cxx::__conditional_type<__load_outside_loop,
922 const _Tp&>::__type _Up;
924 for (; __first != __last; ++__first)
927#pragma GCC diagnostic pop
930 template<
typename _Up,
typename _Tp>
933 __gnu_cxx::__enable_if<__is_byte<_Up>::__value
934 && (__are_same<_Up, _Tp>::__value
935 || __memcpyable_integer<_Tp>::__width),
937 __fill_a1(_Up* __first, _Up* __last,
const _Tp& __x)
941 const _Up __val = __x;
942#if __cpp_lib_is_constant_evaluated
943 if (std::is_constant_evaluated())
945 for (; __first != __last; ++__first)
950 if (
const size_t __len = __last - __first)
951 __builtin_memset(__first,
static_cast<unsigned char>(__val), __len);
954 template<
typename _Ite,
typename _Cont,
typename _Tp>
955 __attribute__((__always_inline__))
958 __fill_a1(::__gnu_cxx::__normal_iterator<_Ite, _Cont> __first,
959 ::__gnu_cxx::__normal_iterator<_Ite, _Cont> __last,
961 { std::__fill_a1(__first.base(), __last.base(), __value); }
963 template<
typename _Tp,
typename _VTp>
965 __fill_a1(
const _GLIBCXX_STD_C::_Deque_iterator<_Tp, _Tp&, _Tp*>&,
966 const _GLIBCXX_STD_C::_Deque_iterator<_Tp, _Tp&, _Tp*>&,
971 __fill_a1(_GLIBCXX_STD_C::_Bit_iterator, _GLIBCXX_STD_C::_Bit_iterator,
974 template<
typename _FIte,
typename _Tp>
975 __attribute__((__always_inline__))
978 __fill_a(_FIte __first, _FIte __last,
const _Tp& __value)
979 { std::__fill_a1(__first, __last, __value); }
981 template<
typename _Ite,
typename _Seq,
typename _Cat,
typename _Tp>
984 __fill_a(const ::__gnu_debug::_Safe_iterator<_Ite, _Seq, _Cat>&,
985 const ::__gnu_debug::_Safe_iterator<_Ite, _Seq, _Cat>&,
1000 template<
typename _ForwardIterator,
typename _Tp>
1001 __attribute__((__always_inline__))
1002 _GLIBCXX20_CONSTEXPR
1004 fill(_ForwardIterator __first, _ForwardIterator __last,
const _Tp& __value)
1007 __glibcxx_function_requires(_Mutable_ForwardIteratorConcept<
1009 __glibcxx_requires_valid_range(__first, __last);
1011 std::__fill_a(__first, __last, __value);
1014#pragma GCC diagnostic push
1015#pragma GCC diagnostic ignored "-Wlong-long"
1017 inline _GLIBCXX_CONSTEXPR
int
1018 __size_to_integer(
int __n) {
return __n; }
1019 inline _GLIBCXX_CONSTEXPR
unsigned
1020 __size_to_integer(
unsigned __n) {
return __n; }
1021 inline _GLIBCXX_CONSTEXPR
long
1022 __size_to_integer(
long __n) {
return __n; }
1023 inline _GLIBCXX_CONSTEXPR
unsigned long
1024 __size_to_integer(
unsigned long __n) {
return __n; }
1025 inline _GLIBCXX_CONSTEXPR
long long
1026 __size_to_integer(
long long __n) {
return __n; }
1027 inline _GLIBCXX_CONSTEXPR
unsigned long long
1028 __size_to_integer(
unsigned long long __n) {
return __n; }
1030#if defined(__GLIBCXX_TYPE_INT_N_0)
1031 __extension__
inline _GLIBCXX_CONSTEXPR __GLIBCXX_TYPE_INT_N_0
1032 __size_to_integer(__GLIBCXX_TYPE_INT_N_0 __n) {
return __n; }
1033 __extension__
inline _GLIBCXX_CONSTEXPR
unsigned __GLIBCXX_TYPE_INT_N_0
1034 __size_to_integer(
unsigned __GLIBCXX_TYPE_INT_N_0 __n) {
return __n; }
1036#if defined(__GLIBCXX_TYPE_INT_N_1)
1037 __extension__
inline _GLIBCXX_CONSTEXPR __GLIBCXX_TYPE_INT_N_1
1038 __size_to_integer(__GLIBCXX_TYPE_INT_N_1 __n) {
return __n; }
1039 __extension__
inline _GLIBCXX_CONSTEXPR
unsigned __GLIBCXX_TYPE_INT_N_1
1040 __size_to_integer(
unsigned __GLIBCXX_TYPE_INT_N_1 __n) {
return __n; }
1042#if defined(__GLIBCXX_TYPE_INT_N_2)
1043 __extension__
inline _GLIBCXX_CONSTEXPR __GLIBCXX_TYPE_INT_N_2
1044 __size_to_integer(__GLIBCXX_TYPE_INT_N_2 __n) {
return __n; }
1045 __extension__
inline _GLIBCXX_CONSTEXPR
unsigned __GLIBCXX_TYPE_INT_N_2
1046 __size_to_integer(
unsigned __GLIBCXX_TYPE_INT_N_2 __n) {
return __n; }
1048#if defined(__GLIBCXX_TYPE_INT_N_3)
1049 __extension__
inline _GLIBCXX_CONSTEXPR __GLIBCXX_TYPE_INT_N_3
1050 __size_to_integer(__GLIBCXX_TYPE_INT_N_3 __n) {
return __n; }
1051 __extension__
inline _GLIBCXX_CONSTEXPR
unsigned __GLIBCXX_TYPE_INT_N_3
1052 __size_to_integer(
unsigned __GLIBCXX_TYPE_INT_N_3 __n) {
return __n; }
1055#if defined(__STRICT_ANSI__) && defined(__SIZEOF_INT128__)
1056 __extension__
inline _GLIBCXX_CONSTEXPR __int128
1057 __size_to_integer(__int128 __n) {
return __n; }
1058 __extension__
inline _GLIBCXX_CONSTEXPR
unsigned __int128
1059 __size_to_integer(
unsigned __int128 __n) {
return __n; }
1062 inline _GLIBCXX_CONSTEXPR
long long
1063 __size_to_integer(
float __n) {
return (
long long)__n; }
1064 inline _GLIBCXX_CONSTEXPR
long long
1065 __size_to_integer(
double __n) {
return (
long long)__n; }
1066 inline _GLIBCXX_CONSTEXPR
long long
1067 __size_to_integer(
long double __n) {
return (
long long)__n; }
1068#ifdef _GLIBCXX_USE_FLOAT128
1069 __extension__
inline _GLIBCXX_CONSTEXPR
long long
1070 __size_to_integer(__float128 __n) {
return (
long long)__n; }
1072#pragma GCC diagnostic pop
1074#pragma GCC diagnostic push
1075#pragma GCC diagnostic ignored "-Wc++17-extensions"
1076#pragma GCC diagnostic ignored "-Wlong-long"
1077 template<
typename _OutputIterator,
typename _Size,
typename _Tp>
1078 _GLIBCXX20_CONSTEXPR
1079 inline _OutputIterator
1080 __fill_n_a1(_OutputIterator __first, _Size __n,
const _Tp& __value)
1083 const bool __load_outside_loop =
1084#if __has_builtin(__is_trivially_constructible) \
1085 && __has_builtin(__is_trivially_assignable)
1086 __is_trivially_constructible(_Tp,
const _Tp&)
1087 && __is_trivially_assignable(__decltype(*__first),
const _Tp&)
1089 __is_trivially_copyable(_Tp)
1090 && __is_same(_Tp, __typeof__(*__first))
1092 &&
sizeof(_Tp) <=
sizeof(
long long);
1096 typedef typename __gnu_cxx::__conditional_type<__load_outside_loop,
1098 const _Tp&>::__type _Up;
1100 for (; __n > 0; --__n, (void) ++__first)
1104#pragma GCC diagnostic pop
1106 template<
typename _Ite,
typename _Seq,
typename _Cat,
typename _Size,
1108 _GLIBCXX20_CONSTEXPR
1109 ::__gnu_debug::_Safe_iterator<_Ite, _Seq, _Cat>
1110 __fill_n_a(const ::__gnu_debug::_Safe_iterator<_Ite, _Seq, _Cat>& __first,
1111 _Size __n,
const _Tp& __value,
1112 std::input_iterator_tag);
1114 template<
typename _OutputIterator,
typename _Size,
typename _Tp>
1115 __attribute__((__always_inline__))
1116 _GLIBCXX20_CONSTEXPR
1117 inline _OutputIterator
1118 __fill_n_a(_OutputIterator __first, _Size __n,
const _Tp& __value,
1119 std::output_iterator_tag)
1121#if __cplusplus >= 201103L
1124 return __fill_n_a1(__first, __n, __value);
1127 template<
typename _OutputIterator,
typename _Size,
typename _Tp>
1128 __attribute__((__always_inline__))
1129 _GLIBCXX20_CONSTEXPR
1130 inline _OutputIterator
1131 __fill_n_a(_OutputIterator __first, _Size __n,
const _Tp& __value,
1132 std::input_iterator_tag)
1134#if __cplusplus >= 201103L
1137 return __fill_n_a1(__first, __n, __value);
1140 template<
typename _OutputIterator,
typename _Size,
typename _Tp>
1141 __attribute__((__always_inline__))
1142 _GLIBCXX20_CONSTEXPR
1143 inline _OutputIterator
1144 __fill_n_a(_OutputIterator __first, _Size __n,
const _Tp& __value,
1145 std::random_access_iterator_tag)
1147#if __cplusplus >= 201103L
1153 __glibcxx_requires_can_increment(__first, __n);
1155 std::__fill_a(__first, __first + __n, __value);
1156 return __first + __n;
1176 template<
typename _OI,
typename _Size,
typename _Tp>
1177 __attribute__((__always_inline__))
1178 _GLIBCXX20_CONSTEXPR
1180 fill_n(_OI __first, _Size __n,
const _Tp& __value)
1183 __glibcxx_function_requires(_OutputIteratorConcept<_OI, const _Tp&>)
1185 return std::__fill_n_a(__first, std::__size_to_integer(__n), __value,
1189 template<
bool _BoolType>
1192 template<
typename _II1,
typename _II2>
1193 _GLIBCXX20_CONSTEXPR
1195 equal(_II1 __first1, _II1 __last1, _II2 __first2)
1197 for (; __first1 != __last1; ++__first1, (void) ++__first2)
1198 if (!(*__first1 == *__first2))
1205 struct __equal<true>
1207 template<
typename _Tp>
1208 _GLIBCXX20_CONSTEXPR
1210 equal(
const _Tp* __first1,
const _Tp* __last1,
const _Tp* __first2)
1212 if (
const size_t __len = (__last1 - __first1))
1213 return !std::__memcmp(__first1, __first2, __len);
1218 template<
typename _Tp,
typename _Ref,
typename _Ptr,
typename _II>
1219 typename __gnu_cxx::__enable_if<
1220 __is_random_access_iter<_II>::__value,
bool>::__type
1221 __equal_aux1(_GLIBCXX_STD_C::_Deque_iterator<_Tp, _Ref, _Ptr>,
1222 _GLIBCXX_STD_C::_Deque_iterator<_Tp, _Ref, _Ptr>,
1225 template<
typename _Tp1,
typename _Ref1,
typename _Ptr1,
1226 typename _Tp2,
typename _Ref2,
typename _Ptr2>
1228 __equal_aux1(_GLIBCXX_STD_C::_Deque_iterator<_Tp1, _Ref1, _Ptr1>,
1229 _GLIBCXX_STD_C::_Deque_iterator<_Tp1, _Ref1, _Ptr1>,
1230 _GLIBCXX_STD_C::_Deque_iterator<_Tp2, _Ref2, _Ptr2>);
1232 template<
typename _II,
typename _Tp,
typename _Ref,
typename _Ptr>
1233 typename __gnu_cxx::__enable_if<
1234 __is_random_access_iter<_II>::__value,
bool>::__type
1235 __equal_aux1(_II, _II,
1236 _GLIBCXX_STD_C::_Deque_iterator<_Tp, _Ref, _Ptr>);
1238 template<
typename _II1,
typename _II2>
1239 _GLIBCXX20_CONSTEXPR
1241 __equal_aux1(_II1 __first1, _II1 __last1, _II2 __first2)
1244 const bool __simple = ((__is_integer<_ValueType1>::__value
1245#if _GLIBCXX_USE_BUILTIN_TRAIT(__is_pointer)
1246 || __is_pointer(_ValueType1)
1248#if __glibcxx_byte && __glibcxx_type_trait_variable_templates
1250 || is_same_v<_ValueType1, byte>
1252 ) && __memcmpable<_II1, _II2>::__value);
1253 return std::__equal<__simple>::equal(__first1, __last1, __first2);
1256 template<
typename _II1,
typename _II2>
1257 __attribute__((__always_inline__))
1258 _GLIBCXX20_CONSTEXPR
1260 __equal_aux(_II1 __first1, _II1 __last1, _II2 __first2)
1262 return std::__equal_aux1(std::__niter_base(__first1),
1263 std::__niter_base(__last1),
1264 std::__niter_base(__first2));
1267 template<
typename _II1,
typename _Seq1,
typename _Cat1,
typename _II2>
1268 _GLIBCXX20_CONSTEXPR
1270 __equal_aux(const ::__gnu_debug::_Safe_iterator<_II1, _Seq1, _Cat1>&,
1271 const ::__gnu_debug::_Safe_iterator<_II1, _Seq1, _Cat1>&,
1274 template<
typename _II1,
typename _II2,
typename _Seq2,
typename _Cat2>
1275 _GLIBCXX20_CONSTEXPR
1277 __equal_aux(_II1, _II1,
1278 const ::__gnu_debug::_Safe_iterator<_II2, _Seq2, _Cat2>&);
1280 template<
typename _II1,
typename _Seq1,
typename _Cat1,
1281 typename _II2,
typename _Seq2,
typename _Cat2>
1282 _GLIBCXX20_CONSTEXPR
1284 __equal_aux(const ::__gnu_debug::_Safe_iterator<_II1, _Seq1, _Cat1>&,
1285 const ::__gnu_debug::_Safe_iterator<_II1, _Seq1, _Cat1>&,
1286 const ::__gnu_debug::_Safe_iterator<_II2, _Seq2, _Cat2>&);
1288 template<
typename,
typename>
1291 template<
typename _II1,
typename _II2>
1292 _GLIBCXX20_CONSTEXPR
1294 __newlast1(_II1, _II1 __last1, _II2, _II2)
1297 template<
typename _II>
1298 _GLIBCXX20_CONSTEXPR
1300 __cnd2(_II __first, _II __last)
1301 {
return __first != __last; }
1307 template<
typename _RAI1,
typename _RAI2>
1308 _GLIBCXX20_CONSTEXPR
1310 __newlast1(_RAI1 __first1, _RAI1 __last1,
1311 _RAI2 __first2, _RAI2 __last2)
1313 const typename iterator_traits<_RAI1>::difference_type
1314 __diff1 = __last1 - __first1;
1315 const typename iterator_traits<_RAI2>::difference_type
1316 __diff2 = __last2 - __first2;
1317 return __diff2 < __diff1 ? __first1 + __diff2 : __last1;
1320 template<
typename _RAI>
1321 static _GLIBCXX20_CONSTEXPR
bool
1326 template<
typename _II1,
typename _II2,
typename _Compare>
1327 _GLIBCXX20_CONSTEXPR
1329 __lexicographical_compare_impl(_II1 __first1, _II1 __last1,
1330 _II2 __first2, _II2 __last2,
1335 typedef std::__lc_rai<_Category1, _Category2> __rai_type;
1337 __last1 = __rai_type::__newlast1(__first1, __last1, __first2, __last2);
1338 for (; __first1 != __last1 && __rai_type::__cnd2(__first2, __last2);
1339 ++__first1, (void)++__first2)
1341 if (__comp(__first1, __first2))
1343 if (__comp(__first2, __first1))
1346 return __first1 == __last1 && __first2 != __last2;
1349 template<
bool _BoolType>
1350 struct __lexicographical_compare
1352 template<
typename _II1,
typename _II2>
1353 _GLIBCXX20_CONSTEXPR
1355 __lc(_II1 __first1, _II1 __last1, _II2 __first2, _II2 __last2)
1357 using __gnu_cxx::__ops::__iter_less_iter;
1358 return std::__lexicographical_compare_impl(__first1, __last1,
1360 __iter_less_iter());
1363 template<
typename _II1,
typename _II2>
1364 _GLIBCXX20_CONSTEXPR
1366 __3way(_II1 __first1, _II1 __last1, _II2 __first2, _II2 __last2)
1368 while (__first1 != __last1)
1370 if (__first2 == __last2)
1372 if (*__first1 < *__first2)
1374 if (*__first2 < *__first1)
1379 return int(__first2 == __last2) - 1;
1384 struct __lexicographical_compare<true>
1386 template<
typename _Tp,
typename _Up>
1387 _GLIBCXX20_CONSTEXPR
1389 __lc(
const _Tp* __first1,
const _Tp* __last1,
1390 const _Up* __first2,
const _Up* __last2)
1391 {
return __3way(__first1, __last1, __first2, __last2) < 0; }
1393 template<
typename _Tp,
typename _Up>
1394 _GLIBCXX20_CONSTEXPR
1396 __3way(
const _Tp* __first1,
const _Tp* __last1,
1397 const _Up* __first2,
const _Up* __last2)
1399 const size_t __len1 = __last1 - __first1;
1400 const size_t __len2 = __last2 - __first2;
1401 if (
const size_t __len =
std::min(__len1, __len2))
1402 if (
int __result = std::__memcmp(__first1, __first2, __len))
1404 return ptrdiff_t(__len1 - __len2);
1408 template<
typename _II1,
typename _II2>
1409 _GLIBCXX20_CONSTEXPR
1411 __lexicographical_compare_aux1(_II1 __first1, _II1 __last1,
1412 _II2 __first2, _II2 __last2)
1416#if _GLIBCXX_USE_BUILTIN_TRAIT(__is_pointer)
1417 const bool __simple =
1418 (__is_memcmp_ordered_with<_ValueType1, _ValueType2>::__value
1419 && __is_pointer(_II1) && __is_pointer(_II2)
1420#if __cplusplus > 201703L && __glibcxx_concepts
1424 && !is_volatile_v<remove_reference_t<iter_reference_t<_II1>>>
1425 && !is_volatile_v<remove_reference_t<iter_reference_t<_II2>>>
1429 const bool __simple =
false;
1432 return std::__lexicographical_compare<__simple>::__lc(__first1, __last1,
1436 template<
typename _Tp1,
typename _Ref1,
typename _Ptr1,
1439 __lexicographical_compare_aux1(
1440 _GLIBCXX_STD_C::_Deque_iterator<_Tp1, _Ref1, _Ptr1>,
1441 _GLIBCXX_STD_C::_Deque_iterator<_Tp1, _Ref1, _Ptr1>,
1444 template<
typename _Tp1,
1445 typename _Tp2,
typename _Ref2,
typename _Ptr2>
1447 __lexicographical_compare_aux1(_Tp1*, _Tp1*,
1448 _GLIBCXX_STD_C::_Deque_iterator<_Tp2, _Ref2, _Ptr2>,
1449 _GLIBCXX_STD_C::_Deque_iterator<_Tp2, _Ref2, _Ptr2>);
1451 template<
typename _Tp1,
typename _Ref1,
typename _Ptr1,
1452 typename _Tp2,
typename _Ref2,
typename _Ptr2>
1454 __lexicographical_compare_aux1(
1455 _GLIBCXX_STD_C::_Deque_iterator<_Tp1, _Ref1, _Ptr1>,
1456 _GLIBCXX_STD_C::_Deque_iterator<_Tp1, _Ref1, _Ptr1>,
1457 _GLIBCXX_STD_C::_Deque_iterator<_Tp2, _Ref2, _Ptr2>,
1458 _GLIBCXX_STD_C::_Deque_iterator<_Tp2, _Ref2, _Ptr2>);
1460 template<
typename _II1,
typename _II2>
1461 _GLIBCXX20_CONSTEXPR
1463 __lexicographical_compare_aux(_II1 __first1, _II1 __last1,
1464 _II2 __first2, _II2 __last2)
1466 return std::__lexicographical_compare_aux1(std::__niter_base(__first1),
1467 std::__niter_base(__last1),
1468 std::__niter_base(__first2),
1469 std::__niter_base(__last2));
1472 template<
typename _Iter1,
typename _Seq1,
typename _Cat1,
1474 _GLIBCXX20_CONSTEXPR
1476 __lexicographical_compare_aux(
1477 const ::__gnu_debug::_Safe_iterator<_Iter1, _Seq1, _Cat1>&,
1478 const ::__gnu_debug::_Safe_iterator<_Iter1, _Seq1, _Cat1>&,
1481 template<
typename _II1,
1482 typename _Iter2,
typename _Seq2,
typename _Cat2>
1483 _GLIBCXX20_CONSTEXPR
1485 __lexicographical_compare_aux(
1487 const ::__gnu_debug::_Safe_iterator<_Iter2, _Seq2, _Cat2>&,
1488 const ::__gnu_debug::_Safe_iterator<_Iter2, _Seq2, _Cat2>&);
1490 template<
typename _Iter1,
typename _Seq1,
typename _Cat1,
1491 typename _Iter2,
typename _Seq2,
typename _Cat2>
1492 _GLIBCXX20_CONSTEXPR
1494 __lexicographical_compare_aux(
1495 const ::__gnu_debug::_Safe_iterator<_Iter1, _Seq1, _Cat1>&,
1496 const ::__gnu_debug::_Safe_iterator<_Iter1, _Seq1, _Cat1>&,
1497 const ::__gnu_debug::_Safe_iterator<_Iter2, _Seq2, _Cat2>&,
1498 const ::__gnu_debug::_Safe_iterator<_Iter2, _Seq2, _Cat2>&);
1500 template<
typename _ForwardIterator,
typename _Tp,
typename _Compare>
1501 _GLIBCXX20_CONSTEXPR
1503 __lower_bound(_ForwardIterator __first, _ForwardIterator __last,
1504 const _Tp& __val, _Compare __comp)
1513 _DistanceType __half = __len >> 1;
1514 _ForwardIterator __middle = __first;
1516 if (__comp(__middle, __val))
1520 __len = __len - __half - 1;
1539 template<
typename _ForwardIterator,
typename _Tp>
1540 _GLIBCXX_NODISCARD _GLIBCXX20_CONSTEXPR
1541 inline _ForwardIterator
1542 lower_bound(_ForwardIterator __first, _ForwardIterator __last,
1546 __glibcxx_function_requires(_ForwardIteratorConcept<_ForwardIterator>)
1547 __glibcxx_function_requires(_LessThanOpConcept<
1549 __glibcxx_requires_partitioned_lower(__first, __last, __val);
1551 return std::__lower_bound(__first, __last, __val,
1552 __gnu_cxx::__ops::__iter_less_val());
1557 template<
typename _Tp>
1558 inline _GLIBCXX_CONSTEXPR _Tp
1561#if __cplusplus >= 201402L
1564#pragma GCC diagnostic push
1565#pragma GCC diagnostic ignored "-Wlong-long"
1567 return (
sizeof(+__n) * __CHAR_BIT__ - 1)
1568 - (
sizeof(+__n) ==
sizeof(
long long)
1569 ? __builtin_clzll(+__n)
1570 : (
sizeof(+__n) ==
sizeof(long)
1571 ? __builtin_clzl(+__n)
1572 : __builtin_clz(+__n)));
1573#pragma GCC diagnostic pop
1577_GLIBCXX_BEGIN_NAMESPACE_ALGO
1591 template<
typename _II1,
typename _II2>
1592 _GLIBCXX_NODISCARD _GLIBCXX20_CONSTEXPR
1594 equal(_II1 __first1, _II1 __last1, _II2 __first2)
1597 __glibcxx_function_requires(_InputIteratorConcept<_II1>)
1598 __glibcxx_function_requires(_InputIteratorConcept<_II2>)
1599 __glibcxx_function_requires(_EqualOpConcept<
1602 __glibcxx_requires_can_increment_range(__first1, __last1, __first2);
1604 return std::__equal_aux(__first1, __last1, __first2);
1622 template<
typename _IIter1,
typename _IIter2,
typename _BinaryPredicate>
1623 _GLIBCXX_NODISCARD _GLIBCXX20_CONSTEXPR
1625 equal(_IIter1 __first1, _IIter1 __last1,
1626 _IIter2 __first2, _BinaryPredicate __binary_pred)
1629 __glibcxx_function_requires(_InputIteratorConcept<_IIter1>)
1630 __glibcxx_function_requires(_InputIteratorConcept<_IIter2>)
1631 __glibcxx_requires_valid_range(__first1, __last1);
1633 for (; __first1 != __last1; ++__first1, (void)++__first2)
1634 if (!
bool(__binary_pred(*__first1, *__first2)))
1639#if __cplusplus >= 201103L
1640#pragma GCC diagnostic push
1641#pragma GCC diagnostic ignored "-Wc++17-extensions"
1644 template<
typename _II1,
typename _II2>
1645 _GLIBCXX20_CONSTEXPR
1647 __equal4(_II1 __first1, _II1 __last1, _II2 __first2, _II2 __last2)
1649 using _RATag = random_access_iterator_tag;
1650 using _Cat1 =
typename iterator_traits<_II1>::iterator_category;
1651 using _Cat2 =
typename iterator_traits<_II2>::iterator_category;
1652 using _RAIters = __and_<is_same<_Cat1, _RATag>, is_same<_Cat2, _RATag>>;
1653 if constexpr (_RAIters::value)
1655 if ((__last1 - __first1) != (__last2 - __first2))
1657 return _GLIBCXX_STD_A::equal(__first1, __last1, __first2);
1661 for (; __first1 != __last1 && __first2 != __last2;
1662 ++__first1, (void)++__first2)
1663 if (!(*__first1 == *__first2))
1665 return __first1 == __last1 && __first2 == __last2;
1670 template<
typename _II1,
typename _II2,
typename _BinaryPredicate>
1671 _GLIBCXX20_CONSTEXPR
1673 __equal4(_II1 __first1, _II1 __last1, _II2 __first2, _II2 __last2,
1674 _BinaryPredicate __binary_pred)
1680 if constexpr (_RAIters::value)
1682 if ((__last1 - __first1) != (__last2 - __first2))
1684 return _GLIBCXX_STD_A::equal(__first1, __last1, __first2,
1689 for (; __first1 != __last1 && __first2 != __last2;
1690 ++__first1, (void)++__first2)
1691 if (!
bool(__binary_pred(*__first1, *__first2)))
1693 return __first1 == __last1 && __first2 == __last2;
1696#pragma GCC diagnostic pop
1699#ifdef __glibcxx_robust_nonmodifying_seq_ops
1713 template<
typename _II1,
typename _II2>
1714 _GLIBCXX_NODISCARD _GLIBCXX20_CONSTEXPR
1716 equal(_II1 __first1, _II1 __last1, _II2 __first2, _II2 __last2)
1719 __glibcxx_function_requires(_InputIteratorConcept<_II1>)
1720 __glibcxx_function_requires(_InputIteratorConcept<_II2>)
1721 __glibcxx_function_requires(_EqualOpConcept<
1724 __glibcxx_requires_valid_range(__first1, __last1);
1725 __glibcxx_requires_valid_range(__first2, __last2);
1727 return _GLIBCXX_STD_A::__equal4(__first1, __last1, __first2, __last2);
1746 template<
typename _IIter1,
typename _IIter2,
typename _BinaryPredicate>
1747 _GLIBCXX_NODISCARD _GLIBCXX20_CONSTEXPR
1749 equal(_IIter1 __first1, _IIter1 __last1,
1750 _IIter2 __first2, _IIter2 __last2, _BinaryPredicate __binary_pred)
1753 __glibcxx_function_requires(_InputIteratorConcept<_IIter1>)
1754 __glibcxx_function_requires(_InputIteratorConcept<_IIter2>)
1755 __glibcxx_requires_valid_range(__first1, __last1);
1756 __glibcxx_requires_valid_range(__first2, __last2);
1758 return _GLIBCXX_STD_A::__equal4(__first1, __last1, __first2, __last2,
1778 template<
typename _II1,
typename _II2>
1779 _GLIBCXX_NODISCARD _GLIBCXX20_CONSTEXPR
1781 lexicographical_compare(_II1 __first1, _II1 __last1,
1782 _II2 __first2, _II2 __last2)
1784#ifdef _GLIBCXX_CONCEPT_CHECKS
1789 __glibcxx_function_requires(_InputIteratorConcept<_II1>)
1790 __glibcxx_function_requires(_InputIteratorConcept<_II2>)
1791 __glibcxx_function_requires(_LessThanOpConcept<_ValueType1, _ValueType2>)
1792 __glibcxx_function_requires(_LessThanOpConcept<_ValueType2, _ValueType1>)
1793 __glibcxx_requires_valid_range(__first1, __last1);
1794 __glibcxx_requires_valid_range(__first2, __last2);
1796 return std::__lexicographical_compare_aux(__first1, __last1,
1813 template<
typename _II1,
typename _II2,
typename _Compare>
1814 _GLIBCXX_NODISCARD _GLIBCXX20_CONSTEXPR
1816 lexicographical_compare(_II1 __first1, _II1 __last1,
1817 _II2 __first2, _II2 __last2, _Compare __comp)
1820 __glibcxx_function_requires(_InputIteratorConcept<_II1>)
1821 __glibcxx_function_requires(_InputIteratorConcept<_II2>)
1822 __glibcxx_requires_valid_range(__first1, __last1);
1823 __glibcxx_requires_valid_range(__first2, __last2);
1825 return std::__lexicographical_compare_impl
1826 (__first1, __last1, __first2, __last2,
1827 __gnu_cxx::__ops::__iter_comp_iter(__comp));
1830#if __cpp_lib_three_way_comparison
1834 template<
typename _Iter1,
typename _Iter2>
1835 concept __memcmp_ordered_with
1836 = (__is_memcmp_ordered_with<iter_value_t<_Iter1>,
1837 iter_value_t<_Iter2>>::__value)
1838 && contiguous_iterator<_Iter1> && contiguous_iterator<_Iter2>;
1842 template<
typename _Tp>
1844 __min_cmp(_Tp __x, _Tp __y)
1848 decltype(__x <=> __y) _M_cmp;
1850 auto __c = __x <=> __y;
1852 return _Res{__y, __c};
1853 return _Res{__x, __c};
1867 template<
typename _InputIter1,
typename _InputIter2,
typename _Comp>
1868 [[nodiscard]]
constexpr auto
1870 _InputIter1 __last1,
1871 _InputIter2 __first2,
1872 _InputIter2 __last2,
1874 ->
decltype(__comp(*__first1, *__first2))
1877 __glibcxx_function_requires(_InputIteratorConcept<_InputIter1>)
1878 __glibcxx_function_requires(_InputIteratorConcept<_InputIter2>)
1879 __glibcxx_requires_valid_range(__first1, __last1);
1880 __glibcxx_requires_valid_range(__first2, __last2);
1882 using _Cat =
decltype(__comp(*__first1, *__first2));
1883 static_assert(same_as<common_comparison_category_t<_Cat>, _Cat>);
1885 if (!std::__is_constant_evaluated())
1886 if constexpr (same_as<_Comp, __detail::_Synth3way>
1887 || same_as<_Comp, compare_three_way>)
1888 if constexpr (__memcmp_ordered_with<_InputIter1, _InputIter2>)
1890 const auto [__len, __lencmp] = _GLIBCXX_STD_A::
1891 __min_cmp(__last1 - __first1, __last2 - __first2);
1894 const auto __blen = __len *
sizeof(*__first1);
1896 = __builtin_memcmp(&*__first1, &*__first2, __blen) <=> 0;
1903 while (__first1 != __last1)
1905 if (__first2 == __last2)
1906 return strong_ordering::greater;
1907 if (
auto __cmp = __comp(*__first1, *__first2); __cmp != 0)
1912 return (__first2 == __last2) <=>
true;
1915 template<
typename _InputIter1,
typename _InputIter2>
1918 _InputIter1 __last1,
1919 _InputIter2 __first2,
1920 _InputIter2 __last2)
1922 return _GLIBCXX_STD_A::
1923 lexicographical_compare_three_way(__first1, __last1, __first2, __last2,
1924 compare_three_way{});
1928 template<
typename _InputIterator1,
typename _InputIterator2,
1929 typename _BinaryPredicate>
1930 _GLIBCXX20_CONSTEXPR
1932 __mismatch(_InputIterator1 __first1, _InputIterator1 __last1,
1933 _InputIterator2 __first2, _BinaryPredicate __binary_pred)
1935 while (__first1 != __last1 && __binary_pred(__first1, __first2))
1956 template<
typename _InputIterator1,
typename _InputIterator2>
1957 _GLIBCXX_NODISCARD _GLIBCXX20_CONSTEXPR
1959 mismatch(_InputIterator1 __first1, _InputIterator1 __last1,
1960 _InputIterator2 __first2)
1963 __glibcxx_function_requires(_InputIteratorConcept<_InputIterator1>)
1964 __glibcxx_function_requires(_InputIteratorConcept<_InputIterator2>)
1965 __glibcxx_function_requires(_EqualOpConcept<
1968 __glibcxx_requires_valid_range(__first1, __last1);
1970 return _GLIBCXX_STD_A::__mismatch(__first1, __last1, __first2,
1971 __gnu_cxx::__ops::__iter_equal_to_iter());
1990 template<
typename _InputIterator1,
typename _InputIterator2,
1991 typename _BinaryPredicate>
1992 _GLIBCXX_NODISCARD _GLIBCXX20_CONSTEXPR
1994 mismatch(_InputIterator1 __first1, _InputIterator1 __last1,
1995 _InputIterator2 __first2, _BinaryPredicate __binary_pred)
1998 __glibcxx_function_requires(_InputIteratorConcept<_InputIterator1>)
1999 __glibcxx_function_requires(_InputIteratorConcept<_InputIterator2>)
2000 __glibcxx_requires_valid_range(__first1, __last1);
2002 return _GLIBCXX_STD_A::__mismatch(__first1, __last1, __first2,
2003 __gnu_cxx::__ops::__iter_comp_iter(__binary_pred));
2006#if __glibcxx_robust_nonmodifying_seq_ops
2007 template<
typename _InputIterator1,
typename _InputIterator2,
2008 typename _BinaryPredicate>
2009 _GLIBCXX20_CONSTEXPR
2011 __mismatch(_InputIterator1 __first1, _InputIterator1 __last1,
2012 _InputIterator2 __first2, _InputIterator2 __last2,
2013 _BinaryPredicate __binary_pred)
2015 while (__first1 != __last1 && __first2 != __last2
2016 && __binary_pred(__first1, __first2))
2038 template<
typename _InputIterator1,
typename _InputIterator2>
2039 _GLIBCXX_NODISCARD _GLIBCXX20_CONSTEXPR
2041 mismatch(_InputIterator1 __first1, _InputIterator1 __last1,
2042 _InputIterator2 __first2, _InputIterator2 __last2)
2045 __glibcxx_function_requires(_InputIteratorConcept<_InputIterator1>)
2046 __glibcxx_function_requires(_InputIteratorConcept<_InputIterator2>)
2047 __glibcxx_function_requires(_EqualOpConcept<
2050 __glibcxx_requires_valid_range(__first1, __last1);
2051 __glibcxx_requires_valid_range(__first2, __last2);
2053 return _GLIBCXX_STD_A::__mismatch(__first1, __last1, __first2, __last2,
2054 __gnu_cxx::__ops::__iter_equal_to_iter());
2074 template<
typename _InputIterator1,
typename _InputIterator2,
2075 typename _BinaryPredicate>
2076 _GLIBCXX_NODISCARD _GLIBCXX20_CONSTEXPR
2078 mismatch(_InputIterator1 __first1, _InputIterator1 __last1,
2079 _InputIterator2 __first2, _InputIterator2 __last2,
2080 _BinaryPredicate __binary_pred)
2083 __glibcxx_function_requires(_InputIteratorConcept<_InputIterator1>)
2084 __glibcxx_function_requires(_InputIteratorConcept<_InputIterator2>)
2085 __glibcxx_requires_valid_range(__first1, __last1);
2086 __glibcxx_requires_valid_range(__first2, __last2);
2088 return _GLIBCXX_STD_A::__mismatch(__first1, __last1, __first2, __last2,
2089 __gnu_cxx::__ops::__iter_comp_iter(__binary_pred));
2093_GLIBCXX_END_NAMESPACE_ALGO
2096 template<
typename _Iterator,
typename _Predicate>
2097 _GLIBCXX20_CONSTEXPR
2099 __find_if(_Iterator __first, _Iterator __last, _Predicate __pred)
2102 while (__first != __last && !__pred(__first))
2107 template<
typename _InputIterator,
typename _Predicate>
2108 _GLIBCXX20_CONSTEXPR
2110 __count_if(_InputIterator __first, _InputIterator __last, _Predicate __pred)
2113 for (; __first != __last; ++__first)
2114 if (__pred(__first))
2119 template<
typename _ForwardIterator,
typename _Predicate>
2120 _GLIBCXX20_CONSTEXPR
2122 __remove_if(_ForwardIterator __first, _ForwardIterator __last,
2125 __first = std::__find_if(__first, __last, __pred);
2126 if (__first == __last)
2128 _ForwardIterator __result = __first;
2130 for (; __first != __last; ++__first)
2131 if (!__pred(__first))
2133 *__result = _GLIBCXX_MOVE(*__first);
2139 template<
typename _ForwardIterator1,
typename _ForwardIterator2,
2140 typename _BinaryPredicate>
2141 _GLIBCXX20_CONSTEXPR
2143 __search(_ForwardIterator1 __first1, _ForwardIterator1 __last1,
2144 _ForwardIterator2 __first2, _ForwardIterator2 __last2,
2145 _BinaryPredicate __predicate)
2148 if (__first1 == __last1 || __first2 == __last2)
2152 _ForwardIterator2 __p1(__first2);
2153 if (++__p1 == __last2)
2154 return std::__find_if(__first1, __last1,
2155 __gnu_cxx::__ops::__iter_comp_iter(__predicate, __first2));
2158 _ForwardIterator1 __current = __first1;
2163 std::__find_if(__first1, __last1,
2164 __gnu_cxx::__ops::__iter_comp_iter(__predicate, __first2));
2166 if (__first1 == __last1)
2169 _ForwardIterator2 __p = __p1;
2170 __current = __first1;
2171 if (++__current == __last1)
2174 while (__predicate(__current, __p))
2176 if (++__p == __last2)
2178 if (++__current == __last1)
2186#if __cplusplus >= 201103L
2187 template<
typename _ForwardIterator1,
typename _ForwardIterator2,
2188 typename _BinaryPredicate>
2189 _GLIBCXX20_CONSTEXPR
2191 __is_permutation(_ForwardIterator1 __first1, _ForwardIterator1 __last1,
2192 _ForwardIterator2 __first2, _BinaryPredicate __pred)
2196 for (; __first1 != __last1; ++__first1, (void)++__first2)
2197 if (!__pred(__first1, __first2))
2200 if (__first1 == __last1)
2205 _ForwardIterator2 __last2 = __first2;
2207 for (_ForwardIterator1 __scan = __first1; __scan != __last1; ++__scan)
2209 if (__scan != std::__find_if(__first1, __scan,
2210 __gnu_cxx::__ops::__iter_comp_iter(__pred, __scan)))
2214 = std::__count_if(__first2, __last2,
2215 __gnu_cxx::__ops::__iter_comp_iter(__pred, __scan));
2216 if (0 == __matches ||
2217 std::__count_if(__scan, __last1,
2218 __gnu_cxx::__ops::__iter_comp_iter(__pred, __scan))
2237 template<
typename _ForwardIterator1,
typename _ForwardIterator2>
2238 _GLIBCXX20_CONSTEXPR
2240 is_permutation(_ForwardIterator1 __first1, _ForwardIterator1 __last1,
2241 _ForwardIterator2 __first2)
2244 __glibcxx_function_requires(_ForwardIteratorConcept<_ForwardIterator1>)
2245 __glibcxx_function_requires(_ForwardIteratorConcept<_ForwardIterator2>)
2246 __glibcxx_function_requires(_EqualOpConcept<
2249 __glibcxx_requires_valid_range(__first1, __last1);
2251 return std::__is_permutation(__first1, __last1, __first2,
2252 __gnu_cxx::__ops::__iter_equal_to_iter());
2256_GLIBCXX_BEGIN_NAMESPACE_ALGO
2279 template<
typename _ForwardIterator1,
typename _ForwardIterator2,
2280 typename _BinaryPredicate>
2281 _GLIBCXX20_CONSTEXPR
2282 inline _ForwardIterator1
2283 search(_ForwardIterator1 __first1, _ForwardIterator1 __last1,
2284 _ForwardIterator2 __first2, _ForwardIterator2 __last2,
2285 _BinaryPredicate __predicate)
2288 __glibcxx_function_requires(_ForwardIteratorConcept<_ForwardIterator1>)
2289 __glibcxx_function_requires(_ForwardIteratorConcept<_ForwardIterator2>)
2290 __glibcxx_function_requires(_BinaryPredicateConcept<_BinaryPredicate,
2293 __glibcxx_requires_valid_range(__first1, __last1);
2294 __glibcxx_requires_valid_range(__first2, __last2);
2296 return std::__search(__first1, __last1, __first2, __last2,
2297 __gnu_cxx::__ops::__iter_comp_iter(__predicate));
2300_GLIBCXX_END_NAMESPACE_ALGO
2301_GLIBCXX_END_NAMESPACE_VERSION
2307#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.
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.
Provides input iterator semantics for streambufs.
Basis for explicit traits specializations.
Struct holding two objects of arbitrary type.
Random-access iterators support a superset of bidirectional iterator operations.
Traits class for iterators.