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 = _GLIBCXX_MOVE(*__a);
91 *__a = _GLIBCXX_MOVE(*__b);
92 *__b = _GLIBCXX_MOVE(__tmp);
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, ++__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 : _Iter_base<_Iterator, __is_normal_iterator<_Iterator>::__value>
280 template<
typename _Iterator>
281 inline typename _Niter_base<_Iterator>::iterator_type
282 __niter_base(_Iterator __it)
283 {
return std::_Niter_base<_Iterator>::_S_base(__it); }
286 template<
typename _Iterator>
288 : _Iter_base<_Iterator, __is_move_iterator<_Iterator>::__value>
291 template<
typename _Iterator>
292 inline typename _Miter_base<_Iterator>::iterator_type
293 __miter_base(_Iterator __it)
294 {
return std::_Miter_base<_Iterator>::_S_base(__it); }
302 template<
bool,
bool,
typename>
305 template<
typename _II,
typename _OI>
307 __copy_m(_II __first, _II __last, _OI __result)
309 for (; __first != __last; ++__result, ++__first)
310 *__result = *__first;
315 #if __cplusplus >= 201103L
316 template<
typename _Category>
317 struct __copy_move<true, false, _Category>
319 template<
typename _II,
typename _OI>
321 __copy_m(_II __first, _II __last, _OI __result)
323 for (; __first != __last; ++__result, ++__first)
331 struct __copy_move<false, false, random_access_iterator_tag>
333 template<
typename _II,
typename _OI>
335 __copy_m(_II __first, _II __last, _OI __result)
337 typedef typename iterator_traits<_II>::difference_type _Distance;
338 for(_Distance __n = __last - __first; __n > 0; --__n)
340 *__result = *__first;
348 #if __cplusplus >= 201103L
350 struct __copy_move<true, false, random_access_iterator_tag>
352 template<
typename _II,
typename _OI>
354 __copy_m(_II __first, _II __last, _OI __result)
356 typedef typename iterator_traits<_II>::difference_type _Distance;
357 for(_Distance __n = __last - __first; __n > 0; --__n)
368 template<
bool _IsMove>
369 struct __copy_move<_IsMove, true, random_access_iterator_tag>
371 template<
typename _Tp>
373 __copy_m(
const _Tp* __first,
const _Tp* __last, _Tp* __result)
375 #if __cplusplus >= 201103L
377 static_assert( is_copy_assignable<_Tp>::value,
378 "type is not assignable" );
380 const ptrdiff_t _Num = __last - __first;
382 __builtin_memmove(__result, __first,
sizeof(_Tp) * _Num);
383 return __result + _Num;
387 template<
bool _IsMove,
typename _II,
typename _OI>
389 __copy_move_a(_II __first, _II __last, _OI __result)
391 typedef typename iterator_traits<_II>::value_type _ValueTypeI;
392 typedef typename iterator_traits<_OI>::value_type _ValueTypeO;
393 typedef typename iterator_traits<_II>::iterator_category _Category;
394 const bool __simple = (__is_trivial(_ValueTypeI)
395 && __is_pointer<_II>::__value
396 && __is_pointer<_OI>::__value
397 && __are_same<_ValueTypeI, _ValueTypeO>::__value);
399 return std::__copy_move<_IsMove, __simple,
400 _Category>::__copy_m(__first, __last, __result);
405 template<
typename _CharT>
408 template<
typename _CharT,
typename _Traits>
411 template<
typename _CharT,
typename _Traits>
414 template<
bool _IsMove,
typename _CharT>
415 typename __gnu_cxx::__enable_if<__is_char<_CharT>::__value,
417 __copy_move_a2(_CharT*, _CharT*,
420 template<
bool _IsMove,
typename _CharT>
421 typename __gnu_cxx::__enable_if<__is_char<_CharT>::__value,
423 __copy_move_a2(
const _CharT*,
const _CharT*,
426 template<
bool _IsMove,
typename _CharT>
427 typename __gnu_cxx::__enable_if<__is_char<_CharT>::__value,
432 template<
bool _IsMove,
typename _II,
typename _OI>
434 __copy_move_a2(_II __first, _II __last, _OI __result)
436 return _OI(std::__copy_move_a<_IsMove>(std::__niter_base(__first),
437 std::__niter_base(__last),
438 std::__niter_base(__result)));
458 template<
typename _II,
typename _OI>
460 copy(_II __first, _II __last, _OI __result)
463 __glibcxx_function_requires(_InputIteratorConcept<_II>)
464 __glibcxx_function_requires(_OutputIteratorConcept<_OI,
465 typename iterator_traits<_II>::value_type>)
466 __glibcxx_requires_valid_range(__first, __last);
468 return (std::__copy_move_a2<__is_move_iterator<_II>::__value>
469 (std::__miter_base(__first), std::__miter_base(__last),
473 #if __cplusplus >= 201103L
491 template<
typename _II,
typename _OI>
493 move(_II __first, _II __last, _OI __result)
496 __glibcxx_function_requires(_InputIteratorConcept<_II>)
497 __glibcxx_function_requires(_OutputIteratorConcept<_OI,
498 typename iterator_traits<_II>::value_type>)
499 __glibcxx_requires_valid_range(__first, __last);
501 return std::__copy_move_a2<true>(std::__miter_base(__first),
502 std::__miter_base(__last), __result);
505 #define _GLIBCXX_MOVE3(_Tp, _Up, _Vp) std::move(_Tp, _Up, _Vp)
507 #define _GLIBCXX_MOVE3(_Tp, _Up, _Vp) std::copy(_Tp, _Up, _Vp)
510 template<
bool,
bool,
typename>
511 struct __copy_move_backward
513 template<
typename _BI1,
typename _BI2>
515 __copy_move_b(_BI1 __first, _BI1 __last, _BI2 __result)
517 while (__first != __last)
518 *--__result = *--__last;
523 #if __cplusplus >= 201103L
524 template<
typename _Category>
525 struct __copy_move_backward<true, false, _Category>
527 template<
typename _BI1,
typename _BI2>
529 __copy_move_b(_BI1 __first, _BI1 __last, _BI2 __result)
531 while (__first != __last)
539 struct __copy_move_backward<false, false, random_access_iterator_tag>
541 template<
typename _BI1,
typename _BI2>
543 __copy_move_b(_BI1 __first, _BI1 __last, _BI2 __result)
545 typename iterator_traits<_BI1>::difference_type __n;
546 for (__n = __last - __first; __n > 0; --__n)
547 *--__result = *--__last;
552 #if __cplusplus >= 201103L
554 struct __copy_move_backward<true, false, random_access_iterator_tag>
556 template<
typename _BI1,
typename _BI2>
558 __copy_move_b(_BI1 __first, _BI1 __last, _BI2 __result)
560 typename iterator_traits<_BI1>::difference_type __n;
561 for (__n = __last - __first; __n > 0; --__n)
568 template<
bool _IsMove>
569 struct __copy_move_backward<_IsMove, true, random_access_iterator_tag>
571 template<
typename _Tp>
573 __copy_move_b(
const _Tp* __first,
const _Tp* __last, _Tp* __result)
575 #if __cplusplus >= 201103L
577 static_assert( is_copy_assignable<_Tp>::value,
578 "type is not assignable" );
580 const ptrdiff_t _Num = __last - __first;
582 __builtin_memmove(__result - _Num, __first,
sizeof(_Tp) * _Num);
583 return __result - _Num;
587 template<
bool _IsMove,
typename _BI1,
typename _BI2>
589 __copy_move_backward_a(_BI1 __first, _BI1 __last, _BI2 __result)
591 typedef typename iterator_traits<_BI1>::value_type _ValueType1;
592 typedef typename iterator_traits<_BI2>::value_type _ValueType2;
593 typedef typename iterator_traits<_BI1>::iterator_category _Category;
594 const bool __simple = (__is_trivial(_ValueType1)
595 && __is_pointer<_BI1>::__value
596 && __is_pointer<_BI2>::__value
597 && __are_same<_ValueType1, _ValueType2>::__value);
599 return std::__copy_move_backward<_IsMove, __simple,
600 _Category>::__copy_move_b(__first,
605 template<
bool _IsMove,
typename _BI1,
typename _BI2>
607 __copy_move_backward_a2(_BI1 __first, _BI1 __last, _BI2 __result)
609 return _BI2(std::__copy_move_backward_a<_IsMove>
610 (std::__niter_base(__first), std::__niter_base(__last),
611 std::__niter_base(__result)));
632 template<
typename _BI1,
typename _BI2>
634 copy_backward(_BI1 __first, _BI1 __last, _BI2 __result)
637 __glibcxx_function_requires(_BidirectionalIteratorConcept<_BI1>)
638 __glibcxx_function_requires(_Mutable_BidirectionalIteratorConcept<_BI2>)
639 __glibcxx_function_requires(_ConvertibleConcept<
640 typename iterator_traits<_BI1>::value_type,
641 typename iterator_traits<_BI2>::value_type>)
642 __glibcxx_requires_valid_range(__first, __last);
644 return (std::__copy_move_backward_a2<__is_move_iterator<_BI1>::__value>
645 (std::__miter_base(__first), std::__miter_base(__last),
649 #if __cplusplus >= 201103L
668 template<
typename _BI1,
typename _BI2>
673 __glibcxx_function_requires(_BidirectionalIteratorConcept<_BI1>)
674 __glibcxx_function_requires(_Mutable_BidirectionalIteratorConcept<_BI2>)
675 __glibcxx_function_requires(_ConvertibleConcept<
676 typename iterator_traits<_BI1>::value_type,
677 typename iterator_traits<_BI2>::value_type>)
678 __glibcxx_requires_valid_range(__first, __last);
680 return std::__copy_move_backward_a2<true>(std::__miter_base(__first),
681 std::__miter_base(__last),
685 #define _GLIBCXX_MOVE_BACKWARD3(_Tp, _Up, _Vp) std::move_backward(_Tp, _Up, _Vp)
687 #define _GLIBCXX_MOVE_BACKWARD3(_Tp, _Up, _Vp) std::copy_backward(_Tp, _Up, _Vp)
690 template<
typename _ForwardIterator,
typename _Tp>
692 __gnu_cxx::__enable_if<!__is_scalar<_Tp>::__value,
void>::__type
693 __fill_a(_ForwardIterator __first, _ForwardIterator __last,
696 for (; __first != __last; ++__first)
700 template<
typename _ForwardIterator,
typename _Tp>
702 __gnu_cxx::__enable_if<__is_scalar<_Tp>::__value,
void>::__type
703 __fill_a(_ForwardIterator __first, _ForwardIterator __last,
706 const _Tp __tmp = __value;
707 for (; __first != __last; ++__first)
712 template<
typename _Tp>
714 __gnu_cxx::__enable_if<__is_byte<_Tp>::__value,
void>::__type
715 __fill_a(_Tp* __first, _Tp* __last,
const _Tp& __c)
717 const _Tp __tmp = __c;
718 if (
const size_t __len = __last - __first)
719 __builtin_memset(__first, static_cast<unsigned char>(__tmp), __len);
734 template<
typename _ForwardIterator,
typename _Tp>
736 fill(_ForwardIterator __first, _ForwardIterator __last,
const _Tp& __value)
739 __glibcxx_function_requires(_Mutable_ForwardIteratorConcept<
741 __glibcxx_requires_valid_range(__first, __last);
743 std::__fill_a(std::__niter_base(__first), std::__niter_base(__last),
747 template<
typename _OutputIterator,
typename _Size,
typename _Tp>
749 __gnu_cxx::__enable_if<!__is_scalar<_Tp>::__value, _OutputIterator>::__type
750 __fill_n_a(_OutputIterator __first, _Size __n,
const _Tp& __value)
752 for (__decltype(__n + 0) __niter = __n;
753 __niter > 0; --__niter, ++__first)
758 template<
typename _OutputIterator,
typename _Size,
typename _Tp>
760 __gnu_cxx::__enable_if<__is_scalar<_Tp>::__value, _OutputIterator>::__type
761 __fill_n_a(_OutputIterator __first, _Size __n,
const _Tp& __value)
763 const _Tp __tmp = __value;
764 for (__decltype(__n + 0) __niter = __n;
765 __niter > 0; --__niter, ++__first)
770 template<
typename _Size,
typename _Tp>
772 __gnu_cxx::__enable_if<__is_byte<_Tp>::__value, _Tp*>::__type
773 __fill_n_a(_Tp* __first, _Size __n,
const _Tp& __c)
775 std::__fill_a(__first, __first + __n, __c);
776 return __first + __n;
794 template<
typename _OI,
typename _Size,
typename _Tp>
796 fill_n(_OI __first, _Size __n,
const _Tp& __value)
799 __glibcxx_function_requires(_OutputIteratorConcept<_OI, _Tp>)
801 return _OI(std::__fill_n_a(std::__niter_base(__first), __n, __value));
804 template<
bool _BoolType>
807 template<
typename _II1,
typename _II2>
809 equal(_II1 __first1, _II1 __last1, _II2 __first2)
811 for (; __first1 != __last1; ++__first1, ++__first2)
812 if (!(*__first1 == *__first2))
821 template<
typename _Tp>
823 equal(
const _Tp* __first1,
const _Tp* __last1,
const _Tp* __first2)
825 if (
const size_t __len = (__last1 - __first1))
826 return !__builtin_memcmp(__first1, __first2,
sizeof(_Tp) * __len);
831 template<
typename _II1,
typename _II2>
833 __equal_aux(_II1 __first1, _II1 __last1, _II2 __first2)
835 typedef typename iterator_traits<_II1>::value_type _ValueType1;
836 typedef typename iterator_traits<_II2>::value_type _ValueType2;
837 const bool __simple = ((__is_integer<_ValueType1>::__value
838 || __is_pointer<_ValueType1>::__value)
839 && __is_pointer<_II1>::__value
840 && __is_pointer<_II2>::__value
841 && __are_same<_ValueType1, _ValueType2>::__value);
846 template<
typename,
typename>
849 template<
typename _II1,
typename _II2>
851 __newlast1(_II1, _II1 __last1, _II2, _II2)
854 template<
typename _II>
856 __cnd2(_II __first, _II __last)
857 {
return __first != __last; }
861 struct __lc_rai<random_access_iterator_tag, random_access_iterator_tag>
863 template<
typename _RAI1,
typename _RAI2>
865 __newlast1(_RAI1 __first1, _RAI1 __last1,
866 _RAI2 __first2, _RAI2 __last2)
868 const typename iterator_traits<_RAI1>::difference_type
869 __diff1 = __last1 - __first1;
870 const typename iterator_traits<_RAI2>::difference_type
871 __diff2 = __last2 - __first2;
872 return __diff2 < __diff1 ? __first1 + __diff2 : __last1;
875 template<
typename _RAI>
881 template<
typename _II1,
typename _II2,
typename _Compare>
883 __lexicographical_compare_impl(_II1 __first1, _II1 __last1,
884 _II2 __first2, _II2 __last2,
887 typedef typename iterator_traits<_II1>::iterator_category _Category1;
888 typedef typename iterator_traits<_II2>::iterator_category _Category2;
889 typedef std::__lc_rai<_Category1, _Category2> __rai_type;
891 __last1 = __rai_type::__newlast1(__first1, __last1, __first2, __last2);
892 for (; __first1 != __last1 && __rai_type::__cnd2(__first2, __last2);
893 ++__first1, ++__first2)
895 if (__comp(__first1, __first2))
897 if (__comp(__first2, __first1))
900 return __first1 == __last1 && __first2 != __last2;
903 template<
bool _BoolType>
904 struct __lexicographical_compare
906 template<
typename _II1,
typename _II2>
907 static bool __lc(_II1, _II1, _II2, _II2);
910 template<
bool _BoolType>
911 template<
typename _II1,
typename _II2>
913 __lexicographical_compare<_BoolType>::
914 __lc(_II1 __first1, _II1 __last1, _II2 __first2, _II2 __last2)
916 return std::__lexicographical_compare_impl(__first1, __last1,
918 __gnu_cxx::__ops::__iter_less_iter());
922 struct __lexicographical_compare<true>
924 template<
typename _Tp,
typename _Up>
926 __lc(
const _Tp* __first1,
const _Tp* __last1,
927 const _Up* __first2,
const _Up* __last2)
929 const size_t __len1 = __last1 - __first1;
930 const size_t __len2 = __last2 - __first2;
931 if (
const size_t __len =
std::min(__len1, __len2))
932 if (
int __result = __builtin_memcmp(__first1, __first2, __len))
934 return __len1 < __len2;
938 template<
typename _II1,
typename _II2>
940 __lexicographical_compare_aux(_II1 __first1, _II1 __last1,
941 _II2 __first2, _II2 __last2)
943 typedef typename iterator_traits<_II1>::value_type _ValueType1;
944 typedef typename iterator_traits<_II2>::value_type _ValueType2;
945 const bool __simple =
946 (__is_byte<_ValueType1>::__value && __is_byte<_ValueType2>::__value
947 && !__gnu_cxx::__numeric_traits<_ValueType1>::__is_signed
948 && !__gnu_cxx::__numeric_traits<_ValueType2>::__is_signed
949 && __is_pointer<_II1>::__value
950 && __is_pointer<_II2>::__value);
952 return std::__lexicographical_compare<__simple>::__lc(__first1, __last1,
956 template<
typename _ForwardIterator,
typename _Tp,
typename _Compare>
958 __lower_bound(_ForwardIterator __first, _ForwardIterator __last,
959 const _Tp& __val, _Compare __comp)
961 typedef typename iterator_traits<_ForwardIterator>::difference_type
968 _DistanceType __half = __len >> 1;
969 _ForwardIterator __middle = __first;
971 if (__comp(__middle, __val))
975 __len = __len - __half - 1;
994 template<
typename _ForwardIterator,
typename _Tp>
995 inline _ForwardIterator
996 lower_bound(_ForwardIterator __first, _ForwardIterator __last,
1000 __glibcxx_function_requires(_ForwardIteratorConcept<_ForwardIterator>)
1001 __glibcxx_function_requires(_LessThanOpConcept<
1002 typename iterator_traits<_ForwardIterator>::value_type, _Tp>)
1003 __glibcxx_requires_partitioned_lower(__first, __last, __val);
1005 return std::__lower_bound(__first, __last, __val,
1006 __gnu_cxx::__ops::__iter_less_val());
1011 inline _GLIBCXX_CONSTEXPR
int
1013 {
return sizeof(int) * __CHAR_BIT__ - 1 - __builtin_clz(__n); }
1015 inline _GLIBCXX_CONSTEXPR
unsigned
1017 {
return sizeof(int) * __CHAR_BIT__ - 1 - __builtin_clz(__n); }
1019 inline _GLIBCXX_CONSTEXPR
long
1021 {
return sizeof(long) * __CHAR_BIT__ - 1 - __builtin_clzl(__n); }
1023 inline _GLIBCXX_CONSTEXPR
unsigned long
1024 __lg(
unsigned long __n)
1025 {
return sizeof(long) * __CHAR_BIT__ - 1 - __builtin_clzl(__n); }
1027 inline _GLIBCXX_CONSTEXPR
long long
1029 {
return sizeof(
long long) * __CHAR_BIT__ - 1 - __builtin_clzll(__n); }
1031 inline _GLIBCXX_CONSTEXPR
unsigned long long
1032 __lg(
unsigned long long __n)
1033 {
return sizeof(
long long) * __CHAR_BIT__ - 1 - __builtin_clzll(__n); }
1035 _GLIBCXX_END_NAMESPACE_VERSION
1037 _GLIBCXX_BEGIN_NAMESPACE_ALGO
1051 template<
typename _II1,
typename _II2>
1053 equal(_II1 __first1, _II1 __last1, _II2 __first2)
1056 __glibcxx_function_requires(_InputIteratorConcept<_II1>)
1057 __glibcxx_function_requires(_InputIteratorConcept<_II2>)
1058 __glibcxx_function_requires(_EqualOpConcept<
1059 typename iterator_traits<_II1>::value_type,
1060 typename iterator_traits<_II2>::value_type>)
1061 __glibcxx_requires_valid_range(__first1, __last1);
1063 return std::__equal_aux(std::__niter_base(__first1),
1064 std::__niter_base(__last1),
1065 std::__niter_base(__first2));
1083 template<
typename _IIter1,
typename _IIter2,
typename _BinaryPredicate>
1085 equal(_IIter1 __first1, _IIter1 __last1,
1086 _IIter2 __first2, _BinaryPredicate __binary_pred)
1089 __glibcxx_function_requires(_InputIteratorConcept<_IIter1>)
1090 __glibcxx_function_requires(_InputIteratorConcept<_IIter2>)
1091 __glibcxx_requires_valid_range(__first1, __last1);
1093 for (; __first1 != __last1; ++__first1, ++__first2)
1094 if (!
bool(__binary_pred(*__first1, *__first2)))
1099 #if __cplusplus > 201103L
1101 #define __cpp_lib_robust_nonmodifying_seq_ops 201304
1116 template<
typename _II1,
typename _II2>
1118 equal(_II1 __first1, _II1 __last1, _II2 __first2, _II2 __last2)
1121 __glibcxx_function_requires(_InputIteratorConcept<_II1>)
1122 __glibcxx_function_requires(_InputIteratorConcept<_II2>)
1123 __glibcxx_function_requires(_EqualOpConcept<
1124 typename iterator_traits<_II1>::value_type,
1125 typename iterator_traits<_II2>::value_type>)
1126 __glibcxx_requires_valid_range(__first1, __last1);
1127 __glibcxx_requires_valid_range(__first2, __last2);
1129 using _RATag = random_access_iterator_tag;
1130 using _Cat1 = typename iterator_traits<_II1>::iterator_category;
1131 using _Cat2 = typename iterator_traits<_II2>::iterator_category;
1132 using _RAIters = __and_<is_same<_Cat1, _RATag>, is_same<_Cat2, _RATag>>;
1142 for (; __first1 != __last1 && __first2 != __last2; ++__first1, ++__first2)
1143 if (!(*__first1 == *__first2))
1145 return __first1 == __last1 && __first2 == __last2;
1164 template<
typename _IIter1,
typename _IIter2,
typename _BinaryPredicate>
1166 equal(_IIter1 __first1, _IIter1 __last1,
1167 _IIter2 __first2, _IIter2 __last2, _BinaryPredicate __binary_pred)
1170 __glibcxx_function_requires(_InputIteratorConcept<_IIter1>)
1171 __glibcxx_function_requires(_InputIteratorConcept<_IIter2>)
1172 __glibcxx_requires_valid_range(__first1, __last1);
1173 __glibcxx_requires_valid_range(__first2, __last2);
1175 using _RATag = random_access_iterator_tag;
1176 using _Cat1 = typename iterator_traits<_IIter1>::iterator_category;
1177 using _Cat2 = typename iterator_traits<_IIter2>::iterator_category;
1178 using _RAIters = __and_<is_same<_Cat1, _RATag>, is_same<_Cat2, _RATag>>;
1189 for (; __first1 != __last1 && __first2 != __last2; ++__first1, ++__first2)
1190 if (!
bool(__binary_pred(*__first1, *__first2)))
1192 return __first1 == __last1 && __first2 == __last2;
1211 template<
typename _II1,
typename _II2>
1213 lexicographical_compare(_II1 __first1, _II1 __last1,
1214 _II2 __first2, _II2 __last2)
1216 #ifdef _GLIBCXX_CONCEPT_CHECKS
1218 typedef typename iterator_traits<_II1>::value_type _ValueType1;
1219 typedef typename iterator_traits<_II2>::value_type _ValueType2;
1221 __glibcxx_function_requires(_InputIteratorConcept<_II1>)
1222 __glibcxx_function_requires(_InputIteratorConcept<_II2>)
1223 __glibcxx_function_requires(_LessThanOpConcept<_ValueType1, _ValueType2>)
1224 __glibcxx_function_requires(_LessThanOpConcept<_ValueType2, _ValueType1>)
1225 __glibcxx_requires_valid_range(__first1, __last1);
1226 __glibcxx_requires_valid_range(__first2, __last2);
1228 return std::__lexicographical_compare_aux(std::__niter_base(__first1),
1229 std::__niter_base(__last1),
1230 std::__niter_base(__first2),
1231 std::__niter_base(__last2));
1247 template<
typename _II1,
typename _II2,
typename _Compare>
1249 lexicographical_compare(_II1 __first1, _II1 __last1,
1250 _II2 __first2, _II2 __last2, _Compare __comp)
1253 __glibcxx_function_requires(_InputIteratorConcept<_II1>)
1254 __glibcxx_function_requires(_InputIteratorConcept<_II2>)
1255 __glibcxx_requires_valid_range(__first1, __last1);
1256 __glibcxx_requires_valid_range(__first2, __last2);
1258 return std::__lexicographical_compare_impl
1259 (__first1, __last1, __first2, __last2,
1260 __gnu_cxx::__ops::__iter_comp_iter(__comp));
1263 template<
typename _InputIterator1,
typename _InputIterator2,
1264 typename _BinaryPredicate>
1265 pair<_InputIterator1, _InputIterator2>
1266 __mismatch(_InputIterator1 __first1, _InputIterator1 __last1,
1267 _InputIterator2 __first2, _BinaryPredicate __binary_pred)
1269 while (__first1 != __last1 && __binary_pred(__first1, __first2))
1274 return pair<_InputIterator1, _InputIterator2>(__first1, __first2);
1290 template<
typename _InputIterator1,
typename _InputIterator2>
1291 inline pair<_InputIterator1, _InputIterator2>
1292 mismatch(_InputIterator1 __first1, _InputIterator1 __last1,
1293 _InputIterator2 __first2)
1296 __glibcxx_function_requires(_InputIteratorConcept<_InputIterator1>)
1297 __glibcxx_function_requires(_InputIteratorConcept<_InputIterator2>)
1298 __glibcxx_function_requires(_EqualOpConcept<
1299 typename iterator_traits<_InputIterator1>::value_type,
1300 typename iterator_traits<_InputIterator2>::value_type>)
1301 __glibcxx_requires_valid_range(__first1, __last1);
1303 return _GLIBCXX_STD_A::__mismatch(__first1, __last1, __first2,
1304 __gnu_cxx::__ops::__iter_equal_to_iter());
1323 template<
typename _InputIterator1,
typename _InputIterator2,
1324 typename _BinaryPredicate>
1325 inline pair<_InputIterator1, _InputIterator2>
1326 mismatch(_InputIterator1 __first1, _InputIterator1 __last1,
1327 _InputIterator2 __first2, _BinaryPredicate __binary_pred)
1330 __glibcxx_function_requires(_InputIteratorConcept<_InputIterator1>)
1331 __glibcxx_function_requires(_InputIteratorConcept<_InputIterator2>)
1332 __glibcxx_requires_valid_range(__first1, __last1);
1334 return _GLIBCXX_STD_A::__mismatch(__first1, __last1, __first2,
1335 __gnu_cxx::__ops::__iter_comp_iter(__binary_pred));
1338 #if __cplusplus > 201103L
1340 template<
typename _InputIterator1,
typename _InputIterator2,
1341 typename _BinaryPredicate>
1342 pair<_InputIterator1, _InputIterator2>
1343 __mismatch(_InputIterator1 __first1, _InputIterator1 __last1,
1344 _InputIterator2 __first2, _InputIterator2 __last2,
1345 _BinaryPredicate __binary_pred)
1347 while (__first1 != __last1 && __first2 != __last2
1348 && __binary_pred(__first1, __first2))
1353 return pair<_InputIterator1, _InputIterator2>(__first1, __first2);
1370 template<
typename _InputIterator1,
typename _InputIterator2>
1371 inline pair<_InputIterator1, _InputIterator2>
1372 mismatch(_InputIterator1 __first1, _InputIterator1 __last1,
1373 _InputIterator2 __first2, _InputIterator2 __last2)
1376 __glibcxx_function_requires(_InputIteratorConcept<_InputIterator1>)
1377 __glibcxx_function_requires(_InputIteratorConcept<_InputIterator2>)
1378 __glibcxx_function_requires(_EqualOpConcept<
1379 typename iterator_traits<_InputIterator1>::value_type,
1380 typename iterator_traits<_InputIterator2>::value_type>)
1381 __glibcxx_requires_valid_range(__first1, __last1);
1382 __glibcxx_requires_valid_range(__first2, __last2);
1384 return _GLIBCXX_STD_A::__mismatch(__first1, __last1, __first2, __last2,
1385 __gnu_cxx::__ops::__iter_equal_to_iter());
1405 template<typename _InputIterator1, typename _InputIterator2,
1406 typename _BinaryPredicate>
1407 inline pair<_InputIterator1, _InputIterator2>
1408 mismatch(_InputIterator1 __first1, _InputIterator1 __last1,
1409 _InputIterator2 __first2, _InputIterator2 __last2,
1410 _BinaryPredicate __binary_pred)
1413 __glibcxx_function_requires(_InputIteratorConcept<_InputIterator1>)
1414 __glibcxx_function_requires(_InputIteratorConcept<_InputIterator2>)
1415 __glibcxx_requires_valid_range(__first1, __last1);
1416 __glibcxx_requires_valid_range(__first2, __last2);
1418 return _GLIBCXX_STD_A::__mismatch(__first1, __last1, __first2, __last2,
1419 __gnu_cxx::__ops::__iter_comp_iter(__binary_pred));
1423 _GLIBCXX_END_NAMESPACE_ALGO
1429 #ifdef _GLIBCXX_PARALLEL
void swap(_Tp &, _Tp &) noexcept(__and_< is_nothrow_move_constructible< _Tp >, is_nothrow_move_assignable< _Tp >>::value)
Swaps two values.
constexpr int __lg(int __n)
This is a helper function for the sort routines and for random.tcc.
void iter_swap(_ForwardIterator1 __a, _ForwardIterator2 __b)
Swaps the contents of two iterators.
Basis for explicit traits specializations.
void advance(_InputIterator &__i, _Distance __n)
A generalization of pointer arithmetic.
Parallel STL function calls corresponding to the stl_algobase.h header. The functions defined here ma...
_GLIBCXX14_CONSTEXPR const _Tp & max(const _Tp &, const _Tp &)
This does what you think it does.
bool equal(_II1 __first1, _II1 __last1, _II2 __first2)
Tests a range for element-wise equality.
_BI2 move_backward(_BI1 __first, _BI1 __last, _BI2 __result)
Moves the range [first,last) into result.
_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.
Provides output iterator semantics for streambufs.
GNU extensions for public use.
iterator_traits< _InputIterator >::difference_type distance(_InputIterator __first, _InputIterator __last)
A generalization of pointer arithmetic.
Provides input iterator semantics for streambufs.
ISO C++ entities toplevel namespace is std.
constexpr std::remove_reference< _Tp >::type && move(_Tp &&__t) noexcept
Convert a value to an rvalue.