56#ifndef _STL_ALGOBASE_H
57#define _STL_ALGOBASE_H 1
71#if __cplusplus >= 201103L
74#if __cplusplus >= 201402L
77#if __cplusplus >= 202002L
82namespace std _GLIBCXX_VISIBILITY(default)
84_GLIBCXX_BEGIN_NAMESPACE_VERSION
90 template<
typename _Tp,
typename _Up>
93 __memcmp(
const _Tp* __first1,
const _Up* __first2,
size_t __num)
95#if __cplusplus >= 201103L
96 static_assert(
sizeof(_Tp) ==
sizeof(_Up),
"can be compared with memcmp");
98#ifdef __cpp_lib_is_constant_evaluated
99 if (std::is_constant_evaluated())
101 for(; __num > 0; ++__first1, ++__first2, --__num)
102 if (*__first1 != *__first2)
103 return *__first1 < *__first2 ? -1 : 1;
108 return __builtin_memcmp(__first1, __first2,
sizeof(_Tp) * __num);
111#if __cplusplus < 201103L
115 template<
bool _BoolType>
118 template<
typename _ForwardIterator1,
typename _ForwardIterator2>
120 iter_swap(_ForwardIterator1 __a, _ForwardIterator2 __b)
122 typedef typename iterator_traits<_ForwardIterator1>::value_type
124 _ValueType1 __tmp = *__a;
131 struct __iter_swap<true>
133 template<
typename _ForwardIterator1,
typename _ForwardIterator2>
135 iter_swap(_ForwardIterator1 __a, _ForwardIterator2 __b)
152 template<
typename _ForwardIterator1,
typename _ForwardIterator2>
155 iter_swap(_ForwardIterator1 __a, _ForwardIterator2 __b)
158 __glibcxx_function_requires(_Mutable_ForwardIteratorConcept<
160 __glibcxx_function_requires(_Mutable_ForwardIteratorConcept<
163#if __cplusplus < 201103L
169 __glibcxx_function_requires(_ConvertibleConcept<_ValueType1,
171 __glibcxx_function_requires(_ConvertibleConcept<_ValueType2,
178 std::__iter_swap<__are_same<_ValueType1, _ValueType2>::__value
179 && __are_same<_ValueType1&, _ReferenceType1>::__value
180 && __are_same<_ValueType2&, _ReferenceType2>::__value>::
201 template<
typename _ForwardIterator1,
typename _ForwardIterator2>
204 swap_ranges(_ForwardIterator1 __first1, _ForwardIterator1 __last1,
205 _ForwardIterator2 __first2)
208 __glibcxx_function_requires(_Mutable_ForwardIteratorConcept<
210 __glibcxx_function_requires(_Mutable_ForwardIteratorConcept<
212 __glibcxx_requires_valid_range(__first1, __last1);
214 for (; __first1 != __last1; ++__first1, (void)++__first2)
215 std::iter_swap(__first1, __first2);
230 template<
typename _Tp>
231 _GLIBCXX_NODISCARD _GLIBCXX14_CONSTEXPR
233 min(
const _Tp& __a,
const _Tp& __b)
236 __glibcxx_function_requires(_LessThanComparableConcept<_Tp>)
254 template<
typename _Tp>
255 _GLIBCXX_NODISCARD _GLIBCXX14_CONSTEXPR
257 max(
const _Tp& __a,
const _Tp& __b)
260 __glibcxx_function_requires(_LessThanComparableConcept<_Tp>)
278 template<
typename _Tp,
typename _Compare>
279 _GLIBCXX_NODISCARD _GLIBCXX14_CONSTEXPR
281 min(
const _Tp& __a,
const _Tp& __b, _Compare __comp)
284 if (__comp(__b, __a))
300 template<
typename _Tp,
typename _Compare>
301 _GLIBCXX_NODISCARD _GLIBCXX14_CONSTEXPR
303 max(
const _Tp& __a,
const _Tp& __b, _Compare __comp)
306 if (__comp(__a, __b))
311_GLIBCXX_BEGIN_NAMESPACE_CONTAINER
313 template<
typename _Tp,
typename _Ref,
typename _Ptr>
314 struct _Deque_iterator;
316 struct _Bit_iterator;
318_GLIBCXX_END_NAMESPACE_CONTAINER
323 template<
typename _CharT>
326 template<
typename _CharT,
typename _Traits>
327 class istreambuf_iterator;
329 template<
typename _CharT,
typename _Traits>
330 class ostreambuf_iterator;
332 template<
bool _IsMove,
typename _CharT>
333 typename __gnu_cxx::__enable_if<__is_char<_CharT>::__value,
334 ostreambuf_iterator<_CharT, char_traits<_CharT> > >::__type
335 __copy_move_a2(_CharT*, _CharT*,
336 ostreambuf_iterator<_CharT, char_traits<_CharT> >);
338 template<
bool _IsMove,
typename _CharT>
339 typename __gnu_cxx::__enable_if<__is_char<_CharT>::__value,
340 ostreambuf_iterator<_CharT, char_traits<_CharT> > >::__type
341 __copy_move_a2(
const _CharT*,
const _CharT*,
342 ostreambuf_iterator<_CharT, char_traits<_CharT> >);
344 template<
bool _IsMove,
typename _CharT>
345 typename __gnu_cxx::__enable_if<__is_char<_CharT>::__value,
347 __copy_move_a2(istreambuf_iterator<_CharT, char_traits<_CharT> >,
348 istreambuf_iterator<_CharT, char_traits<_CharT> >, _CharT*);
350 template<
bool _IsMove,
typename _CharT>
351 typename __gnu_cxx::__enable_if<
352 __is_char<_CharT>::__value,
353 _GLIBCXX_STD_C::_Deque_iterator<_CharT, _CharT&, _CharT*> >::__type
355 istreambuf_iterator<_CharT, char_traits<_CharT> >,
356 istreambuf_iterator<_CharT, char_traits<_CharT> >,
357 _GLIBCXX_STD_C::_Deque_iterator<_CharT, _CharT&, _CharT*>);
360#if __cpp_lib_concepts
361 template<
typename _OutIter,
typename _InIter,
typename _Sent = _InIter>
362 concept __memcpyable_iterators
363 = contiguous_iterator<_OutIter> && contiguous_iterator<_InIter>
364 && sized_sentinel_for<_Sent, _InIter>
365 &&
requires (_OutIter __o, _InIter __i) {
371#if __cplusplus < 201103L
376 template<
typename _Iter> __attribute__((__always_inline__))
377 inline void* __ptr_or_null(_Iter) {
return 0; }
378 template<
typename _Tp> __attribute__((__always_inline__))
379 inline void* __ptr_or_null(_Tp* __p) {
return (
void*)__p; }
380# define _GLIBCXX_TO_ADDR(P) std::__ptr_or_null(P)
382 template<
typename _Iter> __attribute__((__always_inline__))
383 inline void __ptr_advance(_Iter&, ptrdiff_t) { }
384 template<
typename _Tp> __attribute__((__always_inline__))
385 inline void __ptr_advance(_Tp*& __p, ptrdiff_t __n) { __p += __n; }
386# define _GLIBCXX_ADVANCE(P, N) std::__ptr_advance(P, N)
390# define _GLIBCXX_TO_ADDR(P) P
391# define _GLIBCXX_ADVANCE(P, N) P += N
394#pragma GCC diagnostic push
395#pragma GCC diagnostic ignored "-Wc++17-extensions"
396 template<
bool _IsMove,
typename _OutIter,
typename _InIter>
397 __attribute__((__always_inline__)) _GLIBCXX20_CONSTEXPR
399 __assign_one(_OutIter& __out, _InIter& __in)
401#if __cplusplus >= 201103L
402 if constexpr (_IsMove)
409 template<
bool _IsMove,
typename _InIter,
typename _Sent,
typename _OutIter>
412 __copy_move_a2(_InIter __first, _Sent __last, _OutIter __result)
414 typedef __decltype(*__first) _InRef;
415 typedef __decltype(*__result) _OutRef;
416 if _GLIBCXX_CONSTEXPR (!__is_trivially_assignable(_OutRef, _InRef))
418 else if (std::__is_constant_evaluated())
420 else if _GLIBCXX_CONSTEXPR (__memcpyable<_OutIter, _InIter>::__value)
423 if (__builtin_expect(__n > 1,
true))
425 __builtin_memmove(_GLIBCXX_TO_ADDR(__result),
426 _GLIBCXX_TO_ADDR(__first),
427 __n *
sizeof(*__first));
428 _GLIBCXX_ADVANCE(__result, __n);
432 std::__assign_one<_IsMove>(__result, __first);
437#if __cpp_lib_concepts
438 else if constexpr (__memcpyable_iterators<_OutIter, _InIter, _Sent>)
440 if (
auto __n = __last - __first; __n > 1) [[likely]]
444 size_t __nbytes = __n *
sizeof(iter_value_t<_InIter>);
449 __builtin_memmove(__dest, __src, __nbytes);
453 std::__assign_one<_IsMove>(__result, __first);
460 for (; __first != __last; ++__result, (void)++__first)
461 std::__assign_one<_IsMove>(__result, __first);
464#pragma GCC diagnostic pop
466 template<
bool _IsMove,
467 typename _Tp,
typename _Ref,
typename _Ptr,
typename _OI>
469 __copy_move_a1(_GLIBCXX_STD_C::_Deque_iterator<_Tp, _Ref, _Ptr>,
470 _GLIBCXX_STD_C::_Deque_iterator<_Tp, _Ref, _Ptr>,
473 template<
bool _IsMove,
474 typename _ITp,
typename _IRef,
typename _IPtr,
typename _OTp>
475 _GLIBCXX_STD_C::_Deque_iterator<_OTp, _OTp&, _OTp*>
476 __copy_move_a1(_GLIBCXX_STD_C::_Deque_iterator<_ITp, _IRef, _IPtr>,
477 _GLIBCXX_STD_C::_Deque_iterator<_ITp, _IRef, _IPtr>,
478 _GLIBCXX_STD_C::_Deque_iterator<_OTp, _OTp&, _OTp*>);
480 template<
bool _IsMove,
typename _II,
typename _Tp>
481 typename __gnu_cxx::__enable_if<
482 __is_random_access_iter<_II>::__value,
483 _GLIBCXX_STD_C::_Deque_iterator<_Tp, _Tp&, _Tp*> >::__type
484 __copy_move_a1(_II, _II, _GLIBCXX_STD_C::_Deque_iterator<_Tp, _Tp&, _Tp*>);
486 template<
bool _IsMove,
typename _II,
typename _OI>
487 __attribute__((__always_inline__))
490 __copy_move_a1(_II __first, _II __last, _OI __result)
491 {
return std::__copy_move_a2<_IsMove>(__first, __last, __result); }
493 template<
bool _IsMove,
typename _II,
typename _OI>
494 __attribute__((__always_inline__))
497 __copy_move_a(_II __first, _II __last, _OI __result)
499 return std::__niter_wrap(__result,
500 std::__copy_move_a1<_IsMove>(std::__niter_base(__first),
501 std::__niter_base(__last),
502 std::__niter_base(__result)));
505 template<
bool _IsMove,
506 typename _Ite,
typename _Seq,
typename _Cat,
typename _OI>
509 __copy_move_a(const ::__gnu_debug::_Safe_iterator<_Ite, _Seq, _Cat>&,
510 const ::__gnu_debug::_Safe_iterator<_Ite, _Seq, _Cat>&,
513 template<
bool _IsMove,
514 typename _II,
typename _Ite,
typename _Seq,
typename _Cat>
516 __gnu_debug::_Safe_iterator<_Ite, _Seq, _Cat>
517 __copy_move_a(_II, _II,
518 const ::__gnu_debug::_Safe_iterator<_Ite, _Seq, _Cat>&);
520 template<
bool _IsMove,
521 typename _IIte,
typename _ISeq,
typename _ICat,
522 typename _OIte,
typename _OSeq,
typename _OCat>
524 ::__gnu_debug::_Safe_iterator<_OIte, _OSeq, _OCat>
525 __copy_move_a(const ::__gnu_debug::_Safe_iterator<_IIte, _ISeq, _ICat>&,
526 const ::__gnu_debug::_Safe_iterator<_IIte, _ISeq, _ICat>&,
527 const ::__gnu_debug::_Safe_iterator<_OIte, _OSeq, _OCat>&);
529#pragma GCC diagnostic push
530#pragma GCC diagnostic ignored "-Wc++17-extensions"
531 template<
typename _InputIterator,
typename _Size,
typename _OutputIterator>
534 __copy_n_a(_InputIterator __first, _Size __n, _OutputIterator __result,
537 typedef __decltype(*__first) _InRef;
538 typedef __decltype(*__result) _OutRef;
539 if _GLIBCXX_CONSTEXPR (!__is_trivially_assignable(_OutRef, _InRef))
541#ifdef __cpp_lib_is_constant_evaluated
542 else if (std::is_constant_evaluated())
545 else if _GLIBCXX_CONSTEXPR (__memcpyable<_OutputIterator,
546 _InputIterator>::__value)
548 if (__builtin_expect(__n > 1,
true))
550 __builtin_memmove(_GLIBCXX_TO_ADDR(__result),
551 _GLIBCXX_TO_ADDR(__first),
552 __n *
sizeof(*__first));
553 _GLIBCXX_ADVANCE(__result, __n);
556 *__result++ = *__first;
559#if __cpp_lib_concepts
560 else if constexpr (__memcpyable_iterators<_OutputIterator,
563 if (__n > 1) [[likely]]
567 size_t __nbytes = __n *
sizeof(iter_value_t<_InputIterator>);
572 __builtin_memmove(__dest, __src, __nbytes);
575 *__result++ = *__first;
584 *__result = *__first;
594#pragma GCC diagnostic pop
597 template<
typename _CharT,
typename _Size>
598 typename __gnu_cxx::__enable_if<
599 __is_char<_CharT>::__value, _CharT*>::__type
601 _Size, _CharT*,
bool);
603 template<
typename _CharT,
typename _Size>
604 typename __gnu_cxx::__enable_if<
605 __is_char<_CharT>::__value,
606 _GLIBCXX_STD_C::_Deque_iterator<_CharT, _CharT&, _CharT*> >::__type
608 _GLIBCXX_STD_C::_Deque_iterator<_CharT, _CharT&, _CharT*>,
629 template<
typename _II,
typename _OI>
632 copy(_II __first, _II __last, _OI __result)
635 __glibcxx_function_requires(_InputIteratorConcept<_II>)
636 __glibcxx_function_requires(_OutputIteratorConcept<_OI,
638 __glibcxx_requires_can_increment_range(__first, __last, __result);
640 return std::__copy_move_a<__is_move_iterator<_II>::__value>
641 (std::__miter_base(__first), std::__miter_base(__last), __result);
644#if __cplusplus >= 201103L
662 template<
typename _II,
typename _OI>
665 move(_II __first, _II __last, _OI __result)
668 __glibcxx_function_requires(_InputIteratorConcept<_II>)
669 __glibcxx_function_requires(_OutputIteratorConcept<_OI,
671 __glibcxx_requires_can_increment_range(__first, __last, __result);
673 return std::__copy_move_a<true>(std::__miter_base(__first),
674 std::__miter_base(__last), __result);
677#define _GLIBCXX_MOVE3(_Tp, _Up, _Vp) std::move(_Tp, _Up, _Vp)
679#define _GLIBCXX_MOVE3(_Tp, _Up, _Vp) std::copy(_Tp, _Up, _Vp)
682#pragma GCC diagnostic push
683#pragma GCC diagnostic ignored "-Wc++17-extensions"
684 template<
bool _IsMove,
typename _BI1,
typename _BI2>
687 __copy_move_backward_a2(_BI1 __first, _BI1 __last, _BI2 __result)
689 typedef __decltype(*__first) _InRef;
690 typedef __decltype(*__result) _OutRef;
691 if _GLIBCXX_CONSTEXPR (!__is_trivially_assignable(_OutRef, _InRef))
693#ifdef __cpp_lib_is_constant_evaluated
694 else if (std::is_constant_evaluated())
697 else if _GLIBCXX_CONSTEXPR (__memcpyable<_BI2, _BI1>::__value)
701 if (__builtin_expect(__n > 1,
true))
703 __builtin_memmove(_GLIBCXX_TO_ADDR(__result),
704 _GLIBCXX_TO_ADDR(__first),
705 __n *
sizeof(*__first));
708 std::__assign_one<_IsMove>(__result, __first);
711#if __cpp_lib_concepts
712 else if constexpr (__memcpyable_iterators<_BI2, _BI1>)
714 if (
auto __n = __last - __first; __n > 1) [[likely]]
722 size_t __nbytes = __n *
sizeof(iter_value_t<_BI1>);
723 __builtin_memmove(__dest, __src, __nbytes);
728 std::__assign_one<_IsMove>(__result, __first);
734 while (__first != __last)
738 std::__assign_one<_IsMove>(__result, __last);
742#pragma GCC diagnostic pop
744#undef _GLIBCXX_TO_ADDR
745#undef _GLIBCXX_ADVANCE
747 template<
bool _IsMove,
typename _BI1,
typename _BI2>
748 __attribute__((__always_inline__))
751 __copy_move_backward_a1(_BI1 __first, _BI1 __last, _BI2 __result)
752 {
return std::__copy_move_backward_a2<_IsMove>(__first, __last, __result); }
754 template<
bool _IsMove,
755 typename _Tp,
typename _Ref,
typename _Ptr,
typename _OI>
757 __copy_move_backward_a1(_GLIBCXX_STD_C::_Deque_iterator<_Tp, _Ref, _Ptr>,
758 _GLIBCXX_STD_C::_Deque_iterator<_Tp, _Ref, _Ptr>,
761 template<
bool _IsMove,
762 typename _ITp,
typename _IRef,
typename _IPtr,
typename _OTp>
763 _GLIBCXX_STD_C::_Deque_iterator<_OTp, _OTp&, _OTp*>
764 __copy_move_backward_a1(
765 _GLIBCXX_STD_C::_Deque_iterator<_ITp, _IRef, _IPtr>,
766 _GLIBCXX_STD_C::_Deque_iterator<_ITp, _IRef, _IPtr>,
767 _GLIBCXX_STD_C::_Deque_iterator<_OTp, _OTp&, _OTp*>);
769 template<
bool _IsMove,
typename _II,
typename _Tp>
770 typename __gnu_cxx::__enable_if<
771 __is_random_access_iter<_II>::__value,
772 _GLIBCXX_STD_C::_Deque_iterator<_Tp, _Tp&, _Tp*> >::__type
773 __copy_move_backward_a1(_II, _II,
774 _GLIBCXX_STD_C::_Deque_iterator<_Tp, _Tp&, _Tp*>);
776 template<
bool _IsMove,
typename _II,
typename _OI>
777 __attribute__((__always_inline__))
780 __copy_move_backward_a(_II __first, _II __last, _OI __result)
782 return std::__niter_wrap(__result,
783 std::__copy_move_backward_a1<_IsMove>
784 (std::__niter_base(__first), std::__niter_base(__last),
785 std::__niter_base(__result)));
788 template<
bool _IsMove,
789 typename _Ite,
typename _Seq,
typename _Cat,
typename _OI>
792 __copy_move_backward_a(
793 const ::__gnu_debug::_Safe_iterator<_Ite, _Seq, _Cat>&,
794 const ::__gnu_debug::_Safe_iterator<_Ite, _Seq, _Cat>&,
797 template<
bool _IsMove,
798 typename _II,
typename _Ite,
typename _Seq,
typename _Cat>
800 __gnu_debug::_Safe_iterator<_Ite, _Seq, _Cat>
801 __copy_move_backward_a(_II, _II,
802 const ::__gnu_debug::_Safe_iterator<_Ite, _Seq, _Cat>&);
804 template<
bool _IsMove,
805 typename _IIte,
typename _ISeq,
typename _ICat,
806 typename _OIte,
typename _OSeq,
typename _OCat>
808 ::__gnu_debug::_Safe_iterator<_OIte, _OSeq, _OCat>
809 __copy_move_backward_a(
810 const ::__gnu_debug::_Safe_iterator<_IIte, _ISeq, _ICat>&,
811 const ::__gnu_debug::_Safe_iterator<_IIte, _ISeq, _ICat>&,
812 const ::__gnu_debug::_Safe_iterator<_OIte, _OSeq, _OCat>&);
832 template<
typename _BI1,
typename _BI2>
833 __attribute__((__always_inline__))
836 copy_backward(_BI1 __first, _BI1 __last, _BI2 __result)
839 __glibcxx_function_requires(_BidirectionalIteratorConcept<_BI1>)
840 __glibcxx_function_requires(_Mutable_BidirectionalIteratorConcept<_BI2>)
841 __glibcxx_function_requires(_OutputIteratorConcept<_BI2,
843 __glibcxx_requires_can_decrement_range(__first, __last, __result);
845 return std::__copy_move_backward_a<__is_move_iterator<_BI1>::__value>
846 (std::__miter_base(__first), std::__miter_base(__last), __result);
849#if __cplusplus >= 201103L
868 template<
typename _BI1,
typename _BI2>
869 __attribute__((__always_inline__))
875 __glibcxx_function_requires(_BidirectionalIteratorConcept<_BI1>)
876 __glibcxx_function_requires(_Mutable_BidirectionalIteratorConcept<_BI2>)
877 __glibcxx_function_requires(_OutputIteratorConcept<_BI2,
879 __glibcxx_requires_can_decrement_range(__first, __last, __result);
881 return std::__copy_move_backward_a<true>(std::__miter_base(__first),
882 std::__miter_base(__last),
886#define _GLIBCXX_MOVE_BACKWARD3(_Tp, _Up, _Vp) std::move_backward(_Tp, _Up, _Vp)
888#define _GLIBCXX_MOVE_BACKWARD3(_Tp, _Up, _Vp) std::copy_backward(_Tp, _Up, _Vp)
891#pragma GCC diagnostic push
892#pragma GCC diagnostic ignored "-Wc++17-extensions"
893 template<
typename _ForwardIterator,
typename _Tp>
896 __fill_a1(_ForwardIterator __first, _ForwardIterator __last,
899#pragma GCC diagnostic push
900#pragma GCC diagnostic ignored "-Wlong-long"
905 const bool __load_outside_loop =
906#if __has_builtin(__is_trivially_constructible) \
907 && __has_builtin(__is_trivially_assignable)
908 __is_trivially_constructible(_Tp,
const _Tp&)
909 && __is_trivially_assignable(__decltype(*__first),
const _Tp&)
911 __is_trivially_copyable(_Tp)
912 && __is_same(_Tp, __typeof__(*__first))
914 &&
sizeof(_Tp) <=
sizeof(
long long);
915#pragma GCC diagnostic pop
919 typedef typename __gnu_cxx::__conditional_type<__load_outside_loop,
921 const _Tp&>::__type _Up;
923 for (; __first != __last; ++__first)
926#pragma GCC diagnostic pop
929 template<
typename _Up,
typename _Tp>
932 __gnu_cxx::__enable_if<__is_byte<_Up>::__value
933 && (__are_same<_Up, _Tp>::__value
934 || __memcpyable_integer<_Tp>::__width),
936 __fill_a1(_Up* __first, _Up* __last,
const _Tp& __x)
940 const _Up __val = __x;
941#if __cpp_lib_is_constant_evaluated
942 if (std::is_constant_evaluated())
944 for (; __first != __last; ++__first)
949 if (
const size_t __len = __last - __first)
950 __builtin_memset(__first,
static_cast<unsigned char>(__val), __len);
953 template<
typename _Ite,
typename _Cont,
typename _Tp>
954 __attribute__((__always_inline__))
957 __fill_a1(::__gnu_cxx::__normal_iterator<_Ite, _Cont> __first,
958 ::__gnu_cxx::__normal_iterator<_Ite, _Cont> __last,
960 { std::__fill_a1(__first.base(), __last.base(), __value); }
962 template<
typename _Tp,
typename _VTp>
964 __fill_a1(
const _GLIBCXX_STD_C::_Deque_iterator<_Tp, _Tp&, _Tp*>&,
965 const _GLIBCXX_STD_C::_Deque_iterator<_Tp, _Tp&, _Tp*>&,
970 __fill_a1(_GLIBCXX_STD_C::_Bit_iterator, _GLIBCXX_STD_C::_Bit_iterator,
973 template<
typename _FIte,
typename _Tp>
974 __attribute__((__always_inline__))
977 __fill_a(_FIte __first, _FIte __last,
const _Tp& __value)
978 { std::__fill_a1(__first, __last, __value); }
980 template<
typename _Ite,
typename _Seq,
typename _Cat,
typename _Tp>
983 __fill_a(const ::__gnu_debug::_Safe_iterator<_Ite, _Seq, _Cat>&,
984 const ::__gnu_debug::_Safe_iterator<_Ite, _Seq, _Cat>&,
999 template<
typename _ForwardIterator,
typename _Tp>
1000 __attribute__((__always_inline__))
1001 _GLIBCXX20_CONSTEXPR
1003 fill(_ForwardIterator __first, _ForwardIterator __last,
const _Tp& __value)
1006 __glibcxx_function_requires(_Mutable_ForwardIteratorConcept<
1008 __glibcxx_requires_valid_range(__first, __last);
1010 std::__fill_a(__first, __last, __value);
1013#pragma GCC diagnostic push
1014#pragma GCC diagnostic ignored "-Wlong-long"
1016 inline _GLIBCXX_CONSTEXPR
int
1017 __size_to_integer(
int __n) {
return __n; }
1018 inline _GLIBCXX_CONSTEXPR
unsigned
1019 __size_to_integer(
unsigned __n) {
return __n; }
1020 inline _GLIBCXX_CONSTEXPR
long
1021 __size_to_integer(
long __n) {
return __n; }
1022 inline _GLIBCXX_CONSTEXPR
unsigned long
1023 __size_to_integer(
unsigned long __n) {
return __n; }
1024 inline _GLIBCXX_CONSTEXPR
long long
1025 __size_to_integer(
long long __n) {
return __n; }
1026 inline _GLIBCXX_CONSTEXPR
unsigned long long
1027 __size_to_integer(
unsigned long long __n) {
return __n; }
1029#if defined(__GLIBCXX_TYPE_INT_N_0)
1030 __extension__
inline _GLIBCXX_CONSTEXPR __GLIBCXX_TYPE_INT_N_0
1031 __size_to_integer(__GLIBCXX_TYPE_INT_N_0 __n) {
return __n; }
1032 __extension__
inline _GLIBCXX_CONSTEXPR
unsigned __GLIBCXX_TYPE_INT_N_0
1033 __size_to_integer(
unsigned __GLIBCXX_TYPE_INT_N_0 __n) {
return __n; }
1035#if defined(__GLIBCXX_TYPE_INT_N_1)
1036 __extension__
inline _GLIBCXX_CONSTEXPR __GLIBCXX_TYPE_INT_N_1
1037 __size_to_integer(__GLIBCXX_TYPE_INT_N_1 __n) {
return __n; }
1038 __extension__
inline _GLIBCXX_CONSTEXPR
unsigned __GLIBCXX_TYPE_INT_N_1
1039 __size_to_integer(
unsigned __GLIBCXX_TYPE_INT_N_1 __n) {
return __n; }
1041#if defined(__GLIBCXX_TYPE_INT_N_2)
1042 __extension__
inline _GLIBCXX_CONSTEXPR __GLIBCXX_TYPE_INT_N_2
1043 __size_to_integer(__GLIBCXX_TYPE_INT_N_2 __n) {
return __n; }
1044 __extension__
inline _GLIBCXX_CONSTEXPR
unsigned __GLIBCXX_TYPE_INT_N_2
1045 __size_to_integer(
unsigned __GLIBCXX_TYPE_INT_N_2 __n) {
return __n; }
1047#if defined(__GLIBCXX_TYPE_INT_N_3)
1048 __extension__
inline _GLIBCXX_CONSTEXPR __GLIBCXX_TYPE_INT_N_3
1049 __size_to_integer(__GLIBCXX_TYPE_INT_N_3 __n) {
return __n; }
1050 __extension__
inline _GLIBCXX_CONSTEXPR
unsigned __GLIBCXX_TYPE_INT_N_3
1051 __size_to_integer(
unsigned __GLIBCXX_TYPE_INT_N_3 __n) {
return __n; }
1054#if defined(__STRICT_ANSI__) && defined(__SIZEOF_INT128__)
1055 __extension__
inline _GLIBCXX_CONSTEXPR __int128
1056 __size_to_integer(__int128 __n) {
return __n; }
1057 __extension__
inline _GLIBCXX_CONSTEXPR
unsigned __int128
1058 __size_to_integer(
unsigned __int128 __n) {
return __n; }
1061 inline _GLIBCXX_CONSTEXPR
long long
1062 __size_to_integer(
float __n) {
return (
long long)__n; }
1063 inline _GLIBCXX_CONSTEXPR
long long
1064 __size_to_integer(
double __n) {
return (
long long)__n; }
1065 inline _GLIBCXX_CONSTEXPR
long long
1066 __size_to_integer(
long double __n) {
return (
long long)__n; }
1067#ifdef _GLIBCXX_USE_FLOAT128
1068 __extension__
inline _GLIBCXX_CONSTEXPR
long long
1069 __size_to_integer(__float128 __n) {
return (
long long)__n; }
1071#pragma GCC diagnostic pop
1073#pragma GCC diagnostic push
1074#pragma GCC diagnostic ignored "-Wc++17-extensions"
1075#pragma GCC diagnostic ignored "-Wlong-long"
1076 template<
typename _OutputIterator,
typename _Size,
typename _Tp>
1077 _GLIBCXX20_CONSTEXPR
1078 inline _OutputIterator
1079 __fill_n_a1(_OutputIterator __first, _Size __n,
const _Tp& __value)
1082 const bool __load_outside_loop =
1083#if __has_builtin(__is_trivially_constructible) \
1084 && __has_builtin(__is_trivially_assignable)
1085 __is_trivially_constructible(_Tp,
const _Tp&)
1086 && __is_trivially_assignable(__decltype(*__first),
const _Tp&)
1088 __is_trivially_copyable(_Tp)
1089 && __is_same(_Tp, __typeof__(*__first))
1091 &&
sizeof(_Tp) <=
sizeof(
long long);
1095 typedef typename __gnu_cxx::__conditional_type<__load_outside_loop,
1097 const _Tp&>::__type _Up;
1099 for (; __n > 0; --__n, (void) ++__first)
1103#pragma GCC diagnostic pop
1105 template<
typename _Ite,
typename _Seq,
typename _Cat,
typename _Size,
1107 _GLIBCXX20_CONSTEXPR
1108 ::__gnu_debug::_Safe_iterator<_Ite, _Seq, _Cat>
1109 __fill_n_a(const ::__gnu_debug::_Safe_iterator<_Ite, _Seq, _Cat>& __first,
1110 _Size __n,
const _Tp& __value,
1111 std::input_iterator_tag);
1113 template<
typename _OutputIterator,
typename _Size,
typename _Tp>
1114 __attribute__((__always_inline__))
1115 _GLIBCXX20_CONSTEXPR
1116 inline _OutputIterator
1117 __fill_n_a(_OutputIterator __first, _Size __n,
const _Tp& __value,
1118 std::output_iterator_tag)
1120#if __cplusplus >= 201103L
1123 return __fill_n_a1(__first, __n, __value);
1126 template<
typename _OutputIterator,
typename _Size,
typename _Tp>
1127 __attribute__((__always_inline__))
1128 _GLIBCXX20_CONSTEXPR
1129 inline _OutputIterator
1130 __fill_n_a(_OutputIterator __first, _Size __n,
const _Tp& __value,
1131 std::input_iterator_tag)
1133#if __cplusplus >= 201103L
1136 return __fill_n_a1(__first, __n, __value);
1139 template<
typename _OutputIterator,
typename _Size,
typename _Tp>
1140 __attribute__((__always_inline__))
1141 _GLIBCXX20_CONSTEXPR
1142 inline _OutputIterator
1143 __fill_n_a(_OutputIterator __first, _Size __n,
const _Tp& __value,
1144 std::random_access_iterator_tag)
1146#if __cplusplus >= 201103L
1153 __glibcxx_requires_can_increment(__first, __d);
1155 _OutputIterator __last = __first + __d;
1156 std::__fill_a(__first, __last, __value);
1177 template<
typename _OI,
typename _Size,
typename _Tp>
1178 __attribute__((__always_inline__))
1179 _GLIBCXX20_CONSTEXPR
1181 fill_n(_OI __first, _Size __n,
const _Tp& __value)
1184 __glibcxx_function_requires(_OutputIteratorConcept<_OI, const _Tp&>)
1186 return std::__fill_n_a(__first, std::__size_to_integer(__n), __value,
1190 template<
bool _BoolType>
1193 template<
typename _II1,
typename _II2>
1194 _GLIBCXX20_CONSTEXPR
1196 equal(_II1 __first1, _II1 __last1, _II2 __first2)
1198 for (; __first1 != __last1; ++__first1, (void) ++__first2)
1199 if (!(*__first1 == *__first2))
1206 struct __equal<true>
1208 template<
typename _Tp>
1209 _GLIBCXX20_CONSTEXPR
1211 equal(
const _Tp* __first1,
const _Tp* __last1,
const _Tp* __first2)
1213 if (
const size_t __len = (__last1 - __first1))
1214 return !std::__memcmp(__first1, __first2, __len);
1219 template<
typename _Tp,
typename _Ref,
typename _Ptr,
typename _II>
1220 typename __gnu_cxx::__enable_if<
1221 __is_random_access_iter<_II>::__value,
bool>::__type
1222 __equal_aux1(_GLIBCXX_STD_C::_Deque_iterator<_Tp, _Ref, _Ptr>,
1223 _GLIBCXX_STD_C::_Deque_iterator<_Tp, _Ref, _Ptr>,
1226 template<
typename _Tp1,
typename _Ref1,
typename _Ptr1,
1227 typename _Tp2,
typename _Ref2,
typename _Ptr2>
1229 __equal_aux1(_GLIBCXX_STD_C::_Deque_iterator<_Tp1, _Ref1, _Ptr1>,
1230 _GLIBCXX_STD_C::_Deque_iterator<_Tp1, _Ref1, _Ptr1>,
1231 _GLIBCXX_STD_C::_Deque_iterator<_Tp2, _Ref2, _Ptr2>);
1233 template<
typename _II,
typename _Tp,
typename _Ref,
typename _Ptr>
1234 typename __gnu_cxx::__enable_if<
1235 __is_random_access_iter<_II>::__value,
bool>::__type
1236 __equal_aux1(_II, _II,
1237 _GLIBCXX_STD_C::_Deque_iterator<_Tp, _Ref, _Ptr>);
1239 template<
typename _II1,
typename _II2>
1240 _GLIBCXX20_CONSTEXPR
1242 __equal_aux1(_II1 __first1, _II1 __last1, _II2 __first2)
1245 const bool __simple = ((__is_integer<_ValueType1>::__value
1246#if _GLIBCXX_USE_BUILTIN_TRAIT(__is_pointer)
1247 || __is_pointer(_ValueType1)
1249#if __glibcxx_byte && __glibcxx_type_trait_variable_templates
1251 || is_same_v<_ValueType1, byte>
1253 ) && __memcmpable<_II1, _II2>::__value);
1254 return std::__equal<__simple>::equal(__first1, __last1, __first2);
1257 template<
typename _II1,
typename _II2>
1258 __attribute__((__always_inline__))
1259 _GLIBCXX20_CONSTEXPR
1261 __equal_aux(_II1 __first1, _II1 __last1, _II2 __first2)
1263 return std::__equal_aux1(std::__niter_base(__first1),
1264 std::__niter_base(__last1),
1265 std::__niter_base(__first2));
1268 template<
typename _II1,
typename _Seq1,
typename _Cat1,
typename _II2>
1269 _GLIBCXX20_CONSTEXPR
1271 __equal_aux(const ::__gnu_debug::_Safe_iterator<_II1, _Seq1, _Cat1>&,
1272 const ::__gnu_debug::_Safe_iterator<_II1, _Seq1, _Cat1>&,
1275 template<
typename _II1,
typename _II2,
typename _Seq2,
typename _Cat2>
1276 _GLIBCXX20_CONSTEXPR
1278 __equal_aux(_II1, _II1,
1279 const ::__gnu_debug::_Safe_iterator<_II2, _Seq2, _Cat2>&);
1281 template<
typename _II1,
typename _Seq1,
typename _Cat1,
1282 typename _II2,
typename _Seq2,
typename _Cat2>
1283 _GLIBCXX20_CONSTEXPR
1285 __equal_aux(const ::__gnu_debug::_Safe_iterator<_II1, _Seq1, _Cat1>&,
1286 const ::__gnu_debug::_Safe_iterator<_II1, _Seq1, _Cat1>&,
1287 const ::__gnu_debug::_Safe_iterator<_II2, _Seq2, _Cat2>&);
1289 template<
typename,
typename>
1292 template<
typename _II1,
typename _II2>
1293 _GLIBCXX20_CONSTEXPR
1295 __newlast1(_II1, _II1 __last1, _II2, _II2)
1298 template<
typename _II>
1299 _GLIBCXX20_CONSTEXPR
1301 __cnd2(_II __first, _II __last)
1302 {
return __first != __last; }
1308 template<
typename _RAI1,
typename _RAI2>
1309 _GLIBCXX20_CONSTEXPR
1311 __newlast1(_RAI1 __first1, _RAI1 __last1,
1312 _RAI2 __first2, _RAI2 __last2)
1314 typedef typename iterator_traits<_RAI1>::difference_type _Diff1;
1315 typedef typename iterator_traits<_RAI2>::difference_type _Diff2;
1316 const _Diff1 __diff1 = __last1 - __first1;
1317 const _Diff2 __diff2 = __last2 - __first2;
1318 return __diff2 < __diff1 ? __first1 + _Diff1(__diff2) : __last1;
1321 template<
typename _RAI>
1322 static _GLIBCXX20_CONSTEXPR
bool
1327 template<
typename _II1,
typename _II2,
typename _Compare>
1328 _GLIBCXX20_CONSTEXPR
1330 __lexicographical_compare_impl(_II1 __first1, _II1 __last1,
1331 _II2 __first2, _II2 __last2,
1336 typedef std::__lc_rai<_Category1, _Category2> __rai_type;
1338 __last1 = __rai_type::__newlast1(__first1, __last1, __first2, __last2);
1339 for (; __first1 != __last1 && __rai_type::__cnd2(__first2, __last2);
1340 ++__first1, (void)++__first2)
1342 if (__comp(*__first1, *__first2))
1344 if (__comp(*__first2, *__first1))
1347 return __first1 == __last1 && __first2 != __last2;
1350 template<
bool _BoolType>
1351 struct __lexicographical_compare
1353 template<
typename _II1,
typename _II2>
1354 _GLIBCXX20_CONSTEXPR
1356 __lc(_II1 __first1, _II1 __last1, _II2 __first2, _II2 __last2)
1358 using __gnu_cxx::__ops::less;
1359 return std::__lexicographical_compare_impl(__first1, __last1,
1364 template<
typename _II1,
typename _II2>
1365 _GLIBCXX20_CONSTEXPR
1367 __3way(_II1 __first1, _II1 __last1, _II2 __first2, _II2 __last2)
1369 while (__first1 != __last1)
1371 if (__first2 == __last2)
1373 if (*__first1 < *__first2)
1375 if (*__first2 < *__first1)
1380 return int(__first2 == __last2) - 1;
1385 struct __lexicographical_compare<true>
1387 template<
typename _Tp,
typename _Up>
1388 _GLIBCXX20_CONSTEXPR
1390 __lc(
const _Tp* __first1,
const _Tp* __last1,
1391 const _Up* __first2,
const _Up* __last2)
1392 {
return __3way(__first1, __last1, __first2, __last2) < 0; }
1394 template<
typename _Tp,
typename _Up>
1395 _GLIBCXX20_CONSTEXPR
1397 __3way(
const _Tp* __first1,
const _Tp* __last1,
1398 const _Up* __first2,
const _Up* __last2)
1400 const size_t __len1 = __last1 - __first1;
1401 const size_t __len2 = __last2 - __first2;
1402 if (
const size_t __len =
std::min(__len1, __len2))
1403 if (
int __result = std::__memcmp(__first1, __first2, __len))
1405 return ptrdiff_t(__len1 - __len2);
1409 template<
typename _II1,
typename _II2>
1410 _GLIBCXX20_CONSTEXPR
1412 __lexicographical_compare_aux1(_II1 __first1, _II1 __last1,
1413 _II2 __first2, _II2 __last2)
1417#if _GLIBCXX_USE_BUILTIN_TRAIT(__is_pointer)
1418 const bool __simple =
1419 (__is_memcmp_ordered_with<_ValueType1, _ValueType2>::__value
1420 && __is_pointer(_II1) && __is_pointer(_II2)
1421#if __cplusplus > 201703L && __glibcxx_concepts
1425 && !is_volatile_v<remove_reference_t<iter_reference_t<_II1>>>
1426 && !is_volatile_v<remove_reference_t<iter_reference_t<_II2>>>
1430 const bool __simple =
false;
1433 return std::__lexicographical_compare<__simple>::__lc(__first1, __last1,
1437 template<
typename _Tp1,
typename _Ref1,
typename _Ptr1,
1440 __lexicographical_compare_aux1(
1441 _GLIBCXX_STD_C::_Deque_iterator<_Tp1, _Ref1, _Ptr1>,
1442 _GLIBCXX_STD_C::_Deque_iterator<_Tp1, _Ref1, _Ptr1>,
1445 template<
typename _Tp1,
1446 typename _Tp2,
typename _Ref2,
typename _Ptr2>
1448 __lexicographical_compare_aux1(_Tp1*, _Tp1*,
1449 _GLIBCXX_STD_C::_Deque_iterator<_Tp2, _Ref2, _Ptr2>,
1450 _GLIBCXX_STD_C::_Deque_iterator<_Tp2, _Ref2, _Ptr2>);
1452 template<
typename _Tp1,
typename _Ref1,
typename _Ptr1,
1453 typename _Tp2,
typename _Ref2,
typename _Ptr2>
1455 __lexicographical_compare_aux1(
1456 _GLIBCXX_STD_C::_Deque_iterator<_Tp1, _Ref1, _Ptr1>,
1457 _GLIBCXX_STD_C::_Deque_iterator<_Tp1, _Ref1, _Ptr1>,
1458 _GLIBCXX_STD_C::_Deque_iterator<_Tp2, _Ref2, _Ptr2>,
1459 _GLIBCXX_STD_C::_Deque_iterator<_Tp2, _Ref2, _Ptr2>);
1461 template<
typename _II1,
typename _II2>
1462 _GLIBCXX20_CONSTEXPR
1464 __lexicographical_compare_aux(_II1 __first1, _II1 __last1,
1465 _II2 __first2, _II2 __last2)
1467 return std::__lexicographical_compare_aux1(std::__niter_base(__first1),
1468 std::__niter_base(__last1),
1469 std::__niter_base(__first2),
1470 std::__niter_base(__last2));
1473 template<
typename _Iter1,
typename _Seq1,
typename _Cat1,
1475 _GLIBCXX20_CONSTEXPR
1477 __lexicographical_compare_aux(
1478 const ::__gnu_debug::_Safe_iterator<_Iter1, _Seq1, _Cat1>&,
1479 const ::__gnu_debug::_Safe_iterator<_Iter1, _Seq1, _Cat1>&,
1482 template<
typename _II1,
1483 typename _Iter2,
typename _Seq2,
typename _Cat2>
1484 _GLIBCXX20_CONSTEXPR
1486 __lexicographical_compare_aux(
1488 const ::__gnu_debug::_Safe_iterator<_Iter2, _Seq2, _Cat2>&,
1489 const ::__gnu_debug::_Safe_iterator<_Iter2, _Seq2, _Cat2>&);
1491 template<
typename _Iter1,
typename _Seq1,
typename _Cat1,
1492 typename _Iter2,
typename _Seq2,
typename _Cat2>
1493 _GLIBCXX20_CONSTEXPR
1495 __lexicographical_compare_aux(
1496 const ::__gnu_debug::_Safe_iterator<_Iter1, _Seq1, _Cat1>&,
1497 const ::__gnu_debug::_Safe_iterator<_Iter1, _Seq1, _Cat1>&,
1498 const ::__gnu_debug::_Safe_iterator<_Iter2, _Seq2, _Cat2>&,
1499 const ::__gnu_debug::_Safe_iterator<_Iter2, _Seq2, _Cat2>&);
1501 template<
typename _ForwardIterator,
typename _Tp,
typename _Compare>
1502 _GLIBCXX20_CONSTEXPR
1504 __lower_bound(_ForwardIterator __first, _ForwardIterator __last,
1505 const _Tp& __val, _Compare __comp)
1514 _DistanceType __half = __len >> 1;
1515 _ForwardIterator __middle = __first;
1517 if (__comp(*__middle, __val))
1521 __len = __len - __half - 1;
1540 template<
typename _ForwardIterator,
typename _Tp>
1541 _GLIBCXX_NODISCARD _GLIBCXX20_CONSTEXPR
1542 inline _ForwardIterator
1543 lower_bound(_ForwardIterator __first, _ForwardIterator __last,
1547 __glibcxx_function_requires(_ForwardIteratorConcept<_ForwardIterator>)
1548 __glibcxx_function_requires(_LessThanOpConcept<
1550 __glibcxx_requires_partitioned_lower(__first, __last, __val);
1552 return std::__lower_bound(__first, __last, __val,
1553 __gnu_cxx::__ops::less());
1558 template<
typename _Tp>
1559 inline _GLIBCXX_CONSTEXPR _Tp
1562#if __cplusplus >= 201402L
1565#pragma GCC diagnostic push
1566#pragma GCC diagnostic ignored "-Wlong-long"
1568 return (
sizeof(+__n) * __CHAR_BIT__ - 1)
1569 - (
sizeof(+__n) ==
sizeof(
long long)
1570 ? __builtin_clzll(+__n)
1571 : (
sizeof(+__n) ==
sizeof(long)
1572 ? __builtin_clzl(+__n)
1573 : __builtin_clz(+__n)));
1574#pragma GCC diagnostic pop
1578_GLIBCXX_BEGIN_NAMESPACE_ALGO
1592 template<
typename _II1,
typename _II2>
1593 _GLIBCXX_NODISCARD _GLIBCXX20_CONSTEXPR
1595 equal(_II1 __first1, _II1 __last1, _II2 __first2)
1598 __glibcxx_function_requires(_InputIteratorConcept<_II1>)
1599 __glibcxx_function_requires(_InputIteratorConcept<_II2>)
1600 __glibcxx_function_requires(_EqualOpConcept<
1603 __glibcxx_requires_can_increment_range(__first1, __last1, __first2);
1605 return std::__equal_aux(__first1, __last1, __first2);
1623 template<
typename _IIter1,
typename _IIter2,
typename _BinaryPredicate>
1624 _GLIBCXX_NODISCARD _GLIBCXX20_CONSTEXPR
1626 equal(_IIter1 __first1, _IIter1 __last1,
1627 _IIter2 __first2, _BinaryPredicate __binary_pred)
1630 __glibcxx_function_requires(_InputIteratorConcept<_IIter1>)
1631 __glibcxx_function_requires(_InputIteratorConcept<_IIter2>)
1632 __glibcxx_requires_valid_range(__first1, __last1);
1634 for (; __first1 != __last1; ++__first1, (void)++__first2)
1635 if (!
bool(__binary_pred(*__first1, *__first2)))
1640#if __cplusplus >= 201103L
1641#pragma GCC diagnostic push
1642#pragma GCC diagnostic ignored "-Wc++17-extensions"
1645 template<
typename _II1,
typename _II2>
1646 _GLIBCXX20_CONSTEXPR
1648 __equal4(_II1 __first1, _II1 __last1, _II2 __first2, _II2 __last2)
1650 using _RATag = random_access_iterator_tag;
1651 using _Cat1 =
typename iterator_traits<_II1>::iterator_category;
1652 using _Cat2 =
typename iterator_traits<_II2>::iterator_category;
1653 using _RAIters = __and_<is_same<_Cat1, _RATag>, is_same<_Cat2, _RATag>>;
1654 if constexpr (_RAIters::value)
1656 if ((__last1 - __first1) != (__last2 - __first2))
1658 return _GLIBCXX_STD_A::equal(__first1, __last1, __first2);
1662 for (; __first1 != __last1 && __first2 != __last2;
1663 ++__first1, (void)++__first2)
1664 if (!(*__first1 == *__first2))
1666 return __first1 == __last1 && __first2 == __last2;
1671 template<
typename _II1,
typename _II2,
typename _BinaryPredicate>
1672 _GLIBCXX20_CONSTEXPR
1674 __equal4(_II1 __first1, _II1 __last1, _II2 __first2, _II2 __last2,
1675 _BinaryPredicate __binary_pred)
1681 if constexpr (_RAIters::value)
1683 if ((__last1 - __first1) != (__last2 - __first2))
1685 return _GLIBCXX_STD_A::equal(__first1, __last1, __first2,
1690 for (; __first1 != __last1 && __first2 != __last2;
1691 ++__first1, (void)++__first2)
1692 if (!
bool(__binary_pred(*__first1, *__first2)))
1694 return __first1 == __last1 && __first2 == __last2;
1697#pragma GCC diagnostic pop
1700#ifdef __glibcxx_robust_nonmodifying_seq_ops
1714 template<
typename _II1,
typename _II2>
1715 _GLIBCXX_NODISCARD _GLIBCXX20_CONSTEXPR
1717 equal(_II1 __first1, _II1 __last1, _II2 __first2, _II2 __last2)
1720 __glibcxx_function_requires(_InputIteratorConcept<_II1>)
1721 __glibcxx_function_requires(_InputIteratorConcept<_II2>)
1722 __glibcxx_function_requires(_EqualOpConcept<
1725 __glibcxx_requires_valid_range(__first1, __last1);
1726 __glibcxx_requires_valid_range(__first2, __last2);
1728 return _GLIBCXX_STD_A::__equal4(__first1, __last1, __first2, __last2);
1747 template<
typename _IIter1,
typename _IIter2,
typename _BinaryPredicate>
1748 _GLIBCXX_NODISCARD _GLIBCXX20_CONSTEXPR
1750 equal(_IIter1 __first1, _IIter1 __last1,
1751 _IIter2 __first2, _IIter2 __last2, _BinaryPredicate __binary_pred)
1754 __glibcxx_function_requires(_InputIteratorConcept<_IIter1>)
1755 __glibcxx_function_requires(_InputIteratorConcept<_IIter2>)
1756 __glibcxx_requires_valid_range(__first1, __last1);
1757 __glibcxx_requires_valid_range(__first2, __last2);
1759 return _GLIBCXX_STD_A::__equal4(__first1, __last1, __first2, __last2,
1779 template<
typename _II1,
typename _II2>
1780 _GLIBCXX_NODISCARD _GLIBCXX20_CONSTEXPR
1782 lexicographical_compare(_II1 __first1, _II1 __last1,
1783 _II2 __first2, _II2 __last2)
1785#ifdef _GLIBCXX_CONCEPT_CHECKS
1790 __glibcxx_function_requires(_InputIteratorConcept<_II1>)
1791 __glibcxx_function_requires(_InputIteratorConcept<_II2>)
1792 __glibcxx_function_requires(_LessThanOpConcept<_ValueType1, _ValueType2>)
1793 __glibcxx_function_requires(_LessThanOpConcept<_ValueType2, _ValueType1>)
1794 __glibcxx_requires_valid_range(__first1, __last1);
1795 __glibcxx_requires_valid_range(__first2, __last2);
1797 return std::__lexicographical_compare_aux(__first1, __last1,
1814 template<
typename _II1,
typename _II2,
typename _Compare>
1815 _GLIBCXX_NODISCARD _GLIBCXX20_CONSTEXPR
1817 lexicographical_compare(_II1 __first1, _II1 __last1,
1818 _II2 __first2, _II2 __last2, _Compare __comp)
1821 __glibcxx_function_requires(_InputIteratorConcept<_II1>)
1822 __glibcxx_function_requires(_InputIteratorConcept<_II2>)
1823 __glibcxx_requires_valid_range(__first1, __last1);
1824 __glibcxx_requires_valid_range(__first2, __last2);
1826 return std::__lexicographical_compare_impl
1827 (__first1, __last1, __first2, __last2, __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));
1885 if (!std::__is_constant_evaluated())
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::equal_to());
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,
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::equal_to());
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,
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)
2151 __decltype(*__first2) __first2_val(*__first2);
2152 __decltype(__gnu_cxx::__ops::bind2nd(__predicate, __first2_val))
2153 __match_first = __gnu_cxx::__ops::bind2nd(__predicate, __first2_val);
2156 _ForwardIterator2 __p1(__first2);
2157 if (++__p1 == __last2)
2158 return std::__find_if(__first1, __last1, __match_first);
2161 _ForwardIterator1 __current = __first1;
2165 __first1 = std::__find_if(__first1, __last1, __match_first);
2167 if (__first1 == __last1)
2170 _ForwardIterator2 __p = __p1;
2171 __current = __first1;
2172 if (++__current == __last1)
2175 while (__predicate(*__current, *__p))
2177 if (++__p == __last2)
2179 if (++__current == __last1)
2188#if __cplusplus >= 201103L
2189 template<
typename _ForwardIterator1,
typename _ForwardIterator2,
2190 typename _BinaryPredicate>
2191 _GLIBCXX20_CONSTEXPR
2193 __is_permutation(_ForwardIterator1 __first1, _ForwardIterator1 __last1,
2194 _ForwardIterator2 __first2, _BinaryPredicate __pred)
2198 for (; __first1 != __last1; ++__first1, (void)++__first2)
2199 if (!__pred(*__first1, *__first2))
2202 if (__first1 == __last1)
2207 _ForwardIterator2 __last2 = __first2;
2209 for (_ForwardIterator1 __scan = __first1; __scan != __last1; ++__scan)
2211 auto&& __scan_val = *__scan;
2212 auto __scaneq = __gnu_cxx::__ops::bind1st(__pred, __scan_val);
2213 if (__scan != std::__find_if(__first1, __scan, __scaneq))
2216 auto __matches = std::__count_if(__first2, __last2, __scaneq);
2218 || std::__count_if(__scan, __last1, __scaneq) != __matches)
2236 template<
typename _ForwardIterator1,
typename _ForwardIterator2>
2237 _GLIBCXX20_CONSTEXPR
2239 is_permutation(_ForwardIterator1 __first1, _ForwardIterator1 __last1,
2240 _ForwardIterator2 __first2)
2243 __glibcxx_function_requires(_ForwardIteratorConcept<_ForwardIterator1>)
2244 __glibcxx_function_requires(_ForwardIteratorConcept<_ForwardIterator2>)
2245 __glibcxx_function_requires(_EqualOpConcept<
2248 __glibcxx_requires_valid_range(__first1, __last1);
2250 return std::__is_permutation(__first1, __last1, __first2,
2251 __gnu_cxx::__ops::equal_to());
2255_GLIBCXX_BEGIN_NAMESPACE_ALGO
2278 template<
typename _ForwardIterator1,
typename _ForwardIterator2,
2279 typename _BinaryPredicate>
2280 _GLIBCXX20_CONSTEXPR
2281 inline _ForwardIterator1
2282 search(_ForwardIterator1 __first1, _ForwardIterator1 __last1,
2283 _ForwardIterator2 __first2, _ForwardIterator2 __last2,
2284 _BinaryPredicate __predicate)
2287 __glibcxx_function_requires(_ForwardIteratorConcept<_ForwardIterator1>)
2288 __glibcxx_function_requires(_ForwardIteratorConcept<_ForwardIterator2>)
2289 __glibcxx_function_requires(_BinaryPredicateConcept<_BinaryPredicate,
2292 __glibcxx_requires_valid_range(__first1, __last1);
2293 __glibcxx_requires_valid_range(__first2, __last2);
2295 return std::__search(__first1, __last1, __first2, __last2, __predicate);
2298_GLIBCXX_END_NAMESPACE_ALGO
2299_GLIBCXX_END_NAMESPACE_VERSION
2305#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.
Traits class for iterators.
Struct holding two objects of arbitrary type.
Random-access iterators support a superset of bidirectional iterator operations.
[concept.same], concept same_as