56 #ifndef _STL_ALGOBASE_H 57 #define _STL_ALGOBASE_H 1 72 #if __cplusplus >= 201103L 76 namespace std _GLIBCXX_VISIBILITY(default)
78 _GLIBCXX_BEGIN_NAMESPACE_VERSION
80 #if __cplusplus < 201103L 84 template<
bool _BoolType>
87 template<
typename _ForwardIterator1,
typename _ForwardIterator2>
89 iter_swap(_ForwardIterator1 __a, _ForwardIterator2 __b)
91 typedef typename iterator_traits<_ForwardIterator1>::value_type
93 _ValueType1 __tmp = *__a;
100 struct __iter_swap<true>
102 template<
typename _ForwardIterator1,
typename _ForwardIterator2>
104 iter_swap(_ForwardIterator1 __a, _ForwardIterator2 __b)
121 template<
typename _ForwardIterator1,
typename _ForwardIterator2>
123 iter_swap(_ForwardIterator1 __a, _ForwardIterator2 __b)
126 __glibcxx_function_requires(_Mutable_ForwardIteratorConcept<
128 __glibcxx_function_requires(_Mutable_ForwardIteratorConcept<
131 #if __cplusplus < 201103L 132 typedef typename iterator_traits<_ForwardIterator1>::value_type
134 typedef typename iterator_traits<_ForwardIterator2>::value_type
137 __glibcxx_function_requires(_ConvertibleConcept<_ValueType1,
139 __glibcxx_function_requires(_ConvertibleConcept<_ValueType2,
142 typedef typename iterator_traits<_ForwardIterator1>::reference
144 typedef typename iterator_traits<_ForwardIterator2>::reference
146 std::__iter_swap<__are_same<_ValueType1, _ValueType2>::__value
147 && __are_same<_ValueType1&, _ReferenceType1>::__value
148 && __are_same<_ValueType2&, _ReferenceType2>::__value>::
167 template<
typename _ForwardIterator1,
typename _ForwardIterator2>
169 swap_ranges(_ForwardIterator1 __first1, _ForwardIterator1 __last1,
170 _ForwardIterator2 __first2)
173 __glibcxx_function_requires(_Mutable_ForwardIteratorConcept<
175 __glibcxx_function_requires(_Mutable_ForwardIteratorConcept<
177 __glibcxx_requires_valid_range(__first1, __last1);
179 for (; __first1 != __last1; ++__first1, (void)++__first2)
195 template<
typename _Tp>
198 min(
const _Tp& __a,
const _Tp& __b)
201 __glibcxx_function_requires(_LessThanComparableConcept<_Tp>)
219 template<
typename _Tp>
222 max(
const _Tp& __a,
const _Tp& __b)
225 __glibcxx_function_requires(_LessThanComparableConcept<_Tp>)
243 template<
typename _Tp,
typename _Compare>
246 min(
const _Tp& __a,
const _Tp& __b, _Compare __comp)
249 if (__comp(__b, __a))
265 template<
typename _Tp,
typename _Compare>
268 max(
const _Tp& __a,
const _Tp& __b, _Compare __comp)
271 if (__comp(__a, __b))
278 template<
typename _Iterator>
280 __niter_base(_Iterator __it)
287 template<
typename _From,
typename _To>
289 __niter_wrap(_From __from, _To __res)
290 {
return __from + (__res - std::__niter_base(__from)); }
293 template<
typename _Iterator>
295 __niter_wrap(
const _Iterator&, _Iterator __res)
304 template<
bool _IsMove,
bool _IsSimple,
typename _Category>
307 template<
typename _II,
typename _OI>
309 __copy_m(_II __first, _II __last, _OI __result)
311 for (; __first != __last; ++__result, (void)++__first)
312 *__result = *__first;
317 #if __cplusplus >= 201103L 318 template<
typename _Category>
319 struct __copy_move<true, false, _Category>
321 template<
typename _II,
typename _OI>
323 __copy_m(_II __first, _II __last, _OI __result)
325 for (; __first != __last; ++__result, (void)++__first)
326 *__result = std::move(*__first);
333 struct __copy_move<false, false, random_access_iterator_tag>
335 template<
typename _II,
typename _OI>
337 __copy_m(_II __first, _II __last, _OI __result)
339 typedef typename iterator_traits<_II>::difference_type _Distance;
340 for(_Distance __n = __last - __first; __n > 0; --__n)
342 *__result = *__first;
350 #if __cplusplus >= 201103L 352 struct __copy_move<true, false, random_access_iterator_tag>
354 template<
typename _II,
typename _OI>
356 __copy_m(_II __first, _II __last, _OI __result)
358 typedef typename iterator_traits<_II>::difference_type _Distance;
359 for(_Distance __n = __last - __first; __n > 0; --__n)
361 *__result = std::move(*__first);
370 template<
bool _IsMove>
371 struct __copy_move<_IsMove, true, random_access_iterator_tag>
373 template<
typename _Tp>
375 __copy_m(
const _Tp* __first,
const _Tp* __last, _Tp* __result)
377 #if __cplusplus >= 201103L 378 using __assignable = conditional<_IsMove,
379 is_move_assignable<_Tp>,
380 is_copy_assignable<_Tp>>;
382 static_assert( __assignable::type::value,
"type is not assignable" );
384 const ptrdiff_t _Num = __last - __first;
386 __builtin_memmove(__result, __first,
sizeof(_Tp) * _Num);
387 return __result + _Num;
391 template<
bool _IsMove,
typename _II,
typename _OI>
393 __copy_move_a(_II __first, _II __last, _OI __result)
395 typedef typename iterator_traits<_II>::value_type _ValueTypeI;
396 typedef typename iterator_traits<_OI>::value_type _ValueTypeO;
397 typedef typename iterator_traits<_II>::iterator_category _Category;
398 const bool __simple = (__is_trivially_copyable(_ValueTypeI)
399 && __is_pointer<_II>::__value
400 && __is_pointer<_OI>::__value
401 && __are_same<_ValueTypeI, _ValueTypeO>::__value);
403 return std::__copy_move<_IsMove, __simple,
404 _Category>::__copy_m(__first, __last, __result);
409 template<
typename _CharT>
412 template<
typename _CharT,
typename _Traits>
413 class istreambuf_iterator;
415 template<
typename _CharT,
typename _Traits>
416 class ostreambuf_iterator;
418 template<
bool _IsMove,
typename _CharT>
419 typename __gnu_cxx::__enable_if<__is_char<_CharT>::__value,
420 ostreambuf_iterator<_CharT, char_traits<_CharT> > >::__type
421 __copy_move_a2(_CharT*, _CharT*,
422 ostreambuf_iterator<_CharT, char_traits<_CharT> >);
424 template<
bool _IsMove,
typename _CharT>
425 typename __gnu_cxx::__enable_if<__is_char<_CharT>::__value,
426 ostreambuf_iterator<_CharT, char_traits<_CharT> > >::__type
427 __copy_move_a2(
const _CharT*,
const _CharT*,
428 ostreambuf_iterator<_CharT, char_traits<_CharT> >);
430 template<
bool _IsMove,
typename _CharT>
431 typename __gnu_cxx::__enable_if<__is_char<_CharT>::__value,
433 __copy_move_a2(istreambuf_iterator<_CharT, char_traits<_CharT> >,
434 istreambuf_iterator<_CharT, char_traits<_CharT> >, _CharT*);
436 template<
bool _IsMove,
typename _II,
typename _OI>
438 __copy_move_a2(_II __first, _II __last, _OI __result)
440 return std::__niter_wrap(__result,
441 std::__copy_move_a<_IsMove>(std::__niter_base(__first),
442 std::__niter_base(__last),
443 std::__niter_base(__result)));
463 template<
typename _II,
typename _OI>
465 copy(_II __first, _II __last, _OI __result)
468 __glibcxx_function_requires(_InputIteratorConcept<_II>)
469 __glibcxx_function_requires(_OutputIteratorConcept<_OI,
470 typename iterator_traits<_II>::value_type>)
471 __glibcxx_requires_can_increment_range(__first, __last, __result);
473 return std::__copy_move_a2<__is_move_iterator<_II>::__value>
474 (std::__miter_base(__first), std::__miter_base(__last), __result);
477 #if __cplusplus >= 201103L 495 template<
typename _II,
typename _OI>
497 move(_II __first, _II __last, _OI __result)
500 __glibcxx_function_requires(_InputIteratorConcept<_II>)
501 __glibcxx_function_requires(_OutputIteratorConcept<_OI,
502 typename iterator_traits<_II>::value_type>)
503 __glibcxx_requires_can_increment_range(__first, __last, __result);
505 return std::__copy_move_a2<true>(std::__miter_base(__first),
506 std::__miter_base(__last), __result);
509 #define _GLIBCXX_MOVE3(_Tp, _Up, _Vp) std::move(_Tp, _Up, _Vp) 511 #define _GLIBCXX_MOVE3(_Tp, _Up, _Vp) std::copy(_Tp, _Up, _Vp) 514 template<
bool,
bool,
typename>
515 struct __copy_move_backward
517 template<
typename _BI1,
typename _BI2>
519 __copy_move_b(_BI1 __first, _BI1 __last, _BI2 __result)
521 while (__first != __last)
522 *--__result = *--__last;
527 #if __cplusplus >= 201103L 528 template<
typename _Category>
529 struct __copy_move_backward<true, false, _Category>
531 template<
typename _BI1,
typename _BI2>
533 __copy_move_b(_BI1 __first, _BI1 __last, _BI2 __result)
535 while (__first != __last)
536 *--__result = std::move(*--__last);
543 struct __copy_move_backward<false, false, random_access_iterator_tag>
545 template<
typename _BI1,
typename _BI2>
547 __copy_move_b(_BI1 __first, _BI1 __last, _BI2 __result)
549 typename iterator_traits<_BI1>::difference_type __n;
550 for (__n = __last - __first; __n > 0; --__n)
551 *--__result = *--__last;
556 #if __cplusplus >= 201103L 558 struct __copy_move_backward<true, false, random_access_iterator_tag>
560 template<
typename _BI1,
typename _BI2>
562 __copy_move_b(_BI1 __first, _BI1 __last, _BI2 __result)
564 typename iterator_traits<_BI1>::difference_type __n;
565 for (__n = __last - __first; __n > 0; --__n)
566 *--__result = std::move(*--__last);
572 template<
bool _IsMove>
573 struct __copy_move_backward<_IsMove, true, random_access_iterator_tag>
575 template<
typename _Tp>
577 __copy_move_b(
const _Tp* __first,
const _Tp* __last, _Tp* __result)
579 #if __cplusplus >= 201103L 580 using __assignable = conditional<_IsMove,
581 is_move_assignable<_Tp>,
582 is_copy_assignable<_Tp>>;
584 static_assert( __assignable::type::value,
"type is not assignable" );
586 const ptrdiff_t _Num = __last - __first;
588 __builtin_memmove(__result - _Num, __first,
sizeof(_Tp) * _Num);
589 return __result - _Num;
593 template<
bool _IsMove,
typename _BI1,
typename _BI2>
595 __copy_move_backward_a(_BI1 __first, _BI1 __last, _BI2 __result)
597 typedef typename iterator_traits<_BI1>::value_type _ValueType1;
598 typedef typename iterator_traits<_BI2>::value_type _ValueType2;
599 typedef typename iterator_traits<_BI1>::iterator_category _Category;
600 const bool __simple = (__is_trivially_copyable(_ValueType1)
601 && __is_pointer<_BI1>::__value
602 && __is_pointer<_BI2>::__value
603 && __are_same<_ValueType1, _ValueType2>::__value);
605 return std::__copy_move_backward<_IsMove, __simple,
606 _Category>::__copy_move_b(__first,
611 template<
bool _IsMove,
typename _BI1,
typename _BI2>
613 __copy_move_backward_a2(_BI1 __first, _BI1 __last, _BI2 __result)
615 return std::__niter_wrap(__result,
616 std::__copy_move_backward_a<_IsMove>
617 (std::__niter_base(__first), std::__niter_base(__last),
618 std::__niter_base(__result)));
639 template<
typename _BI1,
typename _BI2>
641 copy_backward(_BI1 __first, _BI1 __last, _BI2 __result)
644 __glibcxx_function_requires(_BidirectionalIteratorConcept<_BI1>)
645 __glibcxx_function_requires(_Mutable_BidirectionalIteratorConcept<_BI2>)
646 __glibcxx_function_requires(_ConvertibleConcept<
647 typename iterator_traits<_BI1>::value_type,
648 typename iterator_traits<_BI2>::value_type>)
649 __glibcxx_requires_can_decrement_range(__first, __last, __result);
651 return std::__copy_move_backward_a2<__is_move_iterator<_BI1>::__value>
652 (std::__miter_base(__first), std::__miter_base(__last), __result);
655 #if __cplusplus >= 201103L 674 template<
typename _BI1,
typename _BI2>
676 move_backward(_BI1 __first, _BI1 __last, _BI2 __result)
679 __glibcxx_function_requires(_BidirectionalIteratorConcept<_BI1>)
680 __glibcxx_function_requires(_Mutable_BidirectionalIteratorConcept<_BI2>)
681 __glibcxx_function_requires(_ConvertibleConcept<
682 typename iterator_traits<_BI1>::value_type,
683 typename iterator_traits<_BI2>::value_type>)
684 __glibcxx_requires_can_decrement_range(__first, __last, __result);
686 return std::__copy_move_backward_a2<true>(std::__miter_base(__first),
687 std::__miter_base(__last),
691 #define _GLIBCXX_MOVE_BACKWARD3(_Tp, _Up, _Vp) std::move_backward(_Tp, _Up, _Vp) 693 #define _GLIBCXX_MOVE_BACKWARD3(_Tp, _Up, _Vp) std::copy_backward(_Tp, _Up, _Vp) 696 template<
typename _ForwardIterator,
typename _Tp>
698 __gnu_cxx::__enable_if<!__is_scalar<_Tp>::__value,
void>::__type
699 __fill_a(_ForwardIterator __first, _ForwardIterator __last,
702 for (; __first != __last; ++__first)
706 template<
typename _ForwardIterator,
typename _Tp>
708 __gnu_cxx::__enable_if<__is_scalar<_Tp>::__value,
void>::__type
709 __fill_a(_ForwardIterator __first, _ForwardIterator __last,
712 const _Tp __tmp = __value;
713 for (; __first != __last; ++__first)
718 template<
typename _Tp>
720 __gnu_cxx::__enable_if<__is_byte<_Tp>::__value,
void>::__type
721 __fill_a(_Tp* __first, _Tp* __last,
const _Tp& __c)
723 const _Tp __tmp = __c;
724 if (
const size_t __len = __last - __first)
725 __builtin_memset(__first, static_cast<unsigned char>(__tmp), __len);
740 template<
typename _ForwardIterator,
typename _Tp>
742 fill(_ForwardIterator __first, _ForwardIterator __last,
const _Tp& __value)
745 __glibcxx_function_requires(_Mutable_ForwardIteratorConcept<
747 __glibcxx_requires_valid_range(__first, __last);
749 std::__fill_a(std::__niter_base(__first), std::__niter_base(__last),
753 template<
typename _OutputIterator,
typename _Size,
typename _Tp>
755 __gnu_cxx::__enable_if<!__is_scalar<_Tp>::__value, _OutputIterator>::__type
756 __fill_n_a(_OutputIterator __first, _Size __n,
const _Tp& __value)
758 for (__decltype(__n + 0) __niter = __n;
759 __niter > 0; --__niter, (void) ++__first)
764 template<
typename _OutputIterator,
typename _Size,
typename _Tp>
766 __gnu_cxx::__enable_if<__is_scalar<_Tp>::__value, _OutputIterator>::__type
767 __fill_n_a(_OutputIterator __first, _Size __n,
const _Tp& __value)
769 const _Tp __tmp = __value;
770 for (__decltype(__n + 0) __niter = __n;
771 __niter > 0; --__niter, (void) ++__first)
776 template<
typename _Size,
typename _Tp>
778 __gnu_cxx::__enable_if<__is_byte<_Tp>::__value, _Tp*>::__type
779 __fill_n_a(_Tp* __first, _Size __n,
const _Tp& __c)
781 std::__fill_a(__first, __first + __n, __c);
782 return __first + __n;
800 template<
typename _OI,
typename _Size,
typename _Tp>
802 fill_n(_OI __first, _Size __n,
const _Tp& __value)
805 __glibcxx_function_requires(_OutputIteratorConcept<_OI, _Tp>)
806 __glibcxx_requires_can_increment(__first, __n);
808 return std::__niter_wrap(__first,
809 std::__fill_n_a(std::__niter_base(__first), __n, __value));
812 template<
bool _BoolType>
815 template<
typename _II1,
typename _II2>
817 equal(_II1 __first1, _II1 __last1, _II2 __first2)
819 for (; __first1 != __last1; ++__first1, (void) ++__first2)
820 if (!(*__first1 == *__first2))
829 template<
typename _Tp>
831 equal(
const _Tp* __first1,
const _Tp* __last1,
const _Tp* __first2)
833 if (
const size_t __len = (__last1 - __first1))
834 return !__builtin_memcmp(__first1, __first2,
sizeof(_Tp) * __len);
839 template<
typename _II1,
typename _II2>
841 __equal_aux(_II1 __first1, _II1 __last1, _II2 __first2)
843 typedef typename iterator_traits<_II1>::value_type _ValueType1;
844 typedef typename iterator_traits<_II2>::value_type _ValueType2;
845 const bool __simple = ((__is_integer<_ValueType1>::__value
846 || __is_pointer<_ValueType1>::__value)
847 && __is_pointer<_II1>::__value
848 && __is_pointer<_II2>::__value
849 && __are_same<_ValueType1, _ValueType2>::__value);
854 template<
typename,
typename>
857 template<
typename _II1,
typename _II2>
859 __newlast1(_II1, _II1 __last1, _II2, _II2)
862 template<
typename _II>
864 __cnd2(_II __first, _II __last)
865 {
return __first != __last; }
869 struct __lc_rai<random_access_iterator_tag, random_access_iterator_tag>
871 template<
typename _RAI1,
typename _RAI2>
873 __newlast1(_RAI1 __first1, _RAI1 __last1,
874 _RAI2 __first2, _RAI2 __last2)
876 const typename iterator_traits<_RAI1>::difference_type
877 __diff1 = __last1 - __first1;
878 const typename iterator_traits<_RAI2>::difference_type
879 __diff2 = __last2 - __first2;
880 return __diff2 < __diff1 ? __first1 + __diff2 : __last1;
883 template<
typename _RAI>
889 template<
typename _II1,
typename _II2,
typename _Compare>
891 __lexicographical_compare_impl(_II1 __first1, _II1 __last1,
892 _II2 __first2, _II2 __last2,
895 typedef typename iterator_traits<_II1>::iterator_category _Category1;
896 typedef typename iterator_traits<_II2>::iterator_category _Category2;
897 typedef std::__lc_rai<_Category1, _Category2> __rai_type;
899 __last1 = __rai_type::__newlast1(__first1, __last1, __first2, __last2);
900 for (; __first1 != __last1 && __rai_type::__cnd2(__first2, __last2);
901 ++__first1, (void)++__first2)
903 if (__comp(__first1, __first2))
905 if (__comp(__first2, __first1))
908 return __first1 == __last1 && __first2 != __last2;
911 template<
bool _BoolType>
912 struct __lexicographical_compare
914 template<
typename _II1,
typename _II2>
915 static bool __lc(_II1, _II1, _II2, _II2);
918 template<
bool _BoolType>
919 template<
typename _II1,
typename _II2>
921 __lexicographical_compare<_BoolType>::
922 __lc(_II1 __first1, _II1 __last1, _II2 __first2, _II2 __last2)
924 return std::__lexicographical_compare_impl(__first1, __last1,
926 __gnu_cxx::__ops::__iter_less_iter());
930 struct __lexicographical_compare<true>
932 template<
typename _Tp,
typename _Up>
934 __lc(
const _Tp* __first1,
const _Tp* __last1,
935 const _Up* __first2,
const _Up* __last2)
937 const size_t __len1 = __last1 - __first1;
938 const size_t __len2 = __last2 - __first2;
939 if (
const size_t __len =
std::min(__len1, __len2))
940 if (
int __result = __builtin_memcmp(__first1, __first2, __len))
942 return __len1 < __len2;
946 template<
typename _II1,
typename _II2>
948 __lexicographical_compare_aux(_II1 __first1, _II1 __last1,
949 _II2 __first2, _II2 __last2)
951 typedef typename iterator_traits<_II1>::value_type _ValueType1;
952 typedef typename iterator_traits<_II2>::value_type _ValueType2;
953 const bool __simple =
954 (__is_byte<_ValueType1>::__value && __is_byte<_ValueType2>::__value
955 && !__gnu_cxx::__numeric_traits<_ValueType1>::__is_signed
956 && !__gnu_cxx::__numeric_traits<_ValueType2>::__is_signed
957 && __is_pointer<_II1>::__value
958 && __is_pointer<_II2>::__value);
960 return std::__lexicographical_compare<__simple>::__lc(__first1, __last1,
964 template<
typename _ForwardIterator,
typename _Tp,
typename _Compare>
966 __lower_bound(_ForwardIterator __first, _ForwardIterator __last,
967 const _Tp& __val, _Compare __comp)
969 typedef typename iterator_traits<_ForwardIterator>::difference_type
976 _DistanceType __half = __len >> 1;
977 _ForwardIterator __middle = __first;
979 if (__comp(__middle, __val))
983 __len = __len - __half - 1;
1002 template<
typename _ForwardIterator,
typename _Tp>
1003 inline _ForwardIterator
1004 lower_bound(_ForwardIterator __first, _ForwardIterator __last,
1008 __glibcxx_function_requires(_ForwardIteratorConcept<_ForwardIterator>)
1009 __glibcxx_function_requires(_LessThanOpConcept<
1010 typename iterator_traits<_ForwardIterator>::value_type, _Tp>)
1011 __glibcxx_requires_partitioned_lower(__first, __last, __val);
1013 return std::__lower_bound(__first, __last, __val,
1014 __gnu_cxx::__ops::__iter_less_val());
1019 inline _GLIBCXX_CONSTEXPR
int 1021 {
return (
int)
sizeof(int) * __CHAR_BIT__ - 1 - __builtin_clz(__n); }
1023 inline _GLIBCXX_CONSTEXPR
unsigned 1025 {
return (
int)
sizeof(int) * __CHAR_BIT__ - 1 - __builtin_clz(__n); }
1027 inline _GLIBCXX_CONSTEXPR
long 1029 {
return (
int)
sizeof(long) * __CHAR_BIT__ - 1 - __builtin_clzl(__n); }
1031 inline _GLIBCXX_CONSTEXPR
unsigned long 1032 __lg(
unsigned long __n)
1033 {
return (
int)
sizeof(long) * __CHAR_BIT__ - 1 - __builtin_clzl(__n); }
1035 inline _GLIBCXX_CONSTEXPR
long long 1037 {
return (
int)
sizeof(
long long) * __CHAR_BIT__ - 1 - __builtin_clzll(__n); }
1039 inline _GLIBCXX_CONSTEXPR
unsigned long long 1040 __lg(
unsigned long long __n)
1041 {
return (
int)
sizeof(
long long) * __CHAR_BIT__ - 1 - __builtin_clzll(__n); }
1043 _GLIBCXX_BEGIN_NAMESPACE_ALGO
1057 template<
typename _II1,
typename _II2>
1059 equal(_II1 __first1, _II1 __last1, _II2 __first2)
1062 __glibcxx_function_requires(_InputIteratorConcept<_II1>)
1063 __glibcxx_function_requires(_InputIteratorConcept<_II2>)
1064 __glibcxx_function_requires(_EqualOpConcept<
1065 typename iterator_traits<_II1>::value_type,
1066 typename iterator_traits<_II2>::value_type>)
1067 __glibcxx_requires_can_increment_range(__first1, __last1, __first2);
1069 return std::__equal_aux(std::__niter_base(__first1),
1070 std::__niter_base(__last1),
1071 std::__niter_base(__first2));
1089 template<
typename _IIter1,
typename _IIter2,
typename _BinaryPredicate>
1091 equal(_IIter1 __first1, _IIter1 __last1,
1092 _IIter2 __first2, _BinaryPredicate __binary_pred)
1095 __glibcxx_function_requires(_InputIteratorConcept<_IIter1>)
1096 __glibcxx_function_requires(_InputIteratorConcept<_IIter2>)
1097 __glibcxx_requires_valid_range(__first1, __last1);
1099 for (; __first1 != __last1; ++__first1, (void)++__first2)
1100 if (!
bool(__binary_pred(*__first1, *__first2)))
1105 #if __cplusplus >= 201103L 1107 template<
typename _II1,
typename _II2>
1109 __equal4(_II1 __first1, _II1 __last1, _II2 __first2, _II2 __last2)
1111 using _RATag = random_access_iterator_tag;
1112 using _Cat1 =
typename iterator_traits<_II1>::iterator_category;
1113 using _Cat2 =
typename iterator_traits<_II2>::iterator_category;
1114 using _RAIters = __and_<is_same<_Cat1, _RATag>, is_same<_Cat2, _RATag>>;
1124 for (; __first1 != __last1 && __first2 != __last2;
1125 ++__first1, (void)++__first2)
1126 if (!(*__first1 == *__first2))
1128 return __first1 == __last1 && __first2 == __last2;
1132 template<
typename _II1,
typename _II2,
typename _BinaryPredicate>
1134 __equal4(_II1 __first1, _II1 __last1, _II2 __first2, _II2 __last2,
1135 _BinaryPredicate __binary_pred)
1137 using _RATag = random_access_iterator_tag;
1138 using _Cat1 =
typename iterator_traits<_II1>::iterator_category;
1139 using _Cat2 =
typename iterator_traits<_II2>::iterator_category;
1140 using _RAIters = __and_<is_same<_Cat1, _RATag>, is_same<_Cat2, _RATag>>;
1151 for (; __first1 != __last1 && __first2 != __last2;
1152 ++__first1, (void)++__first2)
1153 if (!
bool(__binary_pred(*__first1, *__first2)))
1155 return __first1 == __last1 && __first2 == __last2;
1159 #if __cplusplus > 201103L 1161 #define __cpp_lib_robust_nonmodifying_seq_ops 201304 1176 template<
typename _II1,
typename _II2>
1178 equal(_II1 __first1, _II1 __last1, _II2 __first2, _II2 __last2)
1181 __glibcxx_function_requires(_InputIteratorConcept<_II1>)
1182 __glibcxx_function_requires(_InputIteratorConcept<_II2>)
1183 __glibcxx_function_requires(_EqualOpConcept<
1184 typename iterator_traits<_II1>::value_type,
1185 typename iterator_traits<_II2>::value_type>)
1186 __glibcxx_requires_valid_range(__first1, __last1);
1187 __glibcxx_requires_valid_range(__first2, __last2);
1189 return _GLIBCXX_STD_A::__equal4(__first1, __last1, __first2, __last2);
1208 template<
typename _IIter1,
typename _IIter2,
typename _BinaryPredicate>
1210 equal(_IIter1 __first1, _IIter1 __last1,
1211 _IIter2 __first2, _IIter2 __last2, _BinaryPredicate __binary_pred)
1214 __glibcxx_function_requires(_InputIteratorConcept<_IIter1>)
1215 __glibcxx_function_requires(_InputIteratorConcept<_IIter2>)
1216 __glibcxx_requires_valid_range(__first1, __last1);
1217 __glibcxx_requires_valid_range(__first2, __last2);
1219 return _GLIBCXX_STD_A::__equal4(__first1, __last1, __first2, __last2,
1239 template<
typename _II1,
typename _II2>
1241 lexicographical_compare(_II1 __first1, _II1 __last1,
1242 _II2 __first2, _II2 __last2)
1244 #ifdef _GLIBCXX_CONCEPT_CHECKS 1246 typedef typename iterator_traits<_II1>::value_type _ValueType1;
1247 typedef typename iterator_traits<_II2>::value_type _ValueType2;
1249 __glibcxx_function_requires(_InputIteratorConcept<_II1>)
1250 __glibcxx_function_requires(_InputIteratorConcept<_II2>)
1251 __glibcxx_function_requires(_LessThanOpConcept<_ValueType1, _ValueType2>)
1252 __glibcxx_function_requires(_LessThanOpConcept<_ValueType2, _ValueType1>)
1253 __glibcxx_requires_valid_range(__first1, __last1);
1254 __glibcxx_requires_valid_range(__first2, __last2);
1256 return std::__lexicographical_compare_aux(std::__niter_base(__first1),
1257 std::__niter_base(__last1),
1258 std::__niter_base(__first2),
1259 std::__niter_base(__last2));
1275 template<
typename _II1,
typename _II2,
typename _Compare>
1277 lexicographical_compare(_II1 __first1, _II1 __last1,
1278 _II2 __first2, _II2 __last2, _Compare __comp)
1281 __glibcxx_function_requires(_InputIteratorConcept<_II1>)
1282 __glibcxx_function_requires(_InputIteratorConcept<_II2>)
1283 __glibcxx_requires_valid_range(__first1, __last1);
1284 __glibcxx_requires_valid_range(__first2, __last2);
1286 return std::__lexicographical_compare_impl
1287 (__first1, __last1, __first2, __last2,
1288 __gnu_cxx::__ops::__iter_comp_iter(__comp));
1291 template<
typename _InputIterator1,
typename _InputIterator2,
1292 typename _BinaryPredicate>
1293 pair<_InputIterator1, _InputIterator2>
1294 __mismatch(_InputIterator1 __first1, _InputIterator1 __last1,
1295 _InputIterator2 __first2, _BinaryPredicate __binary_pred)
1297 while (__first1 != __last1 && __binary_pred(__first1, __first2))
1302 return pair<_InputIterator1, _InputIterator2>(__first1, __first2);
1318 template<
typename _InputIterator1,
typename _InputIterator2>
1319 inline pair<_InputIterator1, _InputIterator2>
1320 mismatch(_InputIterator1 __first1, _InputIterator1 __last1,
1321 _InputIterator2 __first2)
1324 __glibcxx_function_requires(_InputIteratorConcept<_InputIterator1>)
1325 __glibcxx_function_requires(_InputIteratorConcept<_InputIterator2>)
1326 __glibcxx_function_requires(_EqualOpConcept<
1327 typename iterator_traits<_InputIterator1>::value_type,
1328 typename iterator_traits<_InputIterator2>::value_type>)
1329 __glibcxx_requires_valid_range(__first1, __last1);
1331 return _GLIBCXX_STD_A::__mismatch(__first1, __last1, __first2,
1332 __gnu_cxx::__ops::__iter_equal_to_iter());
1351 template<
typename _InputIterator1,
typename _InputIterator2,
1352 typename _BinaryPredicate>
1353 inline pair<_InputIterator1, _InputIterator2>
1354 mismatch(_InputIterator1 __first1, _InputIterator1 __last1,
1355 _InputIterator2 __first2, _BinaryPredicate __binary_pred)
1358 __glibcxx_function_requires(_InputIteratorConcept<_InputIterator1>)
1359 __glibcxx_function_requires(_InputIteratorConcept<_InputIterator2>)
1360 __glibcxx_requires_valid_range(__first1, __last1);
1362 return _GLIBCXX_STD_A::__mismatch(__first1, __last1, __first2,
1363 __gnu_cxx::__ops::__iter_comp_iter(__binary_pred));
1366 #if __cplusplus > 201103L 1368 template<
typename _InputIterator1,
typename _InputIterator2,
1369 typename _BinaryPredicate>
1370 pair<_InputIterator1, _InputIterator2>
1371 __mismatch(_InputIterator1 __first1, _InputIterator1 __last1,
1372 _InputIterator2 __first2, _InputIterator2 __last2,
1373 _BinaryPredicate __binary_pred)
1375 while (__first1 != __last1 && __first2 != __last2
1376 && __binary_pred(__first1, __first2))
1381 return pair<_InputIterator1, _InputIterator2>(__first1, __first2);
1398 template<
typename _InputIterator1,
typename _InputIterator2>
1399 inline pair<_InputIterator1, _InputIterator2>
1400 mismatch(_InputIterator1 __first1, _InputIterator1 __last1,
1401 _InputIterator2 __first2, _InputIterator2 __last2)
1404 __glibcxx_function_requires(_InputIteratorConcept<_InputIterator1>)
1405 __glibcxx_function_requires(_InputIteratorConcept<_InputIterator2>)
1406 __glibcxx_function_requires(_EqualOpConcept<
1407 typename iterator_traits<_InputIterator1>::value_type,
1408 typename iterator_traits<_InputIterator2>::value_type>)
1409 __glibcxx_requires_valid_range(__first1, __last1);
1410 __glibcxx_requires_valid_range(__first2, __last2);
1412 return _GLIBCXX_STD_A::__mismatch(__first1, __last1, __first2, __last2,
1413 __gnu_cxx::__ops::__iter_equal_to_iter());
1433 template<
typename _InputIterator1,
typename _InputIterator2,
1434 typename _BinaryPredicate>
1435 inline pair<_InputIterator1, _InputIterator2>
1436 mismatch(_InputIterator1 __first1, _InputIterator1 __last1,
1437 _InputIterator2 __first2, _InputIterator2 __last2,
1438 _BinaryPredicate __binary_pred)
1441 __glibcxx_function_requires(_InputIteratorConcept<_InputIterator1>)
1442 __glibcxx_function_requires(_InputIteratorConcept<_InputIterator2>)
1443 __glibcxx_requires_valid_range(__first1, __last1);
1444 __glibcxx_requires_valid_range(__first2, __last2);
1446 return _GLIBCXX_STD_A::__mismatch(__first1, __last1, __first2, __last2,
1447 __gnu_cxx::__ops::__iter_comp_iter(__binary_pred));
1451 _GLIBCXX_END_NAMESPACE_ALGO
1452 _GLIBCXX_END_NAMESPACE_VERSION
1458 #ifdef _GLIBCXX_PARALLEL bool equal(_IIter1 __first1, _IIter1 __last1, _IIter2 __first2, _IIter2 __last2, _BinaryPredicate __binary_pred)
Tests a range for element-wise equality.
ISO C++ entities toplevel namespace is std.
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...
_OI copy(_II __first, _II __last, _OI __result)
Copies the range [first,last) into result.
is_nothrow_copy_constructible
_OI move(_II __first, _II __last, _OI __result)
Moves the range [first,last) into result.
void iter_swap(_ForwardIterator1 __a, _ForwardIterator2 __b)
Swaps the contents of two iterators.
_GLIBCXX14_CONSTEXPR const _Tp & min(const _Tp &, const _Tp &)
This does what you think it does.
_GLIBCXX17_CONSTEXPR iterator_traits< _InputIterator >::difference_type distance(_InputIterator __first, _InputIterator __last)
A generalization of pointer arithmetic.
_GLIBCXX14_CONSTEXPR const _Tp & max(const _Tp &, const _Tp &)
This does what you think it does.
_GLIBCXX17_CONSTEXPR void advance(_InputIterator &__i, _Distance __n)
A generalization of pointer arithmetic.