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
1154 __glibcxx_requires_can_increment(__first, __d);
1156 _OutputIterator __last = __first + __d;
1157 std::__fill_a(__first, __last, __value);
1178 template<
typename _OI,
typename _Size,
typename _Tp>
1179 __attribute__((__always_inline__))
1180 _GLIBCXX20_CONSTEXPR
1182 fill_n(_OI __first, _Size __n,
const _Tp& __value)
1185 __glibcxx_function_requires(_OutputIteratorConcept<_OI, const _Tp&>)
1187 return std::__fill_n_a(__first, std::__size_to_integer(__n), __value,
1191 template<
bool _BoolType>
1194 template<
typename _II1,
typename _II2>
1195 _GLIBCXX20_CONSTEXPR
1197 equal(_II1 __first1, _II1 __last1, _II2 __first2)
1199 for (; __first1 != __last1; ++__first1, (void) ++__first2)
1200 if (!(*__first1 == *__first2))
1207 struct __equal<true>
1209 template<
typename _Tp>
1210 _GLIBCXX20_CONSTEXPR
1212 equal(
const _Tp* __first1,
const _Tp* __last1,
const _Tp* __first2)
1214 if (
const size_t __len = (__last1 - __first1))
1215 return !std::__memcmp(__first1, __first2, __len);
1220 template<
typename _Tp,
typename _Ref,
typename _Ptr,
typename _II>
1221 typename __gnu_cxx::__enable_if<
1222 __is_random_access_iter<_II>::__value,
bool>::__type
1223 __equal_aux1(_GLIBCXX_STD_C::_Deque_iterator<_Tp, _Ref, _Ptr>,
1224 _GLIBCXX_STD_C::_Deque_iterator<_Tp, _Ref, _Ptr>,
1227 template<
typename _Tp1,
typename _Ref1,
typename _Ptr1,
1228 typename _Tp2,
typename _Ref2,
typename _Ptr2>
1230 __equal_aux1(_GLIBCXX_STD_C::_Deque_iterator<_Tp1, _Ref1, _Ptr1>,
1231 _GLIBCXX_STD_C::_Deque_iterator<_Tp1, _Ref1, _Ptr1>,
1232 _GLIBCXX_STD_C::_Deque_iterator<_Tp2, _Ref2, _Ptr2>);
1234 template<
typename _II,
typename _Tp,
typename _Ref,
typename _Ptr>
1235 typename __gnu_cxx::__enable_if<
1236 __is_random_access_iter<_II>::__value,
bool>::__type
1237 __equal_aux1(_II, _II,
1238 _GLIBCXX_STD_C::_Deque_iterator<_Tp, _Ref, _Ptr>);
1240 template<
typename _II1,
typename _II2>
1241 _GLIBCXX20_CONSTEXPR
1243 __equal_aux1(_II1 __first1, _II1 __last1, _II2 __first2)
1246 const bool __simple = ((__is_integer<_ValueType1>::__value
1247#if _GLIBCXX_USE_BUILTIN_TRAIT(__is_pointer)
1248 || __is_pointer(_ValueType1)
1250#if __glibcxx_byte && __glibcxx_type_trait_variable_templates
1252 || is_same_v<_ValueType1, byte>
1254 ) && __memcmpable<_II1, _II2>::__value);
1255 return std::__equal<__simple>::equal(__first1, __last1, __first2);
1258 template<
typename _II1,
typename _II2>
1259 __attribute__((__always_inline__))
1260 _GLIBCXX20_CONSTEXPR
1262 __equal_aux(_II1 __first1, _II1 __last1, _II2 __first2)
1264 return std::__equal_aux1(std::__niter_base(__first1),
1265 std::__niter_base(__last1),
1266 std::__niter_base(__first2));
1269 template<
typename _II1,
typename _Seq1,
typename _Cat1,
typename _II2>
1270 _GLIBCXX20_CONSTEXPR
1272 __equal_aux(const ::__gnu_debug::_Safe_iterator<_II1, _Seq1, _Cat1>&,
1273 const ::__gnu_debug::_Safe_iterator<_II1, _Seq1, _Cat1>&,
1276 template<
typename _II1,
typename _II2,
typename _Seq2,
typename _Cat2>
1277 _GLIBCXX20_CONSTEXPR
1279 __equal_aux(_II1, _II1,
1280 const ::__gnu_debug::_Safe_iterator<_II2, _Seq2, _Cat2>&);
1282 template<
typename _II1,
typename _Seq1,
typename _Cat1,
1283 typename _II2,
typename _Seq2,
typename _Cat2>
1284 _GLIBCXX20_CONSTEXPR
1286 __equal_aux(const ::__gnu_debug::_Safe_iterator<_II1, _Seq1, _Cat1>&,
1287 const ::__gnu_debug::_Safe_iterator<_II1, _Seq1, _Cat1>&,
1288 const ::__gnu_debug::_Safe_iterator<_II2, _Seq2, _Cat2>&);
1290 template<
typename,
typename>
1293 template<
typename _II1,
typename _II2>
1294 _GLIBCXX20_CONSTEXPR
1296 __newlast1(_II1, _II1 __last1, _II2, _II2)
1299 template<
typename _II>
1300 _GLIBCXX20_CONSTEXPR
1302 __cnd2(_II __first, _II __last)
1303 {
return __first != __last; }
1309 template<
typename _RAI1,
typename _RAI2>
1310 _GLIBCXX20_CONSTEXPR
1312 __newlast1(_RAI1 __first1, _RAI1 __last1,
1313 _RAI2 __first2, _RAI2 __last2)
1315 typedef typename iterator_traits<_RAI1>::difference_type _Diff1;
1316 typedef typename iterator_traits<_RAI2>::difference_type _Diff2;
1317 const _Diff1 __diff1 = __last1 - __first1;
1318 const _Diff2 __diff2 = __last2 - __first2;
1319 return __diff2 < __diff1 ? __first1 + _Diff1(__diff2) : __last1;
1322 template<
typename _RAI>
1323 static _GLIBCXX20_CONSTEXPR
bool
1328 template<
typename _II1,
typename _II2,
typename _Compare>
1329 _GLIBCXX20_CONSTEXPR
1331 __lexicographical_compare_impl(_II1 __first1, _II1 __last1,
1332 _II2 __first2, _II2 __last2,
1337 typedef std::__lc_rai<_Category1, _Category2> __rai_type;
1339 __last1 = __rai_type::__newlast1(__first1, __last1, __first2, __last2);
1340 for (; __first1 != __last1 && __rai_type::__cnd2(__first2, __last2);
1341 ++__first1, (void)++__first2)
1343 if (__comp(*__first1, *__first2))
1345 if (__comp(*__first2, *__first1))
1348 return __first1 == __last1 && __first2 != __last2;
1351 template<
bool _BoolType>
1352 struct __lexicographical_compare
1354 template<
typename _II1,
typename _II2>
1355 _GLIBCXX20_CONSTEXPR
1357 __lc(_II1 __first1, _II1 __last1, _II2 __first2, _II2 __last2)
1359 using __gnu_cxx::__ops::less;
1360 return std::__lexicographical_compare_impl(__first1, __last1,
1365 template<
typename _II1,
typename _II2>
1366 _GLIBCXX20_CONSTEXPR
1368 __3way(_II1 __first1, _II1 __last1, _II2 __first2, _II2 __last2)
1370 while (__first1 != __last1)
1372 if (__first2 == __last2)
1374 if (*__first1 < *__first2)
1376 if (*__first2 < *__first1)
1381 return int(__first2 == __last2) - 1;
1386 struct __lexicographical_compare<true>
1388 template<
typename _Tp,
typename _Up>
1389 _GLIBCXX20_CONSTEXPR
1391 __lc(
const _Tp* __first1,
const _Tp* __last1,
1392 const _Up* __first2,
const _Up* __last2)
1393 {
return __3way(__first1, __last1, __first2, __last2) < 0; }
1395 template<
typename _Tp,
typename _Up>
1396 _GLIBCXX20_CONSTEXPR
1398 __3way(
const _Tp* __first1,
const _Tp* __last1,
1399 const _Up* __first2,
const _Up* __last2)
1401 const size_t __len1 = __last1 - __first1;
1402 const size_t __len2 = __last2 - __first2;
1403 if (
const size_t __len =
std::min(__len1, __len2))
1404 if (
int __result = std::__memcmp(__first1, __first2, __len))
1406 return ptrdiff_t(__len1 - __len2);
1410 template<
typename _II1,
typename _II2>
1411 _GLIBCXX20_CONSTEXPR
1413 __lexicographical_compare_aux1(_II1 __first1, _II1 __last1,
1414 _II2 __first2, _II2 __last2)
1418#if _GLIBCXX_USE_BUILTIN_TRAIT(__is_pointer)
1419 const bool __simple =
1420 (__is_memcmp_ordered_with<_ValueType1, _ValueType2>::__value
1421 && __is_pointer(_II1) && __is_pointer(_II2)
1422#if __cplusplus > 201703L && __glibcxx_concepts
1426 && !is_volatile_v<remove_reference_t<iter_reference_t<_II1>>>
1427 && !is_volatile_v<remove_reference_t<iter_reference_t<_II2>>>
1431 const bool __simple =
false;
1434 return std::__lexicographical_compare<__simple>::__lc(__first1, __last1,
1438 template<
typename _Tp1,
typename _Ref1,
typename _Ptr1,
1441 __lexicographical_compare_aux1(
1442 _GLIBCXX_STD_C::_Deque_iterator<_Tp1, _Ref1, _Ptr1>,
1443 _GLIBCXX_STD_C::_Deque_iterator<_Tp1, _Ref1, _Ptr1>,
1446 template<
typename _Tp1,
1447 typename _Tp2,
typename _Ref2,
typename _Ptr2>
1449 __lexicographical_compare_aux1(_Tp1*, _Tp1*,
1450 _GLIBCXX_STD_C::_Deque_iterator<_Tp2, _Ref2, _Ptr2>,
1451 _GLIBCXX_STD_C::_Deque_iterator<_Tp2, _Ref2, _Ptr2>);
1453 template<
typename _Tp1,
typename _Ref1,
typename _Ptr1,
1454 typename _Tp2,
typename _Ref2,
typename _Ptr2>
1456 __lexicographical_compare_aux1(
1457 _GLIBCXX_STD_C::_Deque_iterator<_Tp1, _Ref1, _Ptr1>,
1458 _GLIBCXX_STD_C::_Deque_iterator<_Tp1, _Ref1, _Ptr1>,
1459 _GLIBCXX_STD_C::_Deque_iterator<_Tp2, _Ref2, _Ptr2>,
1460 _GLIBCXX_STD_C::_Deque_iterator<_Tp2, _Ref2, _Ptr2>);
1462 template<
typename _II1,
typename _II2>
1463 _GLIBCXX20_CONSTEXPR
1465 __lexicographical_compare_aux(_II1 __first1, _II1 __last1,
1466 _II2 __first2, _II2 __last2)
1468 return std::__lexicographical_compare_aux1(std::__niter_base(__first1),
1469 std::__niter_base(__last1),
1470 std::__niter_base(__first2),
1471 std::__niter_base(__last2));
1474 template<
typename _Iter1,
typename _Seq1,
typename _Cat1,
1476 _GLIBCXX20_CONSTEXPR
1478 __lexicographical_compare_aux(
1479 const ::__gnu_debug::_Safe_iterator<_Iter1, _Seq1, _Cat1>&,
1480 const ::__gnu_debug::_Safe_iterator<_Iter1, _Seq1, _Cat1>&,
1483 template<
typename _II1,
1484 typename _Iter2,
typename _Seq2,
typename _Cat2>
1485 _GLIBCXX20_CONSTEXPR
1487 __lexicographical_compare_aux(
1489 const ::__gnu_debug::_Safe_iterator<_Iter2, _Seq2, _Cat2>&,
1490 const ::__gnu_debug::_Safe_iterator<_Iter2, _Seq2, _Cat2>&);
1492 template<
typename _Iter1,
typename _Seq1,
typename _Cat1,
1493 typename _Iter2,
typename _Seq2,
typename _Cat2>
1494 _GLIBCXX20_CONSTEXPR
1496 __lexicographical_compare_aux(
1497 const ::__gnu_debug::_Safe_iterator<_Iter1, _Seq1, _Cat1>&,
1498 const ::__gnu_debug::_Safe_iterator<_Iter1, _Seq1, _Cat1>&,
1499 const ::__gnu_debug::_Safe_iterator<_Iter2, _Seq2, _Cat2>&,
1500 const ::__gnu_debug::_Safe_iterator<_Iter2, _Seq2, _Cat2>&);
1502 template<
typename _ForwardIterator,
typename _Tp,
typename _Compare>
1503 _GLIBCXX20_CONSTEXPR
1505 __lower_bound(_ForwardIterator __first, _ForwardIterator __last,
1506 const _Tp& __val, _Compare __comp)
1515 _DistanceType __half = __len >> 1;
1516 _ForwardIterator __middle = __first;
1518 if (__comp(*__middle, __val))
1522 __len = __len - __half - 1;
1541 template<
typename _ForwardIterator,
typename _Tp>
1542 _GLIBCXX_NODISCARD _GLIBCXX20_CONSTEXPR
1543 inline _ForwardIterator
1544 lower_bound(_ForwardIterator __first, _ForwardIterator __last,
1548 __glibcxx_function_requires(_ForwardIteratorConcept<_ForwardIterator>)
1549 __glibcxx_function_requires(_LessThanOpConcept<
1551 __glibcxx_requires_partitioned_lower(__first, __last, __val);
1553 return std::__lower_bound(__first, __last, __val,
1554 __gnu_cxx::__ops::less());
1559 template<
typename _Tp>
1560 inline _GLIBCXX_CONSTEXPR _Tp
1563#if __cplusplus >= 201402L
1566#pragma GCC diagnostic push
1567#pragma GCC diagnostic ignored "-Wlong-long"
1569 return (
sizeof(+__n) * __CHAR_BIT__ - 1)
1570 - (
sizeof(+__n) ==
sizeof(
long long)
1571 ? __builtin_clzll(+__n)
1572 : (
sizeof(+__n) ==
sizeof(long)
1573 ? __builtin_clzl(+__n)
1574 : __builtin_clz(+__n)));
1575#pragma GCC diagnostic pop
1579_GLIBCXX_BEGIN_NAMESPACE_ALGO
1593 template<
typename _II1,
typename _II2>
1594 _GLIBCXX_NODISCARD _GLIBCXX20_CONSTEXPR
1596 equal(_II1 __first1, _II1 __last1, _II2 __first2)
1599 __glibcxx_function_requires(_InputIteratorConcept<_II1>)
1600 __glibcxx_function_requires(_InputIteratorConcept<_II2>)
1601 __glibcxx_function_requires(_EqualOpConcept<
1604 __glibcxx_requires_can_increment_range(__first1, __last1, __first2);
1606 return std::__equal_aux(__first1, __last1, __first2);
1624 template<
typename _IIter1,
typename _IIter2,
typename _BinaryPredicate>
1625 _GLIBCXX_NODISCARD _GLIBCXX20_CONSTEXPR
1627 equal(_IIter1 __first1, _IIter1 __last1,
1628 _IIter2 __first2, _BinaryPredicate __binary_pred)
1631 __glibcxx_function_requires(_InputIteratorConcept<_IIter1>)
1632 __glibcxx_function_requires(_InputIteratorConcept<_IIter2>)
1633 __glibcxx_requires_valid_range(__first1, __last1);
1635 for (; __first1 != __last1; ++__first1, (void)++__first2)
1636 if (!
bool(__binary_pred(*__first1, *__first2)))
1641#if __cplusplus >= 201103L
1642#pragma GCC diagnostic push
1643#pragma GCC diagnostic ignored "-Wc++17-extensions"
1646 template<
typename _II1,
typename _II2>
1647 _GLIBCXX20_CONSTEXPR
1649 __equal4(_II1 __first1, _II1 __last1, _II2 __first2, _II2 __last2)
1651 using _RATag = random_access_iterator_tag;
1652 using _Cat1 =
typename iterator_traits<_II1>::iterator_category;
1653 using _Cat2 =
typename iterator_traits<_II2>::iterator_category;
1654 using _RAIters = __and_<is_same<_Cat1, _RATag>, is_same<_Cat2, _RATag>>;
1655 if constexpr (_RAIters::value)
1657 if ((__last1 - __first1) != (__last2 - __first2))
1659 return _GLIBCXX_STD_A::equal(__first1, __last1, __first2);
1663 for (; __first1 != __last1 && __first2 != __last2;
1664 ++__first1, (void)++__first2)
1665 if (!(*__first1 == *__first2))
1667 return __first1 == __last1 && __first2 == __last2;
1672 template<
typename _II1,
typename _II2,
typename _BinaryPredicate>
1673 _GLIBCXX20_CONSTEXPR
1675 __equal4(_II1 __first1, _II1 __last1, _II2 __first2, _II2 __last2,
1676 _BinaryPredicate __binary_pred)
1682 if constexpr (_RAIters::value)
1684 if ((__last1 - __first1) != (__last2 - __first2))
1686 return _GLIBCXX_STD_A::equal(__first1, __last1, __first2,
1691 for (; __first1 != __last1 && __first2 != __last2;
1692 ++__first1, (void)++__first2)
1693 if (!
bool(__binary_pred(*__first1, *__first2)))
1695 return __first1 == __last1 && __first2 == __last2;
1698#pragma GCC diagnostic pop
1701#ifdef __glibcxx_robust_nonmodifying_seq_ops
1715 template<
typename _II1,
typename _II2>
1716 _GLIBCXX_NODISCARD _GLIBCXX20_CONSTEXPR
1718 equal(_II1 __first1, _II1 __last1, _II2 __first2, _II2 __last2)
1721 __glibcxx_function_requires(_InputIteratorConcept<_II1>)
1722 __glibcxx_function_requires(_InputIteratorConcept<_II2>)
1723 __glibcxx_function_requires(_EqualOpConcept<
1726 __glibcxx_requires_valid_range(__first1, __last1);
1727 __glibcxx_requires_valid_range(__first2, __last2);
1729 return _GLIBCXX_STD_A::__equal4(__first1, __last1, __first2, __last2);
1748 template<
typename _IIter1,
typename _IIter2,
typename _BinaryPredicate>
1749 _GLIBCXX_NODISCARD _GLIBCXX20_CONSTEXPR
1751 equal(_IIter1 __first1, _IIter1 __last1,
1752 _IIter2 __first2, _IIter2 __last2, _BinaryPredicate __binary_pred)
1755 __glibcxx_function_requires(_InputIteratorConcept<_IIter1>)
1756 __glibcxx_function_requires(_InputIteratorConcept<_IIter2>)
1757 __glibcxx_requires_valid_range(__first1, __last1);
1758 __glibcxx_requires_valid_range(__first2, __last2);
1760 return _GLIBCXX_STD_A::__equal4(__first1, __last1, __first2, __last2,
1780 template<
typename _II1,
typename _II2>
1781 _GLIBCXX_NODISCARD _GLIBCXX20_CONSTEXPR
1783 lexicographical_compare(_II1 __first1, _II1 __last1,
1784 _II2 __first2, _II2 __last2)
1786#ifdef _GLIBCXX_CONCEPT_CHECKS
1791 __glibcxx_function_requires(_InputIteratorConcept<_II1>)
1792 __glibcxx_function_requires(_InputIteratorConcept<_II2>)
1793 __glibcxx_function_requires(_LessThanOpConcept<_ValueType1, _ValueType2>)
1794 __glibcxx_function_requires(_LessThanOpConcept<_ValueType2, _ValueType1>)
1795 __glibcxx_requires_valid_range(__first1, __last1);
1796 __glibcxx_requires_valid_range(__first2, __last2);
1798 return std::__lexicographical_compare_aux(__first1, __last1,
1815 template<
typename _II1,
typename _II2,
typename _Compare>
1816 _GLIBCXX_NODISCARD _GLIBCXX20_CONSTEXPR
1818 lexicographical_compare(_II1 __first1, _II1 __last1,
1819 _II2 __first2, _II2 __last2, _Compare __comp)
1822 __glibcxx_function_requires(_InputIteratorConcept<_II1>)
1823 __glibcxx_function_requires(_InputIteratorConcept<_II2>)
1824 __glibcxx_requires_valid_range(__first1, __last1);
1825 __glibcxx_requires_valid_range(__first2, __last2);
1827 return std::__lexicographical_compare_impl
1828 (__first1, __last1, __first2, __last2, __comp);
1831#if __cpp_lib_three_way_comparison
1835 template<
typename _Iter1,
typename _Iter2>
1836 concept __memcmp_ordered_with
1837 = (__is_memcmp_ordered_with<iter_value_t<_Iter1>,
1838 iter_value_t<_Iter2>>::__value)
1839 && contiguous_iterator<_Iter1> && contiguous_iterator<_Iter2>;
1843 template<
typename _Tp>
1845 __min_cmp(_Tp __x, _Tp __y)
1849 decltype(__x <=> __y) _M_cmp;
1851 auto __c = __x <=> __y;
1853 return _Res{__y, __c};
1854 return _Res{__x, __c};
1868 template<
typename _InputIter1,
typename _InputIter2,
typename _Comp>
1869 [[nodiscard]]
constexpr auto
1871 _InputIter1 __last1,
1872 _InputIter2 __first2,
1873 _InputIter2 __last2,
1875 ->
decltype(__comp(*__first1, *__first2))
1878 __glibcxx_function_requires(_InputIteratorConcept<_InputIter1>)
1879 __glibcxx_function_requires(_InputIteratorConcept<_InputIter2>)
1880 __glibcxx_requires_valid_range(__first1, __last1);
1881 __glibcxx_requires_valid_range(__first2, __last2);
1883 using _Cat =
decltype(__comp(*__first1, *__first2));
1884 static_assert(same_as<common_comparison_category_t<_Cat>, _Cat>);
1886 if (!std::__is_constant_evaluated())
1887 if constexpr (same_as<_Comp, __detail::_Synth3way>
1888 || same_as<_Comp, compare_three_way>)
1889 if constexpr (__memcmp_ordered_with<_InputIter1, _InputIter2>)
1891 const auto [__len, __lencmp] = _GLIBCXX_STD_A::
1892 __min_cmp(__last1 - __first1, __last2 - __first2);
1895 const auto __blen = __len *
sizeof(*__first1);
1897 = __builtin_memcmp(&*__first1, &*__first2, __blen) <=> 0;
1904 while (__first1 != __last1)
1906 if (__first2 == __last2)
1907 return strong_ordering::greater;
1908 if (
auto __cmp = __comp(*__first1, *__first2); __cmp != 0)
1913 return (__first2 == __last2) <=>
true;
1916 template<
typename _InputIter1,
typename _InputIter2>
1919 _InputIter1 __last1,
1920 _InputIter2 __first2,
1921 _InputIter2 __last2)
1923 return _GLIBCXX_STD_A::
1924 lexicographical_compare_three_way(__first1, __last1, __first2, __last2,
1925 compare_three_way{});
1929 template<
typename _InputIterator1,
typename _InputIterator2,
1930 typename _BinaryPredicate>
1931 _GLIBCXX20_CONSTEXPR
1933 __mismatch(_InputIterator1 __first1, _InputIterator1 __last1,
1934 _InputIterator2 __first2, _BinaryPredicate __binary_pred)
1936 while (__first1 != __last1 && __binary_pred(*__first1, *__first2))
1957 template<
typename _InputIterator1,
typename _InputIterator2>
1958 _GLIBCXX_NODISCARD _GLIBCXX20_CONSTEXPR
1960 mismatch(_InputIterator1 __first1, _InputIterator1 __last1,
1961 _InputIterator2 __first2)
1964 __glibcxx_function_requires(_InputIteratorConcept<_InputIterator1>)
1965 __glibcxx_function_requires(_InputIteratorConcept<_InputIterator2>)
1966 __glibcxx_function_requires(_EqualOpConcept<
1969 __glibcxx_requires_valid_range(__first1, __last1);
1971 return _GLIBCXX_STD_A::__mismatch(__first1, __last1, __first2,
1972 __gnu_cxx::__ops::equal_to());
1991 template<
typename _InputIterator1,
typename _InputIterator2,
1992 typename _BinaryPredicate>
1993 _GLIBCXX_NODISCARD _GLIBCXX20_CONSTEXPR
1995 mismatch(_InputIterator1 __first1, _InputIterator1 __last1,
1996 _InputIterator2 __first2, _BinaryPredicate __binary_pred)
1999 __glibcxx_function_requires(_InputIteratorConcept<_InputIterator1>)
2000 __glibcxx_function_requires(_InputIteratorConcept<_InputIterator2>)
2001 __glibcxx_requires_valid_range(__first1, __last1);
2003 return _GLIBCXX_STD_A::__mismatch(__first1, __last1, __first2,
2007#if __glibcxx_robust_nonmodifying_seq_ops
2008 template<
typename _InputIterator1,
typename _InputIterator2,
2009 typename _BinaryPredicate>
2010 _GLIBCXX20_CONSTEXPR
2012 __mismatch(_InputIterator1 __first1, _InputIterator1 __last1,
2013 _InputIterator2 __first2, _InputIterator2 __last2,
2014 _BinaryPredicate __binary_pred)
2016 while (__first1 != __last1 && __first2 != __last2
2017 && __binary_pred(*__first1, *__first2))
2039 template<
typename _InputIterator1,
typename _InputIterator2>
2040 _GLIBCXX_NODISCARD _GLIBCXX20_CONSTEXPR
2042 mismatch(_InputIterator1 __first1, _InputIterator1 __last1,
2043 _InputIterator2 __first2, _InputIterator2 __last2)
2046 __glibcxx_function_requires(_InputIteratorConcept<_InputIterator1>)
2047 __glibcxx_function_requires(_InputIteratorConcept<_InputIterator2>)
2048 __glibcxx_function_requires(_EqualOpConcept<
2051 __glibcxx_requires_valid_range(__first1, __last1);
2052 __glibcxx_requires_valid_range(__first2, __last2);
2054 return _GLIBCXX_STD_A::__mismatch(__first1, __last1, __first2, __last2,
2055 __gnu_cxx::__ops::equal_to());
2075 template<
typename _InputIterator1,
typename _InputIterator2,
2076 typename _BinaryPredicate>
2077 _GLIBCXX_NODISCARD _GLIBCXX20_CONSTEXPR
2079 mismatch(_InputIterator1 __first1, _InputIterator1 __last1,
2080 _InputIterator2 __first2, _InputIterator2 __last2,
2081 _BinaryPredicate __binary_pred)
2084 __glibcxx_function_requires(_InputIteratorConcept<_InputIterator1>)
2085 __glibcxx_function_requires(_InputIteratorConcept<_InputIterator2>)
2086 __glibcxx_requires_valid_range(__first1, __last1);
2087 __glibcxx_requires_valid_range(__first2, __last2);
2089 return _GLIBCXX_STD_A::__mismatch(__first1, __last1, __first2, __last2,
2094_GLIBCXX_END_NAMESPACE_ALGO
2097 template<
typename _Iterator,
typename _Predicate>
2098 _GLIBCXX20_CONSTEXPR
2100 __find_if(_Iterator __first, _Iterator __last, _Predicate __pred)
2103 while (__first != __last && !__pred(*__first))
2108 template<
typename _InputIterator,
typename _Predicate>
2109 _GLIBCXX20_CONSTEXPR
2111 __count_if(_InputIterator __first, _InputIterator __last, _Predicate __pred)
2114 for (; __first != __last; ++__first)
2115 if (__pred(*__first))
2120 template<
typename _ForwardIterator,
typename _Predicate>
2121 _GLIBCXX20_CONSTEXPR
2123 __remove_if(_ForwardIterator __first, _ForwardIterator __last,
2126 __first = std::__find_if(__first, __last, __pred);
2127 if (__first == __last)
2129 _ForwardIterator __result = __first;
2131 for (; __first != __last; ++__first)
2132 if (!__pred(*__first))
2134 *__result = _GLIBCXX_MOVE(*__first);
2140 template<
typename _ForwardIterator1,
typename _ForwardIterator2,
2141 typename _BinaryPredicate>
2142 _GLIBCXX20_CONSTEXPR
2144 __search(_ForwardIterator1 __first1, _ForwardIterator1 __last1,
2145 _ForwardIterator2 __first2, _ForwardIterator2 __last2,
2146 _BinaryPredicate __predicate)
2149 if (__first1 == __last1 || __first2 == __last2)
2152 __decltype(*__first2) __first2_val(*__first2);
2153 __decltype(__gnu_cxx::__ops::bind2nd(__predicate, __first2_val))
2154 __match_first = __gnu_cxx::__ops::bind2nd(__predicate, __first2_val);
2157 _ForwardIterator2 __p1(__first2);
2158 if (++__p1 == __last2)
2159 return std::__find_if(__first1, __last1, __match_first);
2162 _ForwardIterator1 __current = __first1;
2166 __first1 = std::__find_if(__first1, __last1, __match_first);
2168 if (__first1 == __last1)
2171 _ForwardIterator2 __p = __p1;
2172 __current = __first1;
2173 if (++__current == __last1)
2176 while (__predicate(*__current, *__p))
2178 if (++__p == __last2)
2180 if (++__current == __last1)
2189#if __cplusplus >= 201103L
2190 template<
typename _ForwardIterator1,
typename _ForwardIterator2,
2191 typename _BinaryPredicate>
2192 _GLIBCXX20_CONSTEXPR
2194 __is_permutation(_ForwardIterator1 __first1, _ForwardIterator1 __last1,
2195 _ForwardIterator2 __first2, _BinaryPredicate __pred)
2199 for (; __first1 != __last1; ++__first1, (void)++__first2)
2200 if (!__pred(*__first1, *__first2))
2203 if (__first1 == __last1)
2208 _ForwardIterator2 __last2 = __first2;
2210 for (_ForwardIterator1 __scan = __first1; __scan != __last1; ++__scan)
2212 auto&& __scan_val = *__scan;
2213 auto __scaneq = __gnu_cxx::__ops::bind1st(__pred, __scan_val);
2214 if (__scan != std::__find_if(__first1, __scan, __scaneq))
2217 auto __matches = std::__count_if(__first2, __last2, __scaneq);
2219 || std::__count_if(__scan, __last1, __scaneq) != __matches)
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::equal_to());
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, __predicate);
2299_GLIBCXX_END_NAMESPACE_ALGO
2300_GLIBCXX_END_NAMESPACE_VERSION
2306#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.