56 #ifndef _STL_ALGOBASE_H 57 #define _STL_ALGOBASE_H 1 73 namespace std _GLIBCXX_VISIBILITY(default)
75 _GLIBCXX_BEGIN_NAMESPACE_VERSION
77 #if __cplusplus < 201103L 81 template<
bool _BoolType>
84 template<
typename _ForwardIterator1,
typename _ForwardIterator2>
86 iter_swap(_ForwardIterator1 __a, _ForwardIterator2 __b)
88 typedef typename iterator_traits<_ForwardIterator1>::value_type
90 _ValueType1 __tmp = *__a;
97 struct __iter_swap<true>
99 template<
typename _ForwardIterator1,
typename _ForwardIterator2>
101 iter_swap(_ForwardIterator1 __a, _ForwardIterator2 __b)
118 template<
typename _ForwardIterator1,
typename _ForwardIterator2>
120 iter_swap(_ForwardIterator1 __a, _ForwardIterator2 __b)
123 __glibcxx_function_requires(_Mutable_ForwardIteratorConcept<
125 __glibcxx_function_requires(_Mutable_ForwardIteratorConcept<
128 #if __cplusplus < 201103L 129 typedef typename iterator_traits<_ForwardIterator1>::value_type
131 typedef typename iterator_traits<_ForwardIterator2>::value_type
134 __glibcxx_function_requires(_ConvertibleConcept<_ValueType1,
136 __glibcxx_function_requires(_ConvertibleConcept<_ValueType2,
139 typedef typename iterator_traits<_ForwardIterator1>::reference
141 typedef typename iterator_traits<_ForwardIterator2>::reference
143 std::__iter_swap<__are_same<_ValueType1, _ValueType2>::__value
144 && __are_same<_ValueType1&, _ReferenceType1>::__value
145 && __are_same<_ValueType2&, _ReferenceType2>::__value>::
164 template<
typename _ForwardIterator1,
typename _ForwardIterator2>
166 swap_ranges(_ForwardIterator1 __first1, _ForwardIterator1 __last1,
167 _ForwardIterator2 __first2)
170 __glibcxx_function_requires(_Mutable_ForwardIteratorConcept<
172 __glibcxx_function_requires(_Mutable_ForwardIteratorConcept<
174 __glibcxx_requires_valid_range(__first1, __last1);
176 for (; __first1 != __last1; ++__first1, (void)++__first2)
192 template<
typename _Tp>
195 min(
const _Tp& __a,
const _Tp& __b)
198 __glibcxx_function_requires(_LessThanComparableConcept<_Tp>)
216 template<
typename _Tp>
219 max(
const _Tp& __a,
const _Tp& __b)
222 __glibcxx_function_requires(_LessThanComparableConcept<_Tp>)
240 template<
typename _Tp,
typename _Compare>
243 min(
const _Tp& __a,
const _Tp& __b, _Compare __comp)
246 if (__comp(__b, __a))
262 template<
typename _Tp,
typename _Compare>
265 max(
const _Tp& __a,
const _Tp& __b, _Compare __comp)
268 if (__comp(__a, __b))
275 template<
typename _Iterator>
277 __niter_base(_Iterator __it)
286 template<
bool,
bool,
typename>
289 template<
typename _II,
typename _OI>
291 __copy_m(_II __first, _II __last, _OI __result)
293 for (; __first != __last; ++__result, (void)++__first)
294 *__result = *__first;
299 #if __cplusplus >= 201103L 300 template<
typename _Category>
301 struct __copy_move<true, false, _Category>
303 template<
typename _II,
typename _OI>
305 __copy_m(_II __first, _II __last, _OI __result)
307 for (; __first != __last; ++__result, (void)++__first)
308 *__result = std::move(*__first);
315 struct __copy_move<false, false, random_access_iterator_tag>
317 template<
typename _II,
typename _OI>
319 __copy_m(_II __first, _II __last, _OI __result)
321 typedef typename iterator_traits<_II>::difference_type _Distance;
322 for(_Distance __n = __last - __first; __n > 0; --__n)
324 *__result = *__first;
332 #if __cplusplus >= 201103L 334 struct __copy_move<true, false, random_access_iterator_tag>
336 template<
typename _II,
typename _OI>
338 __copy_m(_II __first, _II __last, _OI __result)
340 typedef typename iterator_traits<_II>::difference_type _Distance;
341 for(_Distance __n = __last - __first; __n > 0; --__n)
343 *__result = std::move(*__first);
352 template<
bool _IsMove>
353 struct __copy_move<_IsMove, true, random_access_iterator_tag>
355 template<
typename _Tp>
357 __copy_m(
const _Tp* __first,
const _Tp* __last, _Tp* __result)
359 #if __cplusplus >= 201103L 360 using __assignable = conditional<_IsMove,
361 is_move_assignable<_Tp>,
362 is_copy_assignable<_Tp>>;
364 static_assert( __assignable::type::value,
"type is not assignable" );
366 const ptrdiff_t _Num = __last - __first;
368 __builtin_memmove(__result, __first,
sizeof(_Tp) * _Num);
369 return __result + _Num;
373 template<
bool _IsMove,
typename _II,
typename _OI>
375 __copy_move_a(_II __first, _II __last, _OI __result)
377 typedef typename iterator_traits<_II>::value_type _ValueTypeI;
378 typedef typename iterator_traits<_OI>::value_type _ValueTypeO;
379 typedef typename iterator_traits<_II>::iterator_category _Category;
380 const bool __simple = (__is_trivial(_ValueTypeI)
381 && __is_pointer<_II>::__value
382 && __is_pointer<_OI>::__value
383 && __are_same<_ValueTypeI, _ValueTypeO>::__value);
385 return std::__copy_move<_IsMove, __simple,
386 _Category>::__copy_m(__first, __last, __result);
391 template<
typename _CharT>
394 template<
typename _CharT,
typename _Traits>
395 class istreambuf_iterator;
397 template<
typename _CharT,
typename _Traits>
398 class ostreambuf_iterator;
400 template<
bool _IsMove,
typename _CharT>
401 typename __gnu_cxx::__enable_if<__is_char<_CharT>::__value,
402 ostreambuf_iterator<_CharT, char_traits<_CharT> > >::__type
403 __copy_move_a2(_CharT*, _CharT*,
404 ostreambuf_iterator<_CharT, char_traits<_CharT> >);
406 template<
bool _IsMove,
typename _CharT>
407 typename __gnu_cxx::__enable_if<__is_char<_CharT>::__value,
408 ostreambuf_iterator<_CharT, char_traits<_CharT> > >::__type
409 __copy_move_a2(
const _CharT*,
const _CharT*,
410 ostreambuf_iterator<_CharT, char_traits<_CharT> >);
412 template<
bool _IsMove,
typename _CharT>
413 typename __gnu_cxx::__enable_if<__is_char<_CharT>::__value,
415 __copy_move_a2(istreambuf_iterator<_CharT, char_traits<_CharT> >,
416 istreambuf_iterator<_CharT, char_traits<_CharT> >, _CharT*);
418 template<
bool _IsMove,
typename _II,
typename _OI>
420 __copy_move_a2(_II __first, _II __last, _OI __result)
422 return _OI(std::__copy_move_a<_IsMove>(std::__niter_base(__first),
423 std::__niter_base(__last),
424 std::__niter_base(__result)));
444 template<
typename _II,
typename _OI>
446 copy(_II __first, _II __last, _OI __result)
449 __glibcxx_function_requires(_InputIteratorConcept<_II>)
450 __glibcxx_function_requires(_OutputIteratorConcept<_OI,
451 typename iterator_traits<_II>::value_type>)
452 __glibcxx_requires_valid_range(__first, __last);
454 return (std::__copy_move_a2<__is_move_iterator<_II>::__value>
455 (std::__miter_base(__first), std::__miter_base(__last),
459 #if __cplusplus >= 201103L 477 template<
typename _II,
typename _OI>
479 move(_II __first, _II __last, _OI __result)
482 __glibcxx_function_requires(_InputIteratorConcept<_II>)
483 __glibcxx_function_requires(_OutputIteratorConcept<_OI,
484 typename iterator_traits<_II>::value_type>)
485 __glibcxx_requires_valid_range(__first, __last);
487 return std::__copy_move_a2<true>(std::__miter_base(__first),
488 std::__miter_base(__last), __result);
491 #define _GLIBCXX_MOVE3(_Tp, _Up, _Vp) std::move(_Tp, _Up, _Vp) 493 #define _GLIBCXX_MOVE3(_Tp, _Up, _Vp) std::copy(_Tp, _Up, _Vp) 496 template<
bool,
bool,
typename>
497 struct __copy_move_backward
499 template<
typename _BI1,
typename _BI2>
501 __copy_move_b(_BI1 __first, _BI1 __last, _BI2 __result)
503 while (__first != __last)
504 *--__result = *--__last;
509 #if __cplusplus >= 201103L 510 template<
typename _Category>
511 struct __copy_move_backward<true, false, _Category>
513 template<
typename _BI1,
typename _BI2>
515 __copy_move_b(_BI1 __first, _BI1 __last, _BI2 __result)
517 while (__first != __last)
518 *--__result = std::move(*--__last);
525 struct __copy_move_backward<false, false, random_access_iterator_tag>
527 template<
typename _BI1,
typename _BI2>
529 __copy_move_b(_BI1 __first, _BI1 __last, _BI2 __result)
531 typename iterator_traits<_BI1>::difference_type __n;
532 for (__n = __last - __first; __n > 0; --__n)
533 *--__result = *--__last;
538 #if __cplusplus >= 201103L 540 struct __copy_move_backward<true, false, random_access_iterator_tag>
542 template<
typename _BI1,
typename _BI2>
544 __copy_move_b(_BI1 __first, _BI1 __last, _BI2 __result)
546 typename iterator_traits<_BI1>::difference_type __n;
547 for (__n = __last - __first; __n > 0; --__n)
548 *--__result = std::move(*--__last);
554 template<
bool _IsMove>
555 struct __copy_move_backward<_IsMove, true, random_access_iterator_tag>
557 template<
typename _Tp>
559 __copy_move_b(
const _Tp* __first,
const _Tp* __last, _Tp* __result)
561 #if __cplusplus >= 201103L 562 using __assignable = conditional<_IsMove,
563 is_move_assignable<_Tp>,
564 is_copy_assignable<_Tp>>;
566 static_assert( __assignable::type::value,
"type is not assignable" );
568 const ptrdiff_t _Num = __last - __first;
570 __builtin_memmove(__result - _Num, __first,
sizeof(_Tp) * _Num);
571 return __result - _Num;
575 template<
bool _IsMove,
typename _BI1,
typename _BI2>
577 __copy_move_backward_a(_BI1 __first, _BI1 __last, _BI2 __result)
579 typedef typename iterator_traits<_BI1>::value_type _ValueType1;
580 typedef typename iterator_traits<_BI2>::value_type _ValueType2;
581 typedef typename iterator_traits<_BI1>::iterator_category _Category;
582 const bool __simple = (__is_trivial(_ValueType1)
583 && __is_pointer<_BI1>::__value
584 && __is_pointer<_BI2>::__value
585 && __are_same<_ValueType1, _ValueType2>::__value);
587 return std::__copy_move_backward<_IsMove, __simple,
588 _Category>::__copy_move_b(__first,
593 template<
bool _IsMove,
typename _BI1,
typename _BI2>
595 __copy_move_backward_a2(_BI1 __first, _BI1 __last, _BI2 __result)
597 return _BI2(std::__copy_move_backward_a<_IsMove>
598 (std::__niter_base(__first), std::__niter_base(__last),
599 std::__niter_base(__result)));
620 template<
typename _BI1,
typename _BI2>
622 copy_backward(_BI1 __first, _BI1 __last, _BI2 __result)
625 __glibcxx_function_requires(_BidirectionalIteratorConcept<_BI1>)
626 __glibcxx_function_requires(_Mutable_BidirectionalIteratorConcept<_BI2>)
627 __glibcxx_function_requires(_ConvertibleConcept<
628 typename iterator_traits<_BI1>::value_type,
629 typename iterator_traits<_BI2>::value_type>)
630 __glibcxx_requires_valid_range(__first, __last);
632 return (std::__copy_move_backward_a2<__is_move_iterator<_BI1>::__value>
633 (std::__miter_base(__first), std::__miter_base(__last),
637 #if __cplusplus >= 201103L 656 template<
typename _BI1,
typename _BI2>
658 move_backward(_BI1 __first, _BI1 __last, _BI2 __result)
661 __glibcxx_function_requires(_BidirectionalIteratorConcept<_BI1>)
662 __glibcxx_function_requires(_Mutable_BidirectionalIteratorConcept<_BI2>)
663 __glibcxx_function_requires(_ConvertibleConcept<
664 typename iterator_traits<_BI1>::value_type,
665 typename iterator_traits<_BI2>::value_type>)
666 __glibcxx_requires_valid_range(__first, __last);
668 return std::__copy_move_backward_a2<true>(std::__miter_base(__first),
669 std::__miter_base(__last),
673 #define _GLIBCXX_MOVE_BACKWARD3(_Tp, _Up, _Vp) std::move_backward(_Tp, _Up, _Vp) 675 #define _GLIBCXX_MOVE_BACKWARD3(_Tp, _Up, _Vp) std::copy_backward(_Tp, _Up, _Vp) 678 template<
typename _ForwardIterator,
typename _Tp>
680 __gnu_cxx::__enable_if<!__is_scalar<_Tp>::__value,
void>::__type
681 __fill_a(_ForwardIterator __first, _ForwardIterator __last,
684 for (; __first != __last; ++__first)
688 template<
typename _ForwardIterator,
typename _Tp>
690 __gnu_cxx::__enable_if<__is_scalar<_Tp>::__value,
void>::__type
691 __fill_a(_ForwardIterator __first, _ForwardIterator __last,
694 const _Tp __tmp = __value;
695 for (; __first != __last; ++__first)
700 template<
typename _Tp>
702 __gnu_cxx::__enable_if<__is_byte<_Tp>::__value,
void>::__type
703 __fill_a(_Tp* __first, _Tp* __last,
const _Tp& __c)
705 const _Tp __tmp = __c;
706 if (
const size_t __len = __last - __first)
707 __builtin_memset(__first, static_cast<unsigned char>(__tmp), __len);
722 template<
typename _ForwardIterator,
typename _Tp>
724 fill(_ForwardIterator __first, _ForwardIterator __last,
const _Tp& __value)
727 __glibcxx_function_requires(_Mutable_ForwardIteratorConcept<
729 __glibcxx_requires_valid_range(__first, __last);
731 std::__fill_a(std::__niter_base(__first), std::__niter_base(__last),
735 template<
typename _OutputIterator,
typename _Size,
typename _Tp>
737 __gnu_cxx::__enable_if<!__is_scalar<_Tp>::__value, _OutputIterator>::__type
738 __fill_n_a(_OutputIterator __first, _Size __n,
const _Tp& __value)
740 for (__decltype(__n + 0) __niter = __n;
741 __niter > 0; --__niter, (void) ++__first)
746 template<
typename _OutputIterator,
typename _Size,
typename _Tp>
748 __gnu_cxx::__enable_if<__is_scalar<_Tp>::__value, _OutputIterator>::__type
749 __fill_n_a(_OutputIterator __first, _Size __n,
const _Tp& __value)
751 const _Tp __tmp = __value;
752 for (__decltype(__n + 0) __niter = __n;
753 __niter > 0; --__niter, (void) ++__first)
758 template<
typename _Size,
typename _Tp>
760 __gnu_cxx::__enable_if<__is_byte<_Tp>::__value, _Tp*>::__type
761 __fill_n_a(_Tp* __first, _Size __n,
const _Tp& __c)
763 std::__fill_a(__first, __first + __n, __c);
764 return __first + __n;
782 template<
typename _OI,
typename _Size,
typename _Tp>
784 fill_n(_OI __first, _Size __n,
const _Tp& __value)
787 __glibcxx_function_requires(_OutputIteratorConcept<_OI, _Tp>)
789 return _OI(std::__fill_n_a(std::__niter_base(__first), __n, __value));
792 template<
bool _BoolType>
795 template<
typename _II1,
typename _II2>
797 equal(_II1 __first1, _II1 __last1, _II2 __first2)
799 for (; __first1 != __last1; ++__first1, (void) ++__first2)
800 if (!(*__first1 == *__first2))
809 template<
typename _Tp>
811 equal(
const _Tp* __first1,
const _Tp* __last1,
const _Tp* __first2)
813 if (
const size_t __len = (__last1 - __first1))
814 return !__builtin_memcmp(__first1, __first2,
sizeof(_Tp) * __len);
819 template<
typename _II1,
typename _II2>
821 __equal_aux(_II1 __first1, _II1 __last1, _II2 __first2)
823 typedef typename iterator_traits<_II1>::value_type _ValueType1;
824 typedef typename iterator_traits<_II2>::value_type _ValueType2;
825 const bool __simple = ((__is_integer<_ValueType1>::__value
826 || __is_pointer<_ValueType1>::__value)
827 && __is_pointer<_II1>::__value
828 && __is_pointer<_II2>::__value
829 && __are_same<_ValueType1, _ValueType2>::__value);
834 template<
typename,
typename>
837 template<
typename _II1,
typename _II2>
839 __newlast1(_II1, _II1 __last1, _II2, _II2)
842 template<
typename _II>
844 __cnd2(_II __first, _II __last)
845 {
return __first != __last; }
849 struct __lc_rai<random_access_iterator_tag, random_access_iterator_tag>
851 template<
typename _RAI1,
typename _RAI2>
853 __newlast1(_RAI1 __first1, _RAI1 __last1,
854 _RAI2 __first2, _RAI2 __last2)
856 const typename iterator_traits<_RAI1>::difference_type
857 __diff1 = __last1 - __first1;
858 const typename iterator_traits<_RAI2>::difference_type
859 __diff2 = __last2 - __first2;
860 return __diff2 < __diff1 ? __first1 + __diff2 : __last1;
863 template<
typename _RAI>
869 template<
typename _II1,
typename _II2,
typename _Compare>
871 __lexicographical_compare_impl(_II1 __first1, _II1 __last1,
872 _II2 __first2, _II2 __last2,
875 typedef typename iterator_traits<_II1>::iterator_category _Category1;
876 typedef typename iterator_traits<_II2>::iterator_category _Category2;
877 typedef std::__lc_rai<_Category1, _Category2> __rai_type;
879 __last1 = __rai_type::__newlast1(__first1, __last1, __first2, __last2);
880 for (; __first1 != __last1 && __rai_type::__cnd2(__first2, __last2);
881 ++__first1, (void)++__first2)
883 if (__comp(__first1, __first2))
885 if (__comp(__first2, __first1))
888 return __first1 == __last1 && __first2 != __last2;
891 template<
bool _BoolType>
892 struct __lexicographical_compare
894 template<
typename _II1,
typename _II2>
895 static bool __lc(_II1, _II1, _II2, _II2);
898 template<
bool _BoolType>
899 template<
typename _II1,
typename _II2>
901 __lexicographical_compare<_BoolType>::
902 __lc(_II1 __first1, _II1 __last1, _II2 __first2, _II2 __last2)
904 return std::__lexicographical_compare_impl(__first1, __last1,
906 __gnu_cxx::__ops::__iter_less_iter());
910 struct __lexicographical_compare<true>
912 template<
typename _Tp,
typename _Up>
914 __lc(
const _Tp* __first1,
const _Tp* __last1,
915 const _Up* __first2,
const _Up* __last2)
917 const size_t __len1 = __last1 - __first1;
918 const size_t __len2 = __last2 - __first2;
919 if (
const size_t __len =
std::min(__len1, __len2))
920 if (
int __result = __builtin_memcmp(__first1, __first2, __len))
922 return __len1 < __len2;
926 template<
typename _II1,
typename _II2>
928 __lexicographical_compare_aux(_II1 __first1, _II1 __last1,
929 _II2 __first2, _II2 __last2)
931 typedef typename iterator_traits<_II1>::value_type _ValueType1;
932 typedef typename iterator_traits<_II2>::value_type _ValueType2;
933 const bool __simple =
934 (__is_byte<_ValueType1>::__value && __is_byte<_ValueType2>::__value
935 && !__gnu_cxx::__numeric_traits<_ValueType1>::__is_signed
936 && !__gnu_cxx::__numeric_traits<_ValueType2>::__is_signed
937 && __is_pointer<_II1>::__value
938 && __is_pointer<_II2>::__value);
940 return std::__lexicographical_compare<__simple>::__lc(__first1, __last1,
944 template<
typename _ForwardIterator,
typename _Tp,
typename _Compare>
946 __lower_bound(_ForwardIterator __first, _ForwardIterator __last,
947 const _Tp& __val, _Compare __comp)
949 typedef typename iterator_traits<_ForwardIterator>::difference_type
956 _DistanceType __half = __len >> 1;
957 _ForwardIterator __middle = __first;
959 if (__comp(__middle, __val))
963 __len = __len - __half - 1;
982 template<
typename _ForwardIterator,
typename _Tp>
983 inline _ForwardIterator
984 lower_bound(_ForwardIterator __first, _ForwardIterator __last,
988 __glibcxx_function_requires(_ForwardIteratorConcept<_ForwardIterator>)
989 __glibcxx_function_requires(_LessThanOpConcept<
990 typename iterator_traits<_ForwardIterator>::value_type, _Tp>)
991 __glibcxx_requires_partitioned_lower(__first, __last, __val);
993 return std::__lower_bound(__first, __last, __val,
994 __gnu_cxx::__ops::__iter_less_val());
999 inline _GLIBCXX_CONSTEXPR
int 1001 {
return (
int)
sizeof(int) * __CHAR_BIT__ - 1 - __builtin_clz(__n); }
1003 inline _GLIBCXX_CONSTEXPR
unsigned 1005 {
return (
int)
sizeof(int) * __CHAR_BIT__ - 1 - __builtin_clz(__n); }
1007 inline _GLIBCXX_CONSTEXPR
long 1009 {
return (
int)
sizeof(long) * __CHAR_BIT__ - 1 - __builtin_clzl(__n); }
1011 inline _GLIBCXX_CONSTEXPR
unsigned long 1012 __lg(
unsigned long __n)
1013 {
return (
int)
sizeof(long) * __CHAR_BIT__ - 1 - __builtin_clzl(__n); }
1015 inline _GLIBCXX_CONSTEXPR
long long 1017 {
return (
int)
sizeof(
long long) * __CHAR_BIT__ - 1 - __builtin_clzll(__n); }
1019 inline _GLIBCXX_CONSTEXPR
unsigned long long 1020 __lg(
unsigned long long __n)
1021 {
return (
int)
sizeof(
long long) * __CHAR_BIT__ - 1 - __builtin_clzll(__n); }
1023 _GLIBCXX_BEGIN_NAMESPACE_ALGO
1037 template<
typename _II1,
typename _II2>
1039 equal(_II1 __first1, _II1 __last1, _II2 __first2)
1042 __glibcxx_function_requires(_InputIteratorConcept<_II1>)
1043 __glibcxx_function_requires(_InputIteratorConcept<_II2>)
1044 __glibcxx_function_requires(_EqualOpConcept<
1045 typename iterator_traits<_II1>::value_type,
1046 typename iterator_traits<_II2>::value_type>)
1047 __glibcxx_requires_valid_range(__first1, __last1);
1049 return std::__equal_aux(std::__niter_base(__first1),
1050 std::__niter_base(__last1),
1051 std::__niter_base(__first2));
1069 template<
typename _IIter1,
typename _IIter2,
typename _BinaryPredicate>
1071 equal(_IIter1 __first1, _IIter1 __last1,
1072 _IIter2 __first2, _BinaryPredicate __binary_pred)
1075 __glibcxx_function_requires(_InputIteratorConcept<_IIter1>)
1076 __glibcxx_function_requires(_InputIteratorConcept<_IIter2>)
1077 __glibcxx_requires_valid_range(__first1, __last1);
1079 for (; __first1 != __last1; ++__first1, (void)++__first2)
1080 if (!
bool(__binary_pred(*__first1, *__first2)))
1085 #if __cplusplus >= 201103L 1087 template<
typename _II1,
typename _II2>
1089 __equal4(_II1 __first1, _II1 __last1, _II2 __first2, _II2 __last2)
1091 using _RATag = random_access_iterator_tag;
1092 using _Cat1 =
typename iterator_traits<_II1>::iterator_category;
1093 using _Cat2 =
typename iterator_traits<_II2>::iterator_category;
1094 using _RAIters = __and_<is_same<_Cat1, _RATag>, is_same<_Cat2, _RATag>>;
1104 for (; __first1 != __last1 && __first2 != __last2;
1105 ++__first1, (void)++__first2)
1106 if (!(*__first1 == *__first2))
1108 return __first1 == __last1 && __first2 == __last2;
1112 template<
typename _II1,
typename _II2,
typename _BinaryPredicate>
1114 __equal4(_II1 __first1, _II1 __last1, _II2 __first2, _II2 __last2,
1115 _BinaryPredicate __binary_pred)
1117 using _RATag = random_access_iterator_tag;
1118 using _Cat1 =
typename iterator_traits<_II1>::iterator_category;
1119 using _Cat2 =
typename iterator_traits<_II2>::iterator_category;
1120 using _RAIters = __and_<is_same<_Cat1, _RATag>, is_same<_Cat2, _RATag>>;
1131 for (; __first1 != __last1 && __first2 != __last2;
1132 ++__first1, (void)++__first2)
1133 if (!
bool(__binary_pred(*__first1, *__first2)))
1135 return __first1 == __last1 && __first2 == __last2;
1139 #if __cplusplus > 201103L 1141 #define __cpp_lib_robust_nonmodifying_seq_ops 201304 1156 template<
typename _II1,
typename _II2>
1158 equal(_II1 __first1, _II1 __last1, _II2 __first2, _II2 __last2)
1161 __glibcxx_function_requires(_InputIteratorConcept<_II1>)
1162 __glibcxx_function_requires(_InputIteratorConcept<_II2>)
1163 __glibcxx_function_requires(_EqualOpConcept<
1164 typename iterator_traits<_II1>::value_type,
1165 typename iterator_traits<_II2>::value_type>)
1166 __glibcxx_requires_valid_range(__first1, __last1);
1167 __glibcxx_requires_valid_range(__first2, __last2);
1169 return _GLIBCXX_STD_A::__equal4(__first1, __last1, __first2, __last2);
1188 template<
typename _IIter1,
typename _IIter2,
typename _BinaryPredicate>
1190 equal(_IIter1 __first1, _IIter1 __last1,
1191 _IIter2 __first2, _IIter2 __last2, _BinaryPredicate __binary_pred)
1194 __glibcxx_function_requires(_InputIteratorConcept<_IIter1>)
1195 __glibcxx_function_requires(_InputIteratorConcept<_IIter2>)
1196 __glibcxx_requires_valid_range(__first1, __last1);
1197 __glibcxx_requires_valid_range(__first2, __last2);
1199 return _GLIBCXX_STD_A::__equal4(__first1, __last1, __first2, __last2,
1219 template<
typename _II1,
typename _II2>
1221 lexicographical_compare(_II1 __first1, _II1 __last1,
1222 _II2 __first2, _II2 __last2)
1224 #ifdef _GLIBCXX_CONCEPT_CHECKS 1226 typedef typename iterator_traits<_II1>::value_type _ValueType1;
1227 typedef typename iterator_traits<_II2>::value_type _ValueType2;
1229 __glibcxx_function_requires(_InputIteratorConcept<_II1>)
1230 __glibcxx_function_requires(_InputIteratorConcept<_II2>)
1231 __glibcxx_function_requires(_LessThanOpConcept<_ValueType1, _ValueType2>)
1232 __glibcxx_function_requires(_LessThanOpConcept<_ValueType2, _ValueType1>)
1233 __glibcxx_requires_valid_range(__first1, __last1);
1234 __glibcxx_requires_valid_range(__first2, __last2);
1236 return std::__lexicographical_compare_aux(std::__niter_base(__first1),
1237 std::__niter_base(__last1),
1238 std::__niter_base(__first2),
1239 std::__niter_base(__last2));
1255 template<
typename _II1,
typename _II2,
typename _Compare>
1257 lexicographical_compare(_II1 __first1, _II1 __last1,
1258 _II2 __first2, _II2 __last2, _Compare __comp)
1261 __glibcxx_function_requires(_InputIteratorConcept<_II1>)
1262 __glibcxx_function_requires(_InputIteratorConcept<_II2>)
1263 __glibcxx_requires_valid_range(__first1, __last1);
1264 __glibcxx_requires_valid_range(__first2, __last2);
1266 return std::__lexicographical_compare_impl
1267 (__first1, __last1, __first2, __last2,
1268 __gnu_cxx::__ops::__iter_comp_iter(__comp));
1271 template<
typename _InputIterator1,
typename _InputIterator2,
1272 typename _BinaryPredicate>
1273 pair<_InputIterator1, _InputIterator2>
1274 __mismatch(_InputIterator1 __first1, _InputIterator1 __last1,
1275 _InputIterator2 __first2, _BinaryPredicate __binary_pred)
1277 while (__first1 != __last1 && __binary_pred(__first1, __first2))
1282 return pair<_InputIterator1, _InputIterator2>(__first1, __first2);
1298 template<
typename _InputIterator1,
typename _InputIterator2>
1299 inline pair<_InputIterator1, _InputIterator2>
1300 mismatch(_InputIterator1 __first1, _InputIterator1 __last1,
1301 _InputIterator2 __first2)
1304 __glibcxx_function_requires(_InputIteratorConcept<_InputIterator1>)
1305 __glibcxx_function_requires(_InputIteratorConcept<_InputIterator2>)
1306 __glibcxx_function_requires(_EqualOpConcept<
1307 typename iterator_traits<_InputIterator1>::value_type,
1308 typename iterator_traits<_InputIterator2>::value_type>)
1309 __glibcxx_requires_valid_range(__first1, __last1);
1311 return _GLIBCXX_STD_A::__mismatch(__first1, __last1, __first2,
1312 __gnu_cxx::__ops::__iter_equal_to_iter());
1331 template<
typename _InputIterator1,
typename _InputIterator2,
1332 typename _BinaryPredicate>
1333 inline pair<_InputIterator1, _InputIterator2>
1334 mismatch(_InputIterator1 __first1, _InputIterator1 __last1,
1335 _InputIterator2 __first2, _BinaryPredicate __binary_pred)
1338 __glibcxx_function_requires(_InputIteratorConcept<_InputIterator1>)
1339 __glibcxx_function_requires(_InputIteratorConcept<_InputIterator2>)
1340 __glibcxx_requires_valid_range(__first1, __last1);
1342 return _GLIBCXX_STD_A::__mismatch(__first1, __last1, __first2,
1343 __gnu_cxx::__ops::__iter_comp_iter(__binary_pred));
1346 #if __cplusplus > 201103L 1348 template<
typename _InputIterator1,
typename _InputIterator2,
1349 typename _BinaryPredicate>
1350 pair<_InputIterator1, _InputIterator2>
1351 __mismatch(_InputIterator1 __first1, _InputIterator1 __last1,
1352 _InputIterator2 __first2, _InputIterator2 __last2,
1353 _BinaryPredicate __binary_pred)
1355 while (__first1 != __last1 && __first2 != __last2
1356 && __binary_pred(__first1, __first2))
1361 return pair<_InputIterator1, _InputIterator2>(__first1, __first2);
1378 template<
typename _InputIterator1,
typename _InputIterator2>
1379 inline pair<_InputIterator1, _InputIterator2>
1380 mismatch(_InputIterator1 __first1, _InputIterator1 __last1,
1381 _InputIterator2 __first2, _InputIterator2 __last2)
1384 __glibcxx_function_requires(_InputIteratorConcept<_InputIterator1>)
1385 __glibcxx_function_requires(_InputIteratorConcept<_InputIterator2>)
1386 __glibcxx_function_requires(_EqualOpConcept<
1387 typename iterator_traits<_InputIterator1>::value_type,
1388 typename iterator_traits<_InputIterator2>::value_type>)
1389 __glibcxx_requires_valid_range(__first1, __last1);
1390 __glibcxx_requires_valid_range(__first2, __last2);
1392 return _GLIBCXX_STD_A::__mismatch(__first1, __last1, __first2, __last2,
1393 __gnu_cxx::__ops::__iter_equal_to_iter());
1413 template<
typename _InputIterator1,
typename _InputIterator2,
1414 typename _BinaryPredicate>
1415 inline pair<_InputIterator1, _InputIterator2>
1416 mismatch(_InputIterator1 __first1, _InputIterator1 __last1,
1417 _InputIterator2 __first2, _InputIterator2 __last2,
1418 _BinaryPredicate __binary_pred)
1421 __glibcxx_function_requires(_InputIteratorConcept<_InputIterator1>)
1422 __glibcxx_function_requires(_InputIteratorConcept<_InputIterator2>)
1423 __glibcxx_requires_valid_range(__first1, __last1);
1424 __glibcxx_requires_valid_range(__first2, __last2);
1426 return _GLIBCXX_STD_A::__mismatch(__first1, __last1, __first2, __last2,
1427 __gnu_cxx::__ops::__iter_comp_iter(__binary_pred));
1431 _GLIBCXX_END_NAMESPACE_ALGO
1432 _GLIBCXX_END_NAMESPACE_VERSION
1438 #ifdef _GLIBCXX_PARALLEL
_GLIBCXX17_CONSTEXPR iterator_traits< _InputIterator >::difference_type distance(_InputIterator __first, _InputIterator __last)
A generalization of pointer arithmetic.
_OI move(_II __first, _II __last, _OI __result)
Moves the range [first,last) into result.
_GLIBCXX17_CONSTEXPR void advance(_InputIterator &__i, _Distance __n)
A generalization of pointer arithmetic.
ISO C++ entities toplevel namespace is std.
_GLIBCXX14_CONSTEXPR const _Tp & min(const _Tp &, const _Tp &)
This does what you think it does.
_OI copy(_II __first, _II __last, _OI __result)
Copies the range [first,last) into result.
void iter_swap(_ForwardIterator1 __a, _ForwardIterator2 __b)
Swaps the contents of two iterators.
constexpr int __lg(int __n)
This is a helper function for the sort routines and for random.tcc.
Parallel STL function calls corresponding to the stl_algobase.h header. The functions defined here ma...
bool equal(_IIter1 __first1, _IIter1 __last1, _IIter2 __first2, _IIter2 __last2, _BinaryPredicate __binary_pred)
Tests a range for element-wise equality.
_GLIBCXX14_CONSTEXPR const _Tp & max(const _Tp &, const _Tp &)
This does what you think it does.