56#ifndef _STL_ALGOBASE_H
57#define _STL_ALGOBASE_H 1
71#if __cplusplus >= 201103L
74#if __cplusplus >= 201402L
77#if __cplusplus >= 202002L
82namespace std _GLIBCXX_VISIBILITY(default)
84_GLIBCXX_BEGIN_NAMESPACE_VERSION
90 template<
typename _Tp,
typename _Up>
93 __memcmp(
const _Tp* __first1,
const _Up* __first2,
size_t __num)
95#if __cplusplus >= 201103L
96 static_assert(
sizeof(_Tp) ==
sizeof(_Up),
"can be compared with memcmp");
98#ifdef __cpp_lib_is_constant_evaluated
99 if (std::is_constant_evaluated())
101 for(; __num > 0; ++__first1, ++__first2, --__num)
102 if (*__first1 != *__first2)
103 return *__first1 < *__first2 ? -1 : 1;
108 return __builtin_memcmp(__first1, __first2,
sizeof(_Tp) * __num);
111#if __cplusplus < 201103L
115 template<
bool _BoolType>
118 template<
typename _ForwardIterator1,
typename _ForwardIterator2>
120 iter_swap(_ForwardIterator1 __a, _ForwardIterator2 __b)
122 typedef typename iterator_traits<_ForwardIterator1>::value_type
124 _ValueType1 __tmp = *__a;
131 struct __iter_swap<true>
133 template<
typename _ForwardIterator1,
typename _ForwardIterator2>
135 iter_swap(_ForwardIterator1 __a, _ForwardIterator2 __b)
151 template<
typename _ForwardIterator1,
typename _ForwardIterator2>
154 iter_swap(_ForwardIterator1 __a, _ForwardIterator2 __b)
157 __glibcxx_function_requires(_Mutable_ForwardIteratorConcept<
159 __glibcxx_function_requires(_Mutable_ForwardIteratorConcept<
162#if __cplusplus < 201103L
168 __glibcxx_function_requires(_ConvertibleConcept<_ValueType1,
170 __glibcxx_function_requires(_ConvertibleConcept<_ValueType2,
177 std::__iter_swap<__are_same<_ValueType1, _ValueType2>::__value
178 && __are_same<_ValueType1&, _ReferenceType1>::__value
179 && __are_same<_ValueType2&, _ReferenceType2>::__value>::
200 template<
typename _ForwardIterator1,
typename _ForwardIterator2>
203 swap_ranges(_ForwardIterator1 __first1, _ForwardIterator1 __last1,
204 _ForwardIterator2 __first2)
207 __glibcxx_function_requires(_Mutable_ForwardIteratorConcept<
209 __glibcxx_function_requires(_Mutable_ForwardIteratorConcept<
211 __glibcxx_requires_valid_range(__first1, __last1);
213 for (; __first1 != __last1; ++__first1, (void)++__first2)
214 std::iter_swap(__first1, __first2);
229 template<
typename _Tp>
230 _GLIBCXX_NODISCARD _GLIBCXX14_CONSTEXPR
232 min(
const _Tp& __a,
const _Tp& __b)
235 __glibcxx_function_requires(_LessThanComparableConcept<_Tp>)
253 template<
typename _Tp>
254 _GLIBCXX_NODISCARD _GLIBCXX14_CONSTEXPR
256 max(
const _Tp& __a,
const _Tp& __b)
259 __glibcxx_function_requires(_LessThanComparableConcept<_Tp>)
277 template<
typename _Tp,
typename _Compare>
278 _GLIBCXX_NODISCARD _GLIBCXX14_CONSTEXPR
280 min(
const _Tp& __a,
const _Tp& __b, _Compare __comp)
283 if (__comp(__b, __a))
299 template<
typename _Tp,
typename _Compare>
300 _GLIBCXX_NODISCARD _GLIBCXX14_CONSTEXPR
302 max(
const _Tp& __a,
const _Tp& __b, _Compare __comp)
305 if (__comp(__a, __b))
310_GLIBCXX_BEGIN_NAMESPACE_CONTAINER
312 template<
typename _Tp,
typename _Ref,
typename _Ptr>
313 struct _Deque_iterator;
315 struct _Bit_iterator;
317_GLIBCXX_END_NAMESPACE_CONTAINER
322 template<
typename _CharT>
325 template<
typename _CharT,
typename _Traits>
326 class istreambuf_iterator;
328 template<
typename _CharT,
typename _Traits>
329 class ostreambuf_iterator;
331 template<
bool _IsMove,
typename _CharT>
332 typename __gnu_cxx::__enable_if<__is_char<_CharT>::__value,
333 ostreambuf_iterator<_CharT, char_traits<_CharT> > >::__type
334 __copy_move_a2(_CharT*, _CharT*,
335 ostreambuf_iterator<_CharT, char_traits<_CharT> >);
337 template<
bool _IsMove,
typename _CharT>
338 typename __gnu_cxx::__enable_if<__is_char<_CharT>::__value,
339 ostreambuf_iterator<_CharT, char_traits<_CharT> > >::__type
340 __copy_move_a2(
const _CharT*,
const _CharT*,
341 ostreambuf_iterator<_CharT, char_traits<_CharT> >);
343 template<
bool _IsMove,
typename _CharT>
344 typename __gnu_cxx::__enable_if<__is_char<_CharT>::__value,
346 __copy_move_a2(istreambuf_iterator<_CharT, char_traits<_CharT> >,
347 istreambuf_iterator<_CharT, char_traits<_CharT> >, _CharT*);
349 template<
bool _IsMove,
typename _CharT>
350 typename __gnu_cxx::__enable_if<
351 __is_char<_CharT>::__value,
352 _GLIBCXX_STD_C::_Deque_iterator<_CharT, _CharT&, _CharT*> >::__type
354 istreambuf_iterator<_CharT, char_traits<_CharT> >,
355 istreambuf_iterator<_CharT, char_traits<_CharT> >,
356 _GLIBCXX_STD_C::_Deque_iterator<_CharT, _CharT&, _CharT*>);
359#if __cpp_lib_concepts
360 template<
typename _OutIter,
typename _InIter,
typename _Sent = _InIter>
361 concept __memcpyable_iterators
362 = contiguous_iterator<_OutIter> && contiguous_iterator<_InIter>
363 && sized_sentinel_for<_Sent, _InIter>
364 &&
requires (_OutIter __o, _InIter __i) {
370#if __cplusplus < 201103L
375 template<
typename _Iter> __attribute__((__always_inline__))
376 inline void* __ptr_or_null(_Iter) {
return 0; }
377 template<
typename _Tp> __attribute__((__always_inline__))
378 inline void* __ptr_or_null(_Tp* __p) {
return (
void*)__p; }
379# define _GLIBCXX_TO_ADDR(P) std::__ptr_or_null(P)
381 template<
typename _Iter> __attribute__((__always_inline__))
382 inline void __ptr_advance(_Iter&, ptrdiff_t) { }
383 template<
typename _Tp> __attribute__((__always_inline__))
384 inline void __ptr_advance(_Tp*& __p, ptrdiff_t __n) { __p += __n; }
385# define _GLIBCXX_ADVANCE(P, N) std::__ptr_advance(P, N)
389# define _GLIBCXX_TO_ADDR(P) P
390# define _GLIBCXX_ADVANCE(P, N) P += N
393#pragma GCC diagnostic push
394#pragma GCC diagnostic ignored "-Wc++17-extensions"
395 template<
bool _IsMove,
typename _OutIter,
typename _InIter>
396 __attribute__((__always_inline__)) _GLIBCXX20_CONSTEXPR
398 __assign_one(_OutIter& __out, _InIter& __in)
400#if __cplusplus >= 201103L
401 if constexpr (_IsMove)
408 template<
bool _IsMove,
typename _InIter,
typename _Sent,
typename _OutIter>
411 __copy_move_a2(_InIter __first, _Sent __last, _OutIter __result)
413 typedef __decltype(*__first) _InRef;
414 typedef __decltype(*__result) _OutRef;
415 if _GLIBCXX_CONSTEXPR (!__is_trivially_assignable(_OutRef, _InRef))
417 else if (std::__is_constant_evaluated())
419 else if _GLIBCXX_CONSTEXPR (__memcpyable<_OutIter, _InIter>::__value)
422 if (__builtin_expect(__n > 1,
true))
424 __builtin_memmove(_GLIBCXX_TO_ADDR(__result),
425 _GLIBCXX_TO_ADDR(__first),
426 __n *
sizeof(*__first));
427 _GLIBCXX_ADVANCE(__result, __n);
431 std::__assign_one<_IsMove>(__result, __first);
436#if __cpp_lib_concepts
437 else if constexpr (__memcpyable_iterators<_OutIter, _InIter, _Sent>)
439 if (
auto __n = __last - __first; __n > 1) [[likely]]
443 size_t __nbytes = __n *
sizeof(iter_value_t<_InIter>);
448 __builtin_memmove(__dest, __src, __nbytes);
452 std::__assign_one<_IsMove>(__result, __first);
459 for (; __first != __last; ++__result, (void)++__first)
460 std::__assign_one<_IsMove>(__result, __first);
463#pragma GCC diagnostic pop
465 template<
bool _IsMove,
466 typename _Tp,
typename _Ref,
typename _Ptr,
typename _OI>
468 __copy_move_a1(_GLIBCXX_STD_C::_Deque_iterator<_Tp, _Ref, _Ptr>,
469 _GLIBCXX_STD_C::_Deque_iterator<_Tp, _Ref, _Ptr>,
472 template<
bool _IsMove,
473 typename _ITp,
typename _IRef,
typename _IPtr,
typename _OTp>
474 _GLIBCXX_STD_C::_Deque_iterator<_OTp, _OTp&, _OTp*>
475 __copy_move_a1(_GLIBCXX_STD_C::_Deque_iterator<_ITp, _IRef, _IPtr>,
476 _GLIBCXX_STD_C::_Deque_iterator<_ITp, _IRef, _IPtr>,
477 _GLIBCXX_STD_C::_Deque_iterator<_OTp, _OTp&, _OTp*>);
479 template<
bool _IsMove,
typename _II,
typename _Tp>
480 typename __gnu_cxx::__enable_if<
481 __is_any_random_access_iter<_II>::__value,
482 _GLIBCXX_STD_C::_Deque_iterator<_Tp, _Tp&, _Tp*> >::__type
483 __copy_move_a1(_II, _II, _GLIBCXX_STD_C::_Deque_iterator<_Tp, _Tp&, _Tp*>);
485 template<
bool _IsMove,
typename _II,
typename _OI>
486 __attribute__((__always_inline__))
489 __copy_move_a1(_II __first, _II __last, _OI __result)
490 {
return std::__copy_move_a2<_IsMove>(__first, __last, __result); }
492 template<
bool _IsMove,
typename _II,
typename _OI>
493 __attribute__((__always_inline__))
496 __copy_move_a(_II __first, _II __last, _OI __result)
498 return std::__niter_wrap(__result,
499 std::__copy_move_a1<_IsMove>(std::__niter_base(__first),
500 std::__niter_base(__last),
501 std::__niter_base(__result)));
504 template<
bool _IsMove,
505 typename _Ite,
typename _Seq,
typename _Cat,
typename _OI>
508 __copy_move_a(const ::__gnu_debug::_Safe_iterator<_Ite, _Seq, _Cat>&,
509 const ::__gnu_debug::_Safe_iterator<_Ite, _Seq, _Cat>&,
512 template<
bool _IsMove,
513 typename _II,
typename _Ite,
typename _Seq,
typename _Cat>
515 __gnu_debug::_Safe_iterator<_Ite, _Seq, _Cat>
516 __copy_move_a(_II, _II,
517 const ::__gnu_debug::_Safe_iterator<_Ite, _Seq, _Cat>&);
519 template<
bool _IsMove,
520 typename _IIte,
typename _ISeq,
typename _ICat,
521 typename _OIte,
typename _OSeq,
typename _OCat>
523 ::__gnu_debug::_Safe_iterator<_OIte, _OSeq, _OCat>
524 __copy_move_a(const ::__gnu_debug::_Safe_iterator<_IIte, _ISeq, _ICat>&,
525 const ::__gnu_debug::_Safe_iterator<_IIte, _ISeq, _ICat>&,
526 const ::__gnu_debug::_Safe_iterator<_OIte, _OSeq, _OCat>&);
528#pragma GCC diagnostic push
529#pragma GCC diagnostic ignored "-Wc++17-extensions"
530 template<
typename _InputIterator,
typename _Size,
typename _OutputIterator>
533 __copy_n_a(_InputIterator __first, _Size __n, _OutputIterator __result,
536 typedef __decltype(*__first) _InRef;
537 typedef __decltype(*__result) _OutRef;
538 if _GLIBCXX_CONSTEXPR (!__is_trivially_assignable(_OutRef, _InRef))
540#ifdef __cpp_lib_is_constant_evaluated
541 else if (std::is_constant_evaluated())
544 else if _GLIBCXX_CONSTEXPR (__memcpyable<_OutputIterator,
545 _InputIterator>::__value)
547 if (__builtin_expect(__n > 1,
true))
549 __builtin_memmove(_GLIBCXX_TO_ADDR(__result),
550 _GLIBCXX_TO_ADDR(__first),
551 __n *
sizeof(*__first));
552 _GLIBCXX_ADVANCE(__result, __n);
555 *__result++ = *__first;
558#if __cpp_lib_concepts
559 else if constexpr (__memcpyable_iterators<_OutputIterator,
562 if (__n > 1) [[likely]]
566 size_t __nbytes = __n *
sizeof(iter_value_t<_InputIterator>);
571 __builtin_memmove(__dest, __src, __nbytes);
574 *__result++ = *__first;
583 *__result = *__first;
593#pragma GCC diagnostic pop
596 template<
typename _CharT,
typename _Size>
597 typename __gnu_cxx::__enable_if<
598 __is_char<_CharT>::__value, _CharT*>::__type
600 _Size, _CharT*,
bool);
602 template<
typename _CharT,
typename _Size>
603 typename __gnu_cxx::__enable_if<
604 __is_char<_CharT>::__value,
605 _GLIBCXX_STD_C::_Deque_iterator<_CharT, _CharT&, _CharT*> >::__type
607 _GLIBCXX_STD_C::_Deque_iterator<_CharT, _CharT&, _CharT*>,
628 template<
typename _II,
typename _OI>
631 copy(_II __first, _II __last, _OI __result)
634 __glibcxx_function_requires(_InputIteratorConcept<_II>)
635 __glibcxx_function_requires(_OutputIteratorConcept<_OI,
637 __glibcxx_requires_can_increment_range(__first, __last, __result);
639 return std::__copy_move_a<__is_move_iterator<_II>::__value>
640 (std::__miter_base(__first), std::__miter_base(__last), __result);
643#if __cplusplus >= 201103L
661 template<
typename _II,
typename _OI>
664 move(_II __first, _II __last, _OI __result)
667 __glibcxx_function_requires(_InputIteratorConcept<_II>)
668 __glibcxx_function_requires(_OutputIteratorConcept<_OI,
670 __glibcxx_requires_can_increment_range(__first, __last, __result);
672 return std::__copy_move_a<true>(std::__miter_base(__first),
673 std::__miter_base(__last), __result);
676#define _GLIBCXX_MOVE3(_Tp, _Up, _Vp) std::move(_Tp, _Up, _Vp)
678#define _GLIBCXX_MOVE3(_Tp, _Up, _Vp) std::copy(_Tp, _Up, _Vp)
681#pragma GCC diagnostic push
682#pragma GCC diagnostic ignored "-Wc++17-extensions"
683 template<
bool _IsMove,
typename _BI1,
typename _BI2>
686 __copy_move_backward_a2(_BI1 __first, _BI1 __last, _BI2 __result)
688 typedef __decltype(*__first) _InRef;
689 typedef __decltype(*__result) _OutRef;
690 if _GLIBCXX_CONSTEXPR (!__is_trivially_assignable(_OutRef, _InRef))
692#ifdef __cpp_lib_is_constant_evaluated
693 else if (std::is_constant_evaluated())
696 else if _GLIBCXX_CONSTEXPR (__memcpyable<_BI2, _BI1>::__value)
700 if (__builtin_expect(__n > 1,
true))
702 __builtin_memmove(_GLIBCXX_TO_ADDR(__result),
703 _GLIBCXX_TO_ADDR(__first),
704 __n *
sizeof(*__first));
707 std::__assign_one<_IsMove>(__result, __first);
710#if __cpp_lib_concepts
711 else if constexpr (__memcpyable_iterators<_BI2, _BI1>)
713 if (
auto __n = __last - __first; __n > 1) [[likely]]
721 size_t __nbytes = __n *
sizeof(iter_value_t<_BI1>);
722 __builtin_memmove(__dest, __src, __nbytes);
727 std::__assign_one<_IsMove>(__result, __first);
733 while (__first != __last)
737 std::__assign_one<_IsMove>(__result, __last);
741#pragma GCC diagnostic pop
743#undef _GLIBCXX_TO_ADDR
744#undef _GLIBCXX_ADVANCE
746 template<
bool _IsMove,
typename _BI1,
typename _BI2>
747 __attribute__((__always_inline__))
750 __copy_move_backward_a1(_BI1 __first, _BI1 __last, _BI2 __result)
751 {
return std::__copy_move_backward_a2<_IsMove>(__first, __last, __result); }
753 template<
bool _IsMove,
754 typename _Tp,
typename _Ref,
typename _Ptr,
typename _OI>
756 __copy_move_backward_a1(_GLIBCXX_STD_C::_Deque_iterator<_Tp, _Ref, _Ptr>,
757 _GLIBCXX_STD_C::_Deque_iterator<_Tp, _Ref, _Ptr>,
760 template<
bool _IsMove,
761 typename _ITp,
typename _IRef,
typename _IPtr,
typename _OTp>
762 _GLIBCXX_STD_C::_Deque_iterator<_OTp, _OTp&, _OTp*>
763 __copy_move_backward_a1(
764 _GLIBCXX_STD_C::_Deque_iterator<_ITp, _IRef, _IPtr>,
765 _GLIBCXX_STD_C::_Deque_iterator<_ITp, _IRef, _IPtr>,
766 _GLIBCXX_STD_C::_Deque_iterator<_OTp, _OTp&, _OTp*>);
768 template<
bool _IsMove,
typename _II,
typename _Tp>
769 typename __gnu_cxx::__enable_if<
770 __is_any_random_access_iter<_II>::__value,
771 _GLIBCXX_STD_C::_Deque_iterator<_Tp, _Tp&, _Tp*> >::__type
772 __copy_move_backward_a1(_II, _II,
773 _GLIBCXX_STD_C::_Deque_iterator<_Tp, _Tp&, _Tp*>);
775 template<
bool _IsMove,
typename _II,
typename _OI>
776 __attribute__((__always_inline__))
779 __copy_move_backward_a(_II __first, _II __last, _OI __result)
781 return std::__niter_wrap(__result,
782 std::__copy_move_backward_a1<_IsMove>
783 (std::__niter_base(__first), std::__niter_base(__last),
784 std::__niter_base(__result)));
787 template<
bool _IsMove,
788 typename _Ite,
typename _Seq,
typename _Cat,
typename _OI>
791 __copy_move_backward_a(
792 const ::__gnu_debug::_Safe_iterator<_Ite, _Seq, _Cat>&,
793 const ::__gnu_debug::_Safe_iterator<_Ite, _Seq, _Cat>&,
796 template<
bool _IsMove,
797 typename _II,
typename _Ite,
typename _Seq,
typename _Cat>
799 __gnu_debug::_Safe_iterator<_Ite, _Seq, _Cat>
800 __copy_move_backward_a(_II, _II,
801 const ::__gnu_debug::_Safe_iterator<_Ite, _Seq, _Cat>&);
803 template<
bool _IsMove,
804 typename _IIte,
typename _ISeq,
typename _ICat,
805 typename _OIte,
typename _OSeq,
typename _OCat>
807 ::__gnu_debug::_Safe_iterator<_OIte, _OSeq, _OCat>
808 __copy_move_backward_a(
809 const ::__gnu_debug::_Safe_iterator<_IIte, _ISeq, _ICat>&,
810 const ::__gnu_debug::_Safe_iterator<_IIte, _ISeq, _ICat>&,
811 const ::__gnu_debug::_Safe_iterator<_OIte, _OSeq, _OCat>&);
831 template<
typename _BI1,
typename _BI2>
832 __attribute__((__always_inline__))
835 copy_backward(_BI1 __first, _BI1 __last, _BI2 __result)
838 __glibcxx_function_requires(_BidirectionalIteratorConcept<_BI1>)
839 __glibcxx_function_requires(_Mutable_BidirectionalIteratorConcept<_BI2>)
840 __glibcxx_function_requires(_OutputIteratorConcept<_BI2,
842 __glibcxx_requires_can_decrement_range(__first, __last, __result);
844 return std::__copy_move_backward_a<__is_move_iterator<_BI1>::__value>
845 (std::__miter_base(__first), std::__miter_base(__last), __result);
848#if __cplusplus >= 201103L
867 template<
typename _BI1,
typename _BI2>
868 __attribute__((__always_inline__))
874 __glibcxx_function_requires(_BidirectionalIteratorConcept<_BI1>)
875 __glibcxx_function_requires(_Mutable_BidirectionalIteratorConcept<_BI2>)
876 __glibcxx_function_requires(_OutputIteratorConcept<_BI2,
878 __glibcxx_requires_can_decrement_range(__first, __last, __result);
880 return std::__copy_move_backward_a<true>(std::__miter_base(__first),
881 std::__miter_base(__last),
885#define _GLIBCXX_MOVE_BACKWARD3(_Tp, _Up, _Vp) std::move_backward(_Tp, _Up, _Vp)
887#define _GLIBCXX_MOVE_BACKWARD3(_Tp, _Up, _Vp) std::copy_backward(_Tp, _Up, _Vp)
890#pragma GCC diagnostic push
891#pragma GCC diagnostic ignored "-Wc++17-extensions"
892 template<
typename _ForwardIterator,
typename _Tp>
895 __fill_a1(_ForwardIterator __first, _ForwardIterator __last,
898#pragma GCC diagnostic push
899#pragma GCC diagnostic ignored "-Wlong-long"
904 const bool __load_outside_loop =
905#if __has_builtin(__is_trivially_constructible) \
906 && __has_builtin(__is_trivially_assignable)
907 __is_trivially_constructible(_Tp,
const _Tp&)
908 && __is_trivially_assignable(__decltype(*__first),
const _Tp&)
910 __is_trivially_copyable(_Tp)
911 && __is_same(_Tp, __typeof__(*__first))
913 &&
sizeof(_Tp) <=
sizeof(
long long);
914#pragma GCC diagnostic pop
918 typedef typename __gnu_cxx::__conditional_type<__load_outside_loop,
920 const _Tp&>::__type _Up;
922 for (; __first != __last; ++__first)
925#pragma GCC diagnostic pop
928 template<
typename _Up,
typename _Tp>
931 __gnu_cxx::__enable_if<__is_byte<_Up>::__value
932 && (__are_same<_Up, _Tp>::__value
933 || __memcpyable_integer<_Tp>::__width),
935 __fill_a1(_Up* __first, _Up* __last,
const _Tp& __x)
939 const _Up __val = __x;
940#if __cpp_lib_is_constant_evaluated
941 if (std::is_constant_evaluated())
943 for (; __first != __last; ++__first)
948 if (
const size_t __len = __last - __first)
949 __builtin_memset(__first,
static_cast<unsigned char>(__val), __len);
952 template<
typename _Ite,
typename _Cont,
typename _Tp>
953 __attribute__((__always_inline__))
956 __fill_a1(::__gnu_cxx::__normal_iterator<_Ite, _Cont> __first,
957 ::__gnu_cxx::__normal_iterator<_Ite, _Cont> __last,
959 { std::__fill_a1(__first.base(), __last.base(), __value); }
961 template<
typename _Tp,
typename _VTp>
963 __fill_a1(
const _GLIBCXX_STD_C::_Deque_iterator<_Tp, _Tp&, _Tp*>&,
964 const _GLIBCXX_STD_C::_Deque_iterator<_Tp, _Tp&, _Tp*>&,
969 __fill_a1(_GLIBCXX_STD_C::_Bit_iterator, _GLIBCXX_STD_C::_Bit_iterator,
972 template<
typename _FIte,
typename _Tp>
973 __attribute__((__always_inline__))
976 __fill_a(_FIte __first, _FIte __last,
const _Tp& __value)
977 { std::__fill_a1(__first, __last, __value); }
979 template<
typename _Ite,
typename _Seq,
typename _Cat,
typename _Tp>
982 __fill_a(const ::__gnu_debug::_Safe_iterator<_Ite, _Seq, _Cat>&,
983 const ::__gnu_debug::_Safe_iterator<_Ite, _Seq, _Cat>&,
997 template<
typename _ForwardIterator,
typename _Tp>
998 __attribute__((__always_inline__))
1001 fill(_ForwardIterator __first, _ForwardIterator __last,
const _Tp& __value)
1004 __glibcxx_function_requires(_Mutable_ForwardIteratorConcept<
1006 __glibcxx_requires_valid_range(__first, __last);
1008 std::__fill_a(__first, __last, __value);
1011#pragma GCC diagnostic push
1012#pragma GCC diagnostic ignored "-Wlong-long"
1014 inline _GLIBCXX_CONSTEXPR
int
1015 __size_to_integer(
int __n) {
return __n; }
1016 inline _GLIBCXX_CONSTEXPR
unsigned
1017 __size_to_integer(
unsigned __n) {
return __n; }
1018 inline _GLIBCXX_CONSTEXPR
long
1019 __size_to_integer(
long __n) {
return __n; }
1020 inline _GLIBCXX_CONSTEXPR
unsigned long
1021 __size_to_integer(
unsigned long __n) {
return __n; }
1022 inline _GLIBCXX_CONSTEXPR
long long
1023 __size_to_integer(
long long __n) {
return __n; }
1024 inline _GLIBCXX_CONSTEXPR
unsigned long long
1025 __size_to_integer(
unsigned long long __n) {
return __n; }
1027#if defined(__GLIBCXX_TYPE_INT_N_0)
1028 __extension__
inline _GLIBCXX_CONSTEXPR __GLIBCXX_TYPE_INT_N_0
1029 __size_to_integer(__GLIBCXX_TYPE_INT_N_0 __n) {
return __n; }
1030 __extension__
inline _GLIBCXX_CONSTEXPR
unsigned __GLIBCXX_TYPE_INT_N_0
1031 __size_to_integer(
unsigned __GLIBCXX_TYPE_INT_N_0 __n) {
return __n; }
1033#if defined(__GLIBCXX_TYPE_INT_N_1)
1034 __extension__
inline _GLIBCXX_CONSTEXPR __GLIBCXX_TYPE_INT_N_1
1035 __size_to_integer(__GLIBCXX_TYPE_INT_N_1 __n) {
return __n; }
1036 __extension__
inline _GLIBCXX_CONSTEXPR
unsigned __GLIBCXX_TYPE_INT_N_1
1037 __size_to_integer(
unsigned __GLIBCXX_TYPE_INT_N_1 __n) {
return __n; }
1039#if defined(__GLIBCXX_TYPE_INT_N_2)
1040 __extension__
inline _GLIBCXX_CONSTEXPR __GLIBCXX_TYPE_INT_N_2
1041 __size_to_integer(__GLIBCXX_TYPE_INT_N_2 __n) {
return __n; }
1042 __extension__
inline _GLIBCXX_CONSTEXPR
unsigned __GLIBCXX_TYPE_INT_N_2
1043 __size_to_integer(
unsigned __GLIBCXX_TYPE_INT_N_2 __n) {
return __n; }
1045#if defined(__GLIBCXX_TYPE_INT_N_3)
1046 __extension__
inline _GLIBCXX_CONSTEXPR __GLIBCXX_TYPE_INT_N_3
1047 __size_to_integer(__GLIBCXX_TYPE_INT_N_3 __n) {
return __n; }
1048 __extension__
inline _GLIBCXX_CONSTEXPR
unsigned __GLIBCXX_TYPE_INT_N_3
1049 __size_to_integer(
unsigned __GLIBCXX_TYPE_INT_N_3 __n) {
return __n; }
1052#if defined(__STRICT_ANSI__) && defined(__SIZEOF_INT128__)
1053 __extension__
inline _GLIBCXX_CONSTEXPR __int128
1054 __size_to_integer(__int128 __n) {
return __n; }
1055 __extension__
inline _GLIBCXX_CONSTEXPR
unsigned __int128
1056 __size_to_integer(
unsigned __int128 __n) {
return __n; }
1059 inline _GLIBCXX_CONSTEXPR
long long
1060 __size_to_integer(
float __n) {
return (
long long)__n; }
1061 inline _GLIBCXX_CONSTEXPR
long long
1062 __size_to_integer(
double __n) {
return (
long long)__n; }
1063 inline _GLIBCXX_CONSTEXPR
long long
1064 __size_to_integer(
long double __n) {
return (
long long)__n; }
1065#ifdef _GLIBCXX_USE_FLOAT128
1066 __extension__
inline _GLIBCXX_CONSTEXPR
long long
1067 __size_to_integer(__float128 __n) {
return (
long long)__n; }
1069#pragma GCC diagnostic pop
1071#pragma GCC diagnostic push
1072#pragma GCC diagnostic ignored "-Wc++17-extensions"
1073#pragma GCC diagnostic ignored "-Wlong-long"
1074 template<
typename _OutputIterator,
typename _Size,
typename _Tp>
1075 _GLIBCXX20_CONSTEXPR
1076 inline _OutputIterator
1077 __fill_n_a1(_OutputIterator __first, _Size __n,
const _Tp& __value)
1080 const bool __load_outside_loop =
1081#if __has_builtin(__is_trivially_constructible) \
1082 && __has_builtin(__is_trivially_assignable)
1083 __is_trivially_constructible(_Tp,
const _Tp&)
1084 && __is_trivially_assignable(__decltype(*__first),
const _Tp&)
1086 __is_trivially_copyable(_Tp)
1087 && __is_same(_Tp, __typeof__(*__first))
1089 &&
sizeof(_Tp) <=
sizeof(
long long);
1093 typedef typename __gnu_cxx::__conditional_type<__load_outside_loop,
1095 const _Tp&>::__type _Up;
1097 for (; __n > 0; --__n, (void) ++__first)
1101#pragma GCC diagnostic pop
1103 template<
typename _Ite,
typename _Seq,
typename _Cat,
typename _Size,
1105 _GLIBCXX20_CONSTEXPR
1106 ::__gnu_debug::_Safe_iterator<_Ite, _Seq, _Cat>
1107 __fill_n_a(const ::__gnu_debug::_Safe_iterator<_Ite, _Seq, _Cat>& __first,
1108 _Size __n,
const _Tp& __value,
1109 std::input_iterator_tag);
1111 template<
typename _OutputIterator,
typename _Size,
typename _Tp>
1112 __attribute__((__always_inline__))
1113 _GLIBCXX20_CONSTEXPR
1114 inline _OutputIterator
1115 __fill_n_a(_OutputIterator __first, _Size __n,
const _Tp& __value,
1116 std::output_iterator_tag)
1118#if __cplusplus >= 201103L
1121 return __fill_n_a1(__first, __n, __value);
1124 template<
typename _OutputIterator,
typename _Size,
typename _Tp>
1125 __attribute__((__always_inline__))
1126 _GLIBCXX20_CONSTEXPR
1127 inline _OutputIterator
1128 __fill_n_a(_OutputIterator __first, _Size __n,
const _Tp& __value,
1129 std::input_iterator_tag)
1131#if __cplusplus >= 201103L
1134 return __fill_n_a1(__first, __n, __value);
1137 template<
typename _OutputIterator,
typename _Size,
typename _Tp>
1138 __attribute__((__always_inline__))
1139 _GLIBCXX20_CONSTEXPR
1140 inline _OutputIterator
1141 __fill_n_a(_OutputIterator __first, _Size __n,
const _Tp& __value,
1142 std::random_access_iterator_tag)
1144#if __cplusplus >= 201103L
1151 __glibcxx_requires_can_increment(__first, __d);
1153 _OutputIterator __last = __first + __d;
1154 std::__fill_a(__first, __last, __value);
1175 template<
typename _OI,
typename _Size,
typename _Tp>
1176 __attribute__((__always_inline__))
1177 _GLIBCXX20_CONSTEXPR
1179 fill_n(_OI __first, _Size __n,
const _Tp& __value)
1182 __glibcxx_function_requires(_OutputIteratorConcept<_OI, const _Tp&>)
1184 return std::__fill_n_a(__first, std::__size_to_integer(__n), __value,
1188 template<
bool _BoolType>
1191 template<
typename _II1,
typename _II2>
1192 _GLIBCXX20_CONSTEXPR
1194 equal(_II1 __first1, _II1 __last1, _II2 __first2)
1196 for (; __first1 != __last1; ++__first1, (void) ++__first2)
1197 if (!(*__first1 == *__first2))
1204 struct __equal<true>
1206 template<
typename _Tp>
1207 _GLIBCXX20_CONSTEXPR
1209 equal(
const _Tp* __first1,
const _Tp* __last1,
const _Tp* __first2)
1211 if (
const size_t __len = (__last1 - __first1))
1212 return !std::__memcmp(__first1, __first2, __len);
1217 template<
typename _Tp,
typename _Ref,
typename _Ptr,
typename _II>
1218 typename __gnu_cxx::__enable_if<
1219 __is_any_random_access_iter<_II>::__value,
bool>::__type
1220 __equal_aux1(_GLIBCXX_STD_C::_Deque_iterator<_Tp, _Ref, _Ptr>,
1221 _GLIBCXX_STD_C::_Deque_iterator<_Tp, _Ref, _Ptr>,
1224 template<
typename _Tp1,
typename _Ref1,
typename _Ptr1,
1225 typename _Tp2,
typename _Ref2,
typename _Ptr2>
1227 __equal_aux1(_GLIBCXX_STD_C::_Deque_iterator<_Tp1, _Ref1, _Ptr1>,
1228 _GLIBCXX_STD_C::_Deque_iterator<_Tp1, _Ref1, _Ptr1>,
1229 _GLIBCXX_STD_C::_Deque_iterator<_Tp2, _Ref2, _Ptr2>);
1231 template<
typename _II,
typename _Tp,
typename _Ref,
typename _Ptr>
1232 typename __gnu_cxx::__enable_if<
1233 __is_any_random_access_iter<_II>::__value,
bool>::__type
1234 __equal_aux1(_II, _II,
1235 _GLIBCXX_STD_C::_Deque_iterator<_Tp, _Ref, _Ptr>);
1237 template<
typename _II1,
typename _II2>
1238 _GLIBCXX20_CONSTEXPR
1240 __equal_aux1(_II1 __first1, _II1 __last1, _II2 __first2)
1243 const bool __simple = ((__is_integer<_ValueType1>::__value
1244#if _GLIBCXX_USE_BUILTIN_TRAIT(__is_pointer)
1245 || __is_pointer(_ValueType1)
1247#if __glibcxx_byte && __glibcxx_type_trait_variable_templates
1249 || is_same_v<_ValueType1, byte>
1251 ) && __memcmpable<_II1, _II2>::__value);
1252 return std::__equal<__simple>::equal(__first1, __last1, __first2);
1255 template<
typename _II1,
typename _II2>
1256 __attribute__((__always_inline__))
1257 _GLIBCXX20_CONSTEXPR
1259 __equal_aux(_II1 __first1, _II1 __last1, _II2 __first2)
1261 return std::__equal_aux1(std::__niter_base(__first1),
1262 std::__niter_base(__last1),
1263 std::__niter_base(__first2));
1266 template<
typename _II1,
typename _Seq1,
typename _Cat1,
typename _II2>
1267 _GLIBCXX20_CONSTEXPR
1269 __equal_aux(const ::__gnu_debug::_Safe_iterator<_II1, _Seq1, _Cat1>&,
1270 const ::__gnu_debug::_Safe_iterator<_II1, _Seq1, _Cat1>&,
1273 template<
typename _II1,
typename _II2,
typename _Seq2,
typename _Cat2>
1274 _GLIBCXX20_CONSTEXPR
1276 __equal_aux(_II1, _II1,
1277 const ::__gnu_debug::_Safe_iterator<_II2, _Seq2, _Cat2>&);
1279 template<
typename _II1,
typename _Seq1,
typename _Cat1,
1280 typename _II2,
typename _Seq2,
typename _Cat2>
1281 _GLIBCXX20_CONSTEXPR
1283 __equal_aux(const ::__gnu_debug::_Safe_iterator<_II1, _Seq1, _Cat1>&,
1284 const ::__gnu_debug::_Safe_iterator<_II1, _Seq1, _Cat1>&,
1285 const ::__gnu_debug::_Safe_iterator<_II2, _Seq2, _Cat2>&);
1287 template<
typename,
typename>
1290 template<
typename _II1,
typename _II2>
1291 _GLIBCXX20_CONSTEXPR
1293 __newlast1(_II1, _II1 __last1, _II2, _II2)
1296 template<
typename _II>
1297 _GLIBCXX20_CONSTEXPR
1299 __cnd2(_II __first, _II __last)
1300 {
return __first != __last; }
1306 template<
typename _RAI1,
typename _RAI2>
1307 _GLIBCXX20_CONSTEXPR
1309 __newlast1(_RAI1 __first1, _RAI1 __last1,
1310 _RAI2 __first2, _RAI2 __last2)
1312 typedef typename iterator_traits<_RAI1>::difference_type _Diff1;
1313 typedef typename iterator_traits<_RAI2>::difference_type _Diff2;
1314 const _Diff1 __diff1 = __last1 - __first1;
1315 const _Diff2 __diff2 = __last2 - __first2;
1316 return __diff2 < __diff1 ? __first1 + _Diff1(__diff2) : __last1;
1319 template<
typename _RAI>
1320 static _GLIBCXX20_CONSTEXPR
bool
1325 template<
typename _II1,
typename _II2,
typename _Compare>
1326 _GLIBCXX20_CONSTEXPR
1328 __lexicographical_compare_impl(_II1 __first1, _II1 __last1,
1329 _II2 __first2, _II2 __last2,
1332 typedef __decltype(std::__iter_concept_or_category<_II1>()) _Category1;
1333 typedef __decltype(std::__iter_concept_or_category<_II2>()) _Category2;
1334 typedef std::__lc_rai<_Category1, _Category2> __rai_type;
1336 __last1 = __rai_type::__newlast1(__first1, __last1, __first2, __last2);
1337 for (; __first1 != __last1 && __rai_type::__cnd2(__first2, __last2);
1338 ++__first1, (
void)++__first2)
1340 if (__comp(*__first1, *__first2))
1342 if (__comp(*__first2, *__first1))
1345 return __first1 == __last1 && __first2 != __last2;
1348 template<
bool _BoolType>
1349 struct __lexicographical_compare
1351 template<
typename _II1,
typename _II2>
1352 _GLIBCXX20_CONSTEXPR
1354 __lc(_II1 __first1, _II1 __last1, _II2 __first2, _II2 __last2)
1356 using __gnu_cxx::__ops::less;
1357 return std::__lexicographical_compare_impl(__first1, __last1,
1362 template<
typename _II1,
typename _II2>
1363 _GLIBCXX20_CONSTEXPR
1365 __3way(_II1 __first1, _II1 __last1, _II2 __first2, _II2 __last2)
1367 while (__first1 != __last1)
1369 if (__first2 == __last2)
1371 if (*__first1 < *__first2)
1373 if (*__first2 < *__first1)
1378 return int(__first2 == __last2) - 1;
1383 struct __lexicographical_compare<true>
1385 template<
typename _Tp,
typename _Up>
1386 _GLIBCXX20_CONSTEXPR
1388 __lc(
const _Tp* __first1,
const _Tp* __last1,
1389 const _Up* __first2,
const _Up* __last2)
1390 {
return __3way(__first1, __last1, __first2, __last2) < 0; }
1392 template<
typename _Tp,
typename _Up>
1393 _GLIBCXX20_CONSTEXPR
1395 __3way(
const _Tp* __first1,
const _Tp* __last1,
1396 const _Up* __first2,
const _Up* __last2)
1398 const size_t __len1 = __last1 - __first1;
1399 const size_t __len2 = __last2 - __first2;
1400 if (
const size_t __len =
std::min(__len1, __len2))
1401 if (
int __result = std::__memcmp(__first1, __first2, __len))
1403 return ptrdiff_t(__len1 - __len2);
1407 template<
typename _II1,
typename _II2>
1408 _GLIBCXX20_CONSTEXPR
1410 __lexicographical_compare_aux1(_II1 __first1, _II1 __last1,
1411 _II2 __first2, _II2 __last2)
1415#if _GLIBCXX_USE_BUILTIN_TRAIT(__is_pointer)
1416 const bool __simple =
1417 (__is_memcmp_ordered_with<_ValueType1, _ValueType2>::__value
1418 && __is_pointer(_II1) && __is_pointer(_II2)
1419#if __cplusplus > 201703L && __glibcxx_concepts
1423 && !is_volatile_v<remove_reference_t<iter_reference_t<_II1>>>
1424 && !is_volatile_v<remove_reference_t<iter_reference_t<_II2>>>
1428 const bool __simple =
false;
1431 return std::__lexicographical_compare<__simple>::__lc(__first1, __last1,
1435 template<
typename _Tp1,
typename _Ref1,
typename _Ptr1,
1438 __lexicographical_compare_aux1(
1439 _GLIBCXX_STD_C::_Deque_iterator<_Tp1, _Ref1, _Ptr1>,
1440 _GLIBCXX_STD_C::_Deque_iterator<_Tp1, _Ref1, _Ptr1>,
1443 template<
typename _Tp1,
1444 typename _Tp2,
typename _Ref2,
typename _Ptr2>
1446 __lexicographical_compare_aux1(_Tp1*, _Tp1*,
1447 _GLIBCXX_STD_C::_Deque_iterator<_Tp2, _Ref2, _Ptr2>,
1448 _GLIBCXX_STD_C::_Deque_iterator<_Tp2, _Ref2, _Ptr2>);
1450 template<
typename _Tp1,
typename _Ref1,
typename _Ptr1,
1451 typename _Tp2,
typename _Ref2,
typename _Ptr2>
1453 __lexicographical_compare_aux1(
1454 _GLIBCXX_STD_C::_Deque_iterator<_Tp1, _Ref1, _Ptr1>,
1455 _GLIBCXX_STD_C::_Deque_iterator<_Tp1, _Ref1, _Ptr1>,
1456 _GLIBCXX_STD_C::_Deque_iterator<_Tp2, _Ref2, _Ptr2>,
1457 _GLIBCXX_STD_C::_Deque_iterator<_Tp2, _Ref2, _Ptr2>);
1459 template<
typename _II1,
typename _II2>
1460 _GLIBCXX20_CONSTEXPR
1462 __lexicographical_compare_aux(_II1 __first1, _II1 __last1,
1463 _II2 __first2, _II2 __last2)
1465 return std::__lexicographical_compare_aux1(std::__niter_base(__first1),
1466 std::__niter_base(__last1),
1467 std::__niter_base(__first2),
1468 std::__niter_base(__last2));
1471 template<
typename _Iter1,
typename _Seq1,
typename _Cat1,
1473 _GLIBCXX20_CONSTEXPR
1475 __lexicographical_compare_aux(
1476 const ::__gnu_debug::_Safe_iterator<_Iter1, _Seq1, _Cat1>&,
1477 const ::__gnu_debug::_Safe_iterator<_Iter1, _Seq1, _Cat1>&,
1480 template<
typename _II1,
1481 typename _Iter2,
typename _Seq2,
typename _Cat2>
1482 _GLIBCXX20_CONSTEXPR
1484 __lexicographical_compare_aux(
1486 const ::__gnu_debug::_Safe_iterator<_Iter2, _Seq2, _Cat2>&,
1487 const ::__gnu_debug::_Safe_iterator<_Iter2, _Seq2, _Cat2>&);
1489 template<
typename _Iter1,
typename _Seq1,
typename _Cat1,
1490 typename _Iter2,
typename _Seq2,
typename _Cat2>
1491 _GLIBCXX20_CONSTEXPR
1493 __lexicographical_compare_aux(
1494 const ::__gnu_debug::_Safe_iterator<_Iter1, _Seq1, _Cat1>&,
1495 const ::__gnu_debug::_Safe_iterator<_Iter1, _Seq1, _Cat1>&,
1496 const ::__gnu_debug::_Safe_iterator<_Iter2, _Seq2, _Cat2>&,
1497 const ::__gnu_debug::_Safe_iterator<_Iter2, _Seq2, _Cat2>&);
1499 template<
typename _ForwardIterator,
typename _Tp,
typename _Compare>
1500 _GLIBCXX20_CONSTEXPR
1502 __lower_bound(_ForwardIterator __first, _ForwardIterator __last,
1503 const _Tp& __val, _Compare __comp)
1512 _DistanceType __half = __len >> 1;
1513 _ForwardIterator __middle = __first;
1515 if (__comp(*__middle, __val))
1519 __len = __len - __half - 1;
1538 template<
typename _ForwardIterator,
typename _Tp>
1539 _GLIBCXX_NODISCARD _GLIBCXX20_CONSTEXPR
1540 inline _ForwardIterator
1541 lower_bound(_ForwardIterator __first, _ForwardIterator __last,
1545 __glibcxx_function_requires(_ForwardIteratorConcept<_ForwardIterator>)
1546 __glibcxx_function_requires(_LessThanOpConcept<
1548 __glibcxx_requires_partitioned_lower(__first, __last, __val);
1550 return std::__lower_bound(__first, __last, __val,
1551 __gnu_cxx::__ops::less());
1556 template<
typename _Tp>
1557 inline _GLIBCXX_CONSTEXPR _Tp
1560#if __cplusplus >= 201402L
1563#pragma GCC diagnostic push
1564#pragma GCC diagnostic ignored "-Wlong-long"
1566 return (
sizeof(+__n) * __CHAR_BIT__ - 1)
1567 - (
sizeof(+__n) ==
sizeof(
long long)
1568 ? __builtin_clzll(+__n)
1569 : (
sizeof(+__n) ==
sizeof(long)
1570 ? __builtin_clzl(+__n)
1571 : __builtin_clz(+__n)));
1572#pragma GCC diagnostic pop
1576_GLIBCXX_BEGIN_NAMESPACE_ALGO
1590 template<
typename _II1,
typename _II2>
1591 _GLIBCXX_NODISCARD _GLIBCXX20_CONSTEXPR
1593 equal(_II1 __first1, _II1 __last1, _II2 __first2)
1596 __glibcxx_function_requires(_InputIteratorConcept<_II1>)
1597 __glibcxx_function_requires(_InputIteratorConcept<_II2>)
1598 __glibcxx_function_requires(_EqualOpConcept<
1601 __glibcxx_requires_can_increment_range(__first1, __last1, __first2);
1603 return std::__equal_aux(__first1, __last1, __first2);
1621 template<
typename _IIter1,
typename _IIter2,
typename _BinaryPredicate>
1622 _GLIBCXX_NODISCARD _GLIBCXX20_CONSTEXPR
1624 equal(_IIter1 __first1, _IIter1 __last1,
1625 _IIter2 __first2, _BinaryPredicate __binary_pred)
1628 __glibcxx_function_requires(_InputIteratorConcept<_IIter1>)
1629 __glibcxx_function_requires(_InputIteratorConcept<_IIter2>)
1630 __glibcxx_requires_valid_range(__first1, __last1);
1632 for (; __first1 != __last1; ++__first1, (void)++__first2)
1633 if (!
bool(__binary_pred(*__first1, *__first2)))
1638#if __cplusplus >= 201103L
1639#pragma GCC diagnostic push
1640#pragma GCC diagnostic ignored "-Wc++17-extensions"
1643 template<
typename _II1,
typename _II2>
1644 _GLIBCXX20_CONSTEXPR
1646 __equal4(_II1 __first1, _II1 __last1, _II2 __first2, _II2 __last2)
1648 using _RATag = random_access_iterator_tag;
1649 using _Cat1 =
decltype(std::__iter_concept_or_category<_II1>());
1650 using _Cat2 =
decltype(std::__iter_concept_or_category<_II2>());
1651 using _RAIters = __and_<is_same<_Cat1, _RATag>, is_same<_Cat2, _RATag>>;
1652 if constexpr (_RAIters::value)
1654 if ((__last1 - __first1) != (__last2 - __first2))
1656 return _GLIBCXX_STD_A::equal(__first1, __last1, __first2);
1660 for (; __first1 != __last1 && __first2 != __last2;
1661 ++__first1, (void)++__first2)
1662 if (!(*__first1 == *__first2))
1664 return __first1 == __last1 && __first2 == __last2;
1669 template<
typename _II1,
typename _II2,
typename _BinaryPredicate>
1670 _GLIBCXX20_CONSTEXPR
1672 __equal4(_II1 __first1, _II1 __last1, _II2 __first2, _II2 __last2,
1673 _BinaryPredicate __binary_pred)
1676 using _Cat1 =
decltype(std::__iter_concept_or_category<_II1>());
1677 using _Cat2 =
decltype(std::__iter_concept_or_category<_II2>());
1679 if constexpr (_RAIters::value)
1681 if ((__last1 - __first1) != (__last2 - __first2))
1683 return _GLIBCXX_STD_A::equal(__first1, __last1, __first2,
1688 for (; __first1 != __last1 && __first2 != __last2;
1689 ++__first1, (void)++__first2)
1690 if (!
bool(__binary_pred(*__first1, *__first2)))
1692 return __first1 == __last1 && __first2 == __last2;
1695#pragma GCC diagnostic pop
1698#ifdef __glibcxx_robust_nonmodifying_seq_ops
1712 template<
typename _II1,
typename _II2>
1713 _GLIBCXX_NODISCARD _GLIBCXX20_CONSTEXPR
1715 equal(_II1 __first1, _II1 __last1, _II2 __first2, _II2 __last2)
1718 __glibcxx_function_requires(_InputIteratorConcept<_II1>)
1719 __glibcxx_function_requires(_InputIteratorConcept<_II2>)
1720 __glibcxx_function_requires(_EqualOpConcept<
1723 __glibcxx_requires_valid_range(__first1, __last1);
1724 __glibcxx_requires_valid_range(__first2, __last2);
1726 return _GLIBCXX_STD_A::__equal4(__first1, __last1, __first2, __last2);
1745 template<
typename _IIter1,
typename _IIter2,
typename _BinaryPredicate>
1746 _GLIBCXX_NODISCARD _GLIBCXX20_CONSTEXPR
1748 equal(_IIter1 __first1, _IIter1 __last1,
1749 _IIter2 __first2, _IIter2 __last2, _BinaryPredicate __binary_pred)
1752 __glibcxx_function_requires(_InputIteratorConcept<_IIter1>)
1753 __glibcxx_function_requires(_InputIteratorConcept<_IIter2>)
1754 __glibcxx_requires_valid_range(__first1, __last1);
1755 __glibcxx_requires_valid_range(__first2, __last2);
1757 return _GLIBCXX_STD_A::__equal4(__first1, __last1, __first2, __last2,
1777 template<
typename _II1,
typename _II2>
1778 _GLIBCXX_NODISCARD _GLIBCXX20_CONSTEXPR
1780 lexicographical_compare(_II1 __first1, _II1 __last1,
1781 _II2 __first2, _II2 __last2)
1783#ifdef _GLIBCXX_CONCEPT_CHECKS
1788 __glibcxx_function_requires(_InputIteratorConcept<_II1>)
1789 __glibcxx_function_requires(_InputIteratorConcept<_II2>)
1790 __glibcxx_function_requires(_LessThanOpConcept<_ValueType1, _ValueType2>)
1791 __glibcxx_function_requires(_LessThanOpConcept<_ValueType2, _ValueType1>)
1792 __glibcxx_requires_valid_range(__first1, __last1);
1793 __glibcxx_requires_valid_range(__first2, __last2);
1795 return std::__lexicographical_compare_aux(__first1, __last1,
1812 template<
typename _II1,
typename _II2,
typename _Compare>
1813 _GLIBCXX_NODISCARD _GLIBCXX20_CONSTEXPR
1815 lexicographical_compare(_II1 __first1, _II1 __last1,
1816 _II2 __first2, _II2 __last2, _Compare __comp)
1819 __glibcxx_function_requires(_InputIteratorConcept<_II1>)
1820 __glibcxx_function_requires(_InputIteratorConcept<_II2>)
1821 __glibcxx_requires_valid_range(__first1, __last1);
1822 __glibcxx_requires_valid_range(__first2, __last2);
1824 return std::__lexicographical_compare_impl
1825 (__first1, __last1, __first2, __last2, __comp);
1828#if __cpp_lib_three_way_comparison
1832 template<
typename _Iter1,
typename _Iter2>
1833 concept __memcmp_ordered_with
1834 = (__is_memcmp_ordered_with<iter_value_t<_Iter1>,
1835 iter_value_t<_Iter2>>::__value)
1836 && contiguous_iterator<_Iter1> && contiguous_iterator<_Iter2>;
1840 template<
typename _Tp>
1842 __min_cmp(_Tp __x, _Tp __y)
1846 decltype(__x <=> __y) _M_cmp;
1848 auto __c = __x <=> __y;
1850 return _Res{__y, __c};
1851 return _Res{__x, __c};
1865 template<
typename _InputIter1,
typename _InputIter2,
typename _Comp>
1866 [[nodiscard]]
constexpr auto
1868 _InputIter1 __last1,
1869 _InputIter2 __first2,
1870 _InputIter2 __last2,
1872 ->
decltype(__comp(*__first1, *__first2))
1875 __glibcxx_function_requires(_InputIteratorConcept<_InputIter1>)
1876 __glibcxx_function_requires(_InputIteratorConcept<_InputIter2>)
1877 __glibcxx_requires_valid_range(__first1, __last1);
1878 __glibcxx_requires_valid_range(__first2, __last2);
1880 using _Cat =
decltype(__comp(*__first1, *__first2));
1883 if (!std::__is_constant_evaluated())
1886 if constexpr (__memcmp_ordered_with<_InputIter1, _InputIter2>)
1888 const auto [__len, __lencmp] = _GLIBCXX_STD_A::
1889 __min_cmp(__last1 - __first1, __last2 - __first2);
1892 const auto __blen = __len *
sizeof(*__first1);
1894 = __builtin_memcmp(&*__first1, &*__first2, __blen) <=> 0;
1901 while (__first1 != __last1)
1903 if (__first2 == __last2)
1904 return strong_ordering::greater;
1905 if (
auto __cmp = __comp(*__first1, *__first2); __cmp != 0)
1910 return (__first2 == __last2) <=>
true;
1913 template<
typename _InputIter1,
typename _InputIter2>
1916 _InputIter1 __last1,
1917 _InputIter2 __first2,
1918 _InputIter2 __last2)
1920 return _GLIBCXX_STD_A::
1921 lexicographical_compare_three_way(__first1, __last1, __first2, __last2,
1922 compare_three_way{});
1926 template<
typename _InputIterator1,
typename _InputIterator2,
1927 typename _BinaryPredicate>
1928 _GLIBCXX20_CONSTEXPR
1930 __mismatch(_InputIterator1 __first1, _InputIterator1 __last1,
1931 _InputIterator2 __first2, _BinaryPredicate __binary_pred)
1933 while (__first1 != __last1 &&
bool(__binary_pred(*__first1, *__first2)))
1954 template<
typename _InputIterator1,
typename _InputIterator2>
1955 _GLIBCXX_NODISCARD _GLIBCXX20_CONSTEXPR
1957 mismatch(_InputIterator1 __first1, _InputIterator1 __last1,
1958 _InputIterator2 __first2)
1961 __glibcxx_function_requires(_InputIteratorConcept<_InputIterator1>)
1962 __glibcxx_function_requires(_InputIteratorConcept<_InputIterator2>)
1963 __glibcxx_function_requires(_EqualOpConcept<
1966 __glibcxx_requires_valid_range(__first1, __last1);
1968 return _GLIBCXX_STD_A::__mismatch(__first1, __last1, __first2,
1969 __gnu_cxx::__ops::equal_to());
1988 template<
typename _InputIterator1,
typename _InputIterator2,
1989 typename _BinaryPredicate>
1990 _GLIBCXX_NODISCARD _GLIBCXX20_CONSTEXPR
1992 mismatch(_InputIterator1 __first1, _InputIterator1 __last1,
1993 _InputIterator2 __first2, _BinaryPredicate __binary_pred)
1996 __glibcxx_function_requires(_InputIteratorConcept<_InputIterator1>)
1997 __glibcxx_function_requires(_InputIteratorConcept<_InputIterator2>)
1998 __glibcxx_requires_valid_range(__first1, __last1);
2000 return _GLIBCXX_STD_A::__mismatch(__first1, __last1, __first2,
2004#if __glibcxx_robust_nonmodifying_seq_ops
2005 template<
typename _InputIterator1,
typename _InputIterator2,
2006 typename _BinaryPredicate>
2007 _GLIBCXX20_CONSTEXPR
2009 __mismatch(_InputIterator1 __first1, _InputIterator1 __last1,
2010 _InputIterator2 __first2, _InputIterator2 __last2,
2011 _BinaryPredicate __binary_pred)
2013 while (__first1 != __last1 && __first2 != __last2
2014 &&
bool(__binary_pred(*__first1, *__first2)))
2036 template<
typename _InputIterator1,
typename _InputIterator2>
2037 _GLIBCXX_NODISCARD _GLIBCXX20_CONSTEXPR
2039 mismatch(_InputIterator1 __first1, _InputIterator1 __last1,
2040 _InputIterator2 __first2, _InputIterator2 __last2)
2043 __glibcxx_function_requires(_InputIteratorConcept<_InputIterator1>)
2044 __glibcxx_function_requires(_InputIteratorConcept<_InputIterator2>)
2045 __glibcxx_function_requires(_EqualOpConcept<
2048 __glibcxx_requires_valid_range(__first1, __last1);
2049 __glibcxx_requires_valid_range(__first2, __last2);
2051 return _GLIBCXX_STD_A::__mismatch(__first1, __last1, __first2, __last2,
2052 __gnu_cxx::__ops::equal_to());
2072 template<
typename _InputIterator1,
typename _InputIterator2,
2073 typename _BinaryPredicate>
2074 _GLIBCXX_NODISCARD _GLIBCXX20_CONSTEXPR
2076 mismatch(_InputIterator1 __first1, _InputIterator1 __last1,
2077 _InputIterator2 __first2, _InputIterator2 __last2,
2078 _BinaryPredicate __binary_pred)
2081 __glibcxx_function_requires(_InputIteratorConcept<_InputIterator1>)
2082 __glibcxx_function_requires(_InputIteratorConcept<_InputIterator2>)
2083 __glibcxx_requires_valid_range(__first1, __last1);
2084 __glibcxx_requires_valid_range(__first2, __last2);
2086 return _GLIBCXX_STD_A::__mismatch(__first1, __last1, __first2, __last2,
2091_GLIBCXX_END_NAMESPACE_ALGO
2094 template<
typename _Iterator,
typename _Predicate>
2095 _GLIBCXX20_CONSTEXPR
2097 __find_if(_Iterator __first, _Iterator __last, _Predicate __pred)
2100 while (__first != __last && !
bool(__pred(*__first)))
2105 template<
typename _InputIterator,
typename _Predicate>
2106 _GLIBCXX20_CONSTEXPR
2108 __count_if(_InputIterator __first, _InputIterator __last, _Predicate __pred)
2111 for (; __first != __last; ++__first)
2112 if (__pred(*__first))
2117 template<
typename _ForwardIterator,
typename _Predicate>
2118 _GLIBCXX20_CONSTEXPR
2120 __remove_if(_ForwardIterator __first, _ForwardIterator __last,
2123 __first = std::__find_if(__first, __last, __pred);
2124 if (__first == __last)
2126 _ForwardIterator __result = __first;
2128 for (; __first != __last; ++__first)
2129 if (!__pred(*__first))
2131 *__result = _GLIBCXX_MOVE(*__first);
2137 template<
typename _ForwardIterator1,
typename _ForwardIterator2,
2138 typename _BinaryPredicate>
2139 _GLIBCXX20_CONSTEXPR
2141 __search(_ForwardIterator1 __first1, _ForwardIterator1 __last1,
2142 _ForwardIterator2 __first2, _ForwardIterator2 __last2,
2143 _BinaryPredicate __predicate)
2146 if (__first1 == __last1 || __first2 == __last2)
2149 __decltype(*__first2) __first2_val(*__first2);
2150 __decltype(__gnu_cxx::__ops::bind2nd(__predicate, __first2_val))
2151 __match_first = __gnu_cxx::__ops::bind2nd(__predicate, __first2_val);
2154 _ForwardIterator2 __p1(__first2);
2155 if (++__p1 == __last2)
2156 return std::__find_if(__first1, __last1, __match_first);
2159 _ForwardIterator1 __current = __first1;
2163 __first1 = std::__find_if(__first1, __last1, __match_first);
2165 if (__first1 == __last1)
2168 _ForwardIterator2 __p = __p1;
2169 __current = __first1;
2170 if (++__current == __last1)
2173 while (__predicate(*__current, *__p))
2175 if (++__p == __last2)
2177 if (++__current == __last1)
2186#if __cplusplus >= 201103L
2187 template<
typename _ForwardIterator1,
typename _ForwardIterator2,
2188 typename _BinaryPredicate>
2189 _GLIBCXX20_CONSTEXPR
2191 __is_permutation(_ForwardIterator1 __first1, _ForwardIterator1 __last1,
2192 _ForwardIterator2 __first2, _BinaryPredicate __pred)
2196 for (; __first1 != __last1; ++__first1, (void)++__first2)
2197 if (!__pred(*__first1, *__first2))
2200 if (__first1 == __last1)
2205 _ForwardIterator2 __last2 = __first2;
2207 for (_ForwardIterator1 __scan = __first1; __scan != __last1; ++__scan)
2209 auto&& __scan_val = *__scan;
2210 auto __scaneq = __gnu_cxx::__ops::bind1st(__pred, __scan_val);
2211 if (__scan != std::__find_if(__first1, __scan, __scaneq))
2214 auto __matches = std::__count_if(__first2, __last2, __scaneq);
2216 || std::__count_if(__scan, __last1, __scaneq) != __matches)
2234 template<
typename _ForwardIterator1,
typename _ForwardIterator2>
2235 _GLIBCXX20_CONSTEXPR
2237 is_permutation(_ForwardIterator1 __first1, _ForwardIterator1 __last1,
2238 _ForwardIterator2 __first2)
2241 __glibcxx_function_requires(_ForwardIteratorConcept<_ForwardIterator1>)
2242 __glibcxx_function_requires(_ForwardIteratorConcept<_ForwardIterator2>)
2243 __glibcxx_function_requires(_EqualOpConcept<
2246 __glibcxx_requires_valid_range(__first1, __last1);
2248 return std::__is_permutation(__first1, __last1, __first2,
2249 __gnu_cxx::__ops::equal_to());
2253_GLIBCXX_BEGIN_NAMESPACE_ALGO
2276 template<
typename _ForwardIterator1,
typename _ForwardIterator2,
2277 typename _BinaryPredicate>
2278 _GLIBCXX20_CONSTEXPR
2279 inline _ForwardIterator1
2280 search(_ForwardIterator1 __first1, _ForwardIterator1 __last1,
2281 _ForwardIterator2 __first2, _ForwardIterator2 __last2,
2282 _BinaryPredicate __predicate)
2285 __glibcxx_function_requires(_ForwardIteratorConcept<_ForwardIterator1>)
2286 __glibcxx_function_requires(_ForwardIteratorConcept<_ForwardIterator2>)
2287 __glibcxx_function_requires(_BinaryPredicateConcept<_BinaryPredicate,
2290 __glibcxx_requires_valid_range(__first1, __last1);
2291 __glibcxx_requires_valid_range(__first2, __last2);
2293 return std::__search(__first1, __last1, __first2, __last2, __predicate);
2296_GLIBCXX_END_NAMESPACE_ALGO
2297_GLIBCXX_END_NAMESPACE_VERSION
2303#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 (or references) of arbitrary type.
constexpr pair(const pair &)=default
Copy constructor.
Random-access iterators support a superset of bidirectional iterator operations.
[concept.same], concept same_as