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 __builtin_memset(__first, static_cast<unsigned char>(__tmp),
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 return !__builtin_memcmp(__first1, __first2,
sizeof(_Tp)
826 * (__last1 - __first1));
830 template<
typename _II1,
typename _II2>
832 __equal_aux(_II1 __first1, _II1 __last1, _II2 __first2)
834 typedef typename iterator_traits<_II1>::value_type _ValueType1;
835 typedef typename iterator_traits<_II2>::value_type _ValueType2;
836 const bool __simple = ((__is_integer<_ValueType1>::__value
837 || __is_pointer<_ValueType1>::__value)
838 && __is_pointer<_II1>::__value
839 && __is_pointer<_II2>::__value
840 && __are_same<_ValueType1, _ValueType2>::__value);
845 template<
typename,
typename>
848 template<
typename _II1,
typename _II2>
850 __newlast1(_II1, _II1 __last1, _II2, _II2)
853 template<
typename _II>
855 __cnd2(_II __first, _II __last)
856 {
return __first != __last; }
860 struct __lc_rai<random_access_iterator_tag, random_access_iterator_tag>
862 template<
typename _RAI1,
typename _RAI2>
864 __newlast1(_RAI1 __first1, _RAI1 __last1,
865 _RAI2 __first2, _RAI2 __last2)
867 const typename iterator_traits<_RAI1>::difference_type
868 __diff1 = __last1 - __first1;
869 const typename iterator_traits<_RAI2>::difference_type
870 __diff2 = __last2 - __first2;
871 return __diff2 < __diff1 ? __first1 + __diff2 : __last1;
874 template<
typename _RAI>
880 template<
typename _II1,
typename _II2,
typename _Compare>
882 __lexicographical_compare_impl(_II1 __first1, _II1 __last1,
883 _II2 __first2, _II2 __last2,
886 typedef typename iterator_traits<_II1>::iterator_category _Category1;
887 typedef typename iterator_traits<_II2>::iterator_category _Category2;
888 typedef std::__lc_rai<_Category1, _Category2> __rai_type;
890 __last1 = __rai_type::__newlast1(__first1, __last1, __first2, __last2);
891 for (; __first1 != __last1 && __rai_type::__cnd2(__first2, __last2);
892 ++__first1, ++__first2)
894 if (__comp(__first1, __first2))
896 if (__comp(__first2, __first1))
899 return __first1 == __last1 && __first2 != __last2;
902 template<
bool _BoolType>
903 struct __lexicographical_compare
905 template<
typename _II1,
typename _II2>
906 static bool __lc(_II1, _II1, _II2, _II2);
909 template<
bool _BoolType>
910 template<
typename _II1,
typename _II2>
912 __lexicographical_compare<_BoolType>::
913 __lc(_II1 __first1, _II1 __last1, _II2 __first2, _II2 __last2)
915 return std::__lexicographical_compare_impl(__first1, __last1,
917 __gnu_cxx::__ops::__iter_less_iter());
921 struct __lexicographical_compare<true>
923 template<
typename _Tp,
typename _Up>
925 __lc(
const _Tp* __first1,
const _Tp* __last1,
926 const _Up* __first2,
const _Up* __last2)
928 const size_t __len1 = __last1 - __first1;
929 const size_t __len2 = __last2 - __first2;
930 const int __result = __builtin_memcmp(__first1, __first2,
932 return __result != 0 ? __result < 0 : __len1 < __len2;
936 template<
typename _II1,
typename _II2>
938 __lexicographical_compare_aux(_II1 __first1, _II1 __last1,
939 _II2 __first2, _II2 __last2)
941 typedef typename iterator_traits<_II1>::value_type _ValueType1;
942 typedef typename iterator_traits<_II2>::value_type _ValueType2;
943 const bool __simple =
944 (__is_byte<_ValueType1>::__value && __is_byte<_ValueType2>::__value
945 && !__gnu_cxx::__numeric_traits<_ValueType1>::__is_signed
946 && !__gnu_cxx::__numeric_traits<_ValueType2>::__is_signed
947 && __is_pointer<_II1>::__value
948 && __is_pointer<_II2>::__value);
950 return std::__lexicographical_compare<__simple>::__lc(__first1, __last1,
954 template<
typename _ForwardIterator,
typename _Tp,
typename _Compare>
956 __lower_bound(_ForwardIterator __first, _ForwardIterator __last,
957 const _Tp& __val, _Compare __comp)
959 typedef typename iterator_traits<_ForwardIterator>::difference_type
966 _DistanceType __half = __len >> 1;
967 _ForwardIterator __middle = __first;
969 if (__comp(__middle, __val))
973 __len = __len - __half - 1;
992 template<
typename _ForwardIterator,
typename _Tp>
993 inline _ForwardIterator
994 lower_bound(_ForwardIterator __first, _ForwardIterator __last,
998 __glibcxx_function_requires(_ForwardIteratorConcept<_ForwardIterator>)
999 __glibcxx_function_requires(_LessThanOpConcept<
1000 typename iterator_traits<_ForwardIterator>::value_type, _Tp>)
1001 __glibcxx_requires_partitioned_lower(__first, __last, __val);
1003 return std::__lower_bound(__first, __last, __val,
1004 __gnu_cxx::__ops::__iter_less_val());
1009 inline _GLIBCXX_CONSTEXPR
int
1011 {
return sizeof(int) * __CHAR_BIT__ - 1 - __builtin_clz(__n); }
1013 inline _GLIBCXX_CONSTEXPR
unsigned
1015 {
return sizeof(int) * __CHAR_BIT__ - 1 - __builtin_clz(__n); }
1017 inline _GLIBCXX_CONSTEXPR
long
1019 {
return sizeof(long) * __CHAR_BIT__ - 1 - __builtin_clzl(__n); }
1021 inline _GLIBCXX_CONSTEXPR
unsigned long
1022 __lg(
unsigned long __n)
1023 {
return sizeof(long) * __CHAR_BIT__ - 1 - __builtin_clzl(__n); }
1025 inline _GLIBCXX_CONSTEXPR
long long
1027 {
return sizeof(
long long) * __CHAR_BIT__ - 1 - __builtin_clzll(__n); }
1029 inline _GLIBCXX_CONSTEXPR
unsigned long long
1030 __lg(
unsigned long long __n)
1031 {
return sizeof(
long long) * __CHAR_BIT__ - 1 - __builtin_clzll(__n); }
1033 _GLIBCXX_END_NAMESPACE_VERSION
1035 _GLIBCXX_BEGIN_NAMESPACE_ALGO
1049 template<
typename _II1,
typename _II2>
1051 equal(_II1 __first1, _II1 __last1, _II2 __first2)
1054 __glibcxx_function_requires(_InputIteratorConcept<_II1>)
1055 __glibcxx_function_requires(_InputIteratorConcept<_II2>)
1056 __glibcxx_function_requires(_EqualOpConcept<
1057 typename iterator_traits<_II1>::value_type,
1058 typename iterator_traits<_II2>::value_type>)
1059 __glibcxx_requires_valid_range(__first1, __last1);
1061 return std::__equal_aux(std::__niter_base(__first1),
1062 std::__niter_base(__last1),
1063 std::__niter_base(__first2));
1081 template<
typename _IIter1,
typename _IIter2,
typename _BinaryPredicate>
1083 equal(_IIter1 __first1, _IIter1 __last1,
1084 _IIter2 __first2, _BinaryPredicate __binary_pred)
1087 __glibcxx_function_requires(_InputIteratorConcept<_IIter1>)
1088 __glibcxx_function_requires(_InputIteratorConcept<_IIter2>)
1089 __glibcxx_requires_valid_range(__first1, __last1);
1091 for (; __first1 != __last1; ++__first1, ++__first2)
1092 if (!
bool(__binary_pred(*__first1, *__first2)))
1097 #if __cplusplus > 201103L
1099 #define __cpp_lib_robust_nonmodifying_seq_ops 201304
1114 template<
typename _II1,
typename _II2>
1116 equal(_II1 __first1, _II1 __last1, _II2 __first2, _II2 __last2)
1119 __glibcxx_function_requires(_InputIteratorConcept<_II1>)
1120 __glibcxx_function_requires(_InputIteratorConcept<_II2>)
1121 __glibcxx_function_requires(_EqualOpConcept<
1122 typename iterator_traits<_II1>::value_type,
1123 typename iterator_traits<_II2>::value_type>)
1124 __glibcxx_requires_valid_range(__first1, __last1);
1125 __glibcxx_requires_valid_range(__first2, __last2);
1127 using _RATag = random_access_iterator_tag;
1128 using _Cat1 = typename iterator_traits<_II1>::iterator_category;
1129 using _Cat2 = typename iterator_traits<_II2>::iterator_category;
1130 using _RAIters = __and_<is_same<_Cat1, _RATag>, is_same<_Cat2, _RATag>>;
1140 for (; __first1 != __last1 && __first2 != __last2; ++__first1, ++__first2)
1141 if (!(*__first1 == *__first2))
1143 return __first1 == __last1 && __first2 == __last2;
1162 template<
typename _IIter1,
typename _IIter2,
typename _BinaryPredicate>
1164 equal(_IIter1 __first1, _IIter1 __last1,
1165 _IIter2 __first2, _IIter2 __last2, _BinaryPredicate __binary_pred)
1168 __glibcxx_function_requires(_InputIteratorConcept<_IIter1>)
1169 __glibcxx_function_requires(_InputIteratorConcept<_IIter2>)
1170 __glibcxx_requires_valid_range(__first1, __last1);
1171 __glibcxx_requires_valid_range(__first2, __last2);
1173 using _RATag = random_access_iterator_tag;
1174 using _Cat1 = typename iterator_traits<_IIter1>::iterator_category;
1175 using _Cat2 = typename iterator_traits<_IIter2>::iterator_category;
1176 using _RAIters = __and_<is_same<_Cat1, _RATag>, is_same<_Cat2, _RATag>>;
1187 for (; __first1 != __last1 && __first2 != __last2; ++__first1, ++__first2)
1188 if (!
bool(__binary_pred(*__first1, *__first2)))
1190 return __first1 == __last1 && __first2 == __last2;
1209 template<
typename _II1,
typename _II2>
1211 lexicographical_compare(_II1 __first1, _II1 __last1,
1212 _II2 __first2, _II2 __last2)
1214 #ifdef _GLIBCXX_CONCEPT_CHECKS
1216 typedef typename iterator_traits<_II1>::value_type _ValueType1;
1217 typedef typename iterator_traits<_II2>::value_type _ValueType2;
1219 __glibcxx_function_requires(_InputIteratorConcept<_II1>)
1220 __glibcxx_function_requires(_InputIteratorConcept<_II2>)
1221 __glibcxx_function_requires(_LessThanOpConcept<_ValueType1, _ValueType2>)
1222 __glibcxx_function_requires(_LessThanOpConcept<_ValueType2, _ValueType1>)
1223 __glibcxx_requires_valid_range(__first1, __last1);
1224 __glibcxx_requires_valid_range(__first2, __last2);
1226 return std::__lexicographical_compare_aux(std::__niter_base(__first1),
1227 std::__niter_base(__last1),
1228 std::__niter_base(__first2),
1229 std::__niter_base(__last2));
1245 template<
typename _II1,
typename _II2,
typename _Compare>
1247 lexicographical_compare(_II1 __first1, _II1 __last1,
1248 _II2 __first2, _II2 __last2, _Compare __comp)
1251 __glibcxx_function_requires(_InputIteratorConcept<_II1>)
1252 __glibcxx_function_requires(_InputIteratorConcept<_II2>)
1253 __glibcxx_requires_valid_range(__first1, __last1);
1254 __glibcxx_requires_valid_range(__first2, __last2);
1256 return std::__lexicographical_compare_impl
1257 (__first1, __last1, __first2, __last2,
1258 __gnu_cxx::__ops::__iter_comp_iter(__comp));
1261 template<
typename _InputIterator1,
typename _InputIterator2,
1262 typename _BinaryPredicate>
1263 pair<_InputIterator1, _InputIterator2>
1264 __mismatch(_InputIterator1 __first1, _InputIterator1 __last1,
1265 _InputIterator2 __first2, _BinaryPredicate __binary_pred)
1267 while (__first1 != __last1 && __binary_pred(__first1, __first2))
1272 return pair<_InputIterator1, _InputIterator2>(__first1, __first2);
1288 template<
typename _InputIterator1,
typename _InputIterator2>
1289 inline pair<_InputIterator1, _InputIterator2>
1290 mismatch(_InputIterator1 __first1, _InputIterator1 __last1,
1291 _InputIterator2 __first2)
1294 __glibcxx_function_requires(_InputIteratorConcept<_InputIterator1>)
1295 __glibcxx_function_requires(_InputIteratorConcept<_InputIterator2>)
1296 __glibcxx_function_requires(_EqualOpConcept<
1297 typename iterator_traits<_InputIterator1>::value_type,
1298 typename iterator_traits<_InputIterator2>::value_type>)
1299 __glibcxx_requires_valid_range(__first1, __last1);
1301 return _GLIBCXX_STD_A::__mismatch(__first1, __last1, __first2,
1302 __gnu_cxx::__ops::__iter_equal_to_iter());
1321 template<
typename _InputIterator1,
typename _InputIterator2,
1322 typename _BinaryPredicate>
1323 inline pair<_InputIterator1, _InputIterator2>
1324 mismatch(_InputIterator1 __first1, _InputIterator1 __last1,
1325 _InputIterator2 __first2, _BinaryPredicate __binary_pred)
1328 __glibcxx_function_requires(_InputIteratorConcept<_InputIterator1>)
1329 __glibcxx_function_requires(_InputIteratorConcept<_InputIterator2>)
1330 __glibcxx_requires_valid_range(__first1, __last1);
1332 return _GLIBCXX_STD_A::__mismatch(__first1, __last1, __first2,
1333 __gnu_cxx::__ops::__iter_comp_iter(__binary_pred));
1336 #if __cplusplus > 201103L
1338 template<
typename _InputIterator1,
typename _InputIterator2,
1339 typename _BinaryPredicate>
1340 pair<_InputIterator1, _InputIterator2>
1341 __mismatch(_InputIterator1 __first1, _InputIterator1 __last1,
1342 _InputIterator2 __first2, _InputIterator2 __last2,
1343 _BinaryPredicate __binary_pred)
1345 while (__first1 != __last1 && __first2 != __last2
1346 && __binary_pred(__first1, __first2))
1351 return pair<_InputIterator1, _InputIterator2>(__first1, __first2);
1368 template<
typename _InputIterator1,
typename _InputIterator2>
1369 inline pair<_InputIterator1, _InputIterator2>
1370 mismatch(_InputIterator1 __first1, _InputIterator1 __last1,
1371 _InputIterator2 __first2, _InputIterator2 __last2)
1374 __glibcxx_function_requires(_InputIteratorConcept<_InputIterator1>)
1375 __glibcxx_function_requires(_InputIteratorConcept<_InputIterator2>)
1376 __glibcxx_function_requires(_EqualOpConcept<
1377 typename iterator_traits<_InputIterator1>::value_type,
1378 typename iterator_traits<_InputIterator2>::value_type>)
1379 __glibcxx_requires_valid_range(__first1, __last1);
1380 __glibcxx_requires_valid_range(__first2, __last2);
1382 return _GLIBCXX_STD_A::__mismatch(__first1, __last1, __first2, __last2,
1383 __gnu_cxx::__ops::__iter_equal_to_iter());
1403 template<typename _InputIterator1, typename _InputIterator2,
1404 typename _BinaryPredicate>
1405 inline pair<_InputIterator1, _InputIterator2>
1406 mismatch(_InputIterator1 __first1, _InputIterator1 __last1,
1407 _InputIterator2 __first2, _InputIterator2 __last2,
1408 _BinaryPredicate __binary_pred)
1411 __glibcxx_function_requires(_InputIteratorConcept<_InputIterator1>)
1412 __glibcxx_function_requires(_InputIteratorConcept<_InputIterator2>)
1413 __glibcxx_requires_valid_range(__first1, __last1);
1414 __glibcxx_requires_valid_range(__first2, __last2);
1416 return _GLIBCXX_STD_A::__mismatch(__first1, __last1, __first2, __last2,
1417 __gnu_cxx::__ops::__iter_comp_iter(__binary_pred));
1421 _GLIBCXX_END_NAMESPACE_ALGO
1427 #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.