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>
194 min(
const _Tp& __a,
const _Tp& __b)
197 __glibcxx_function_requires(_LessThanComparableConcept<_Tp>)
215 template<
typename _Tp>
217 max(
const _Tp& __a,
const _Tp& __b)
220 __glibcxx_function_requires(_LessThanComparableConcept<_Tp>)
238 template<
typename _Tp,
typename _Compare>
240 min(
const _Tp& __a,
const _Tp& __b, _Compare __comp)
243 if (__comp(__b, __a))
259 template<
typename _Tp,
typename _Compare>
261 max(
const _Tp& __a,
const _Tp& __b, _Compare __comp)
264 if (__comp(__a, __b))
271 template<
typename _Iterator>
273 : _Iter_base<_Iterator, __is_normal_iterator<_Iterator>::__value>
276 template<
typename _Iterator>
277 inline typename _Niter_base<_Iterator>::iterator_type
278 __niter_base(_Iterator __it)
279 {
return std::_Niter_base<_Iterator>::_S_base(__it); }
282 template<
typename _Iterator>
284 : _Iter_base<_Iterator, __is_move_iterator<_Iterator>::__value>
287 template<
typename _Iterator>
288 inline typename _Miter_base<_Iterator>::iterator_type
289 __miter_base(_Iterator __it)
290 {
return std::_Miter_base<_Iterator>::_S_base(__it); }
298 template<
bool,
bool,
typename>
301 template<
typename _II,
typename _OI>
303 __copy_m(_II __first, _II __last, _OI __result)
305 for (; __first != __last; ++__result, ++__first)
306 *__result = *__first;
311 #if __cplusplus >= 201103L 312 template<
typename _Category>
313 struct __copy_move<true, false, _Category>
315 template<
typename _II,
typename _OI>
317 __copy_m(_II __first, _II __last, _OI __result)
319 for (; __first != __last; ++__result, ++__first)
327 struct __copy_move<false, false, random_access_iterator_tag>
329 template<
typename _II,
typename _OI>
331 __copy_m(_II __first, _II __last, _OI __result)
333 typedef typename iterator_traits<_II>::difference_type _Distance;
334 for(_Distance __n = __last - __first; __n > 0; --__n)
336 *__result = *__first;
344 #if __cplusplus >= 201103L 346 struct __copy_move<true, false, random_access_iterator_tag>
348 template<
typename _II,
typename _OI>
350 __copy_m(_II __first, _II __last, _OI __result)
352 typedef typename iterator_traits<_II>::difference_type _Distance;
353 for(_Distance __n = __last - __first; __n > 0; --__n)
364 template<
bool _IsMove>
365 struct __copy_move<_IsMove, true, random_access_iterator_tag>
367 template<
typename _Tp>
369 __copy_m(
const _Tp* __first,
const _Tp* __last, _Tp* __result)
371 #if __cplusplus >= 201103L 373 static_assert( is_copy_assignable<_Tp>::value,
374 "type is not assignable" );
376 const ptrdiff_t _Num = __last - __first;
378 __builtin_memmove(__result, __first,
sizeof(_Tp) * _Num);
379 return __result + _Num;
383 template<
bool _IsMove,
typename _II,
typename _OI>
385 __copy_move_a(_II __first, _II __last, _OI __result)
387 typedef typename iterator_traits<_II>::value_type _ValueTypeI;
388 typedef typename iterator_traits<_OI>::value_type _ValueTypeO;
389 typedef typename iterator_traits<_II>::iterator_category _Category;
390 const bool __simple = (__is_trivial(_ValueTypeI)
391 && __is_pointer<_II>::__value
392 && __is_pointer<_OI>::__value
393 && __are_same<_ValueTypeI, _ValueTypeO>::__value);
395 return std::__copy_move<_IsMove, __simple,
396 _Category>::__copy_m(__first, __last, __result);
401 template<
typename _CharT>
404 template<
typename _CharT,
typename _Traits>
407 template<
typename _CharT,
typename _Traits>
410 template<
bool _IsMove,
typename _CharT>
411 typename __gnu_cxx::__enable_if<__is_char<_CharT>::__value,
413 __copy_move_a2(_CharT*, _CharT*,
416 template<
bool _IsMove,
typename _CharT>
417 typename __gnu_cxx::__enable_if<__is_char<_CharT>::__value,
419 __copy_move_a2(
const _CharT*,
const _CharT*,
422 template<
bool _IsMove,
typename _CharT>
423 typename __gnu_cxx::__enable_if<__is_char<_CharT>::__value,
428 template<
bool _IsMove,
typename _II,
typename _OI>
430 __copy_move_a2(_II __first, _II __last, _OI __result)
432 return _OI(std::__copy_move_a<_IsMove>(std::__niter_base(__first),
433 std::__niter_base(__last),
434 std::__niter_base(__result)));
454 template<
typename _II,
typename _OI>
456 copy(_II __first, _II __last, _OI __result)
459 __glibcxx_function_requires(_InputIteratorConcept<_II>)
460 __glibcxx_function_requires(_OutputIteratorConcept<_OI,
461 typename iterator_traits<_II>::value_type>)
462 __glibcxx_requires_valid_range(__first, __last);
464 return (std::__copy_move_a2<__is_move_iterator<_II>::__value>
465 (std::__miter_base(__first), std::__miter_base(__last),
469 #if __cplusplus >= 201103L 487 template<
typename _II,
typename _OI>
489 move(_II __first, _II __last, _OI __result)
492 __glibcxx_function_requires(_InputIteratorConcept<_II>)
493 __glibcxx_function_requires(_OutputIteratorConcept<_OI,
494 typename iterator_traits<_II>::value_type>)
495 __glibcxx_requires_valid_range(__first, __last);
497 return std::__copy_move_a2<true>(std::__miter_base(__first),
498 std::__miter_base(__last), __result);
501 #define _GLIBCXX_MOVE3(_Tp, _Up, _Vp) std::move(_Tp, _Up, _Vp) 503 #define _GLIBCXX_MOVE3(_Tp, _Up, _Vp) std::copy(_Tp, _Up, _Vp) 506 template<
bool,
bool,
typename>
507 struct __copy_move_backward
509 template<
typename _BI1,
typename _BI2>
511 __copy_move_b(_BI1 __first, _BI1 __last, _BI2 __result)
513 while (__first != __last)
514 *--__result = *--__last;
519 #if __cplusplus >= 201103L 520 template<
typename _Category>
521 struct __copy_move_backward<true, false, _Category>
523 template<
typename _BI1,
typename _BI2>
525 __copy_move_b(_BI1 __first, _BI1 __last, _BI2 __result)
527 while (__first != __last)
535 struct __copy_move_backward<false, false, random_access_iterator_tag>
537 template<
typename _BI1,
typename _BI2>
539 __copy_move_b(_BI1 __first, _BI1 __last, _BI2 __result)
541 typename iterator_traits<_BI1>::difference_type __n;
542 for (__n = __last - __first; __n > 0; --__n)
543 *--__result = *--__last;
548 #if __cplusplus >= 201103L 550 struct __copy_move_backward<true, false, random_access_iterator_tag>
552 template<
typename _BI1,
typename _BI2>
554 __copy_move_b(_BI1 __first, _BI1 __last, _BI2 __result)
556 typename iterator_traits<_BI1>::difference_type __n;
557 for (__n = __last - __first; __n > 0; --__n)
564 template<
bool _IsMove>
565 struct __copy_move_backward<_IsMove, true, random_access_iterator_tag>
567 template<
typename _Tp>
569 __copy_move_b(
const _Tp* __first,
const _Tp* __last, _Tp* __result)
571 #if __cplusplus >= 201103L 573 static_assert( is_copy_assignable<_Tp>::value,
574 "type is not assignable" );
576 const ptrdiff_t _Num = __last - __first;
578 __builtin_memmove(__result - _Num, __first,
sizeof(_Tp) * _Num);
579 return __result - _Num;
583 template<
bool _IsMove,
typename _BI1,
typename _BI2>
585 __copy_move_backward_a(_BI1 __first, _BI1 __last, _BI2 __result)
587 typedef typename iterator_traits<_BI1>::value_type _ValueType1;
588 typedef typename iterator_traits<_BI2>::value_type _ValueType2;
589 typedef typename iterator_traits<_BI1>::iterator_category _Category;
590 const bool __simple = (__is_trivial(_ValueType1)
591 && __is_pointer<_BI1>::__value
592 && __is_pointer<_BI2>::__value
593 && __are_same<_ValueType1, _ValueType2>::__value);
595 return std::__copy_move_backward<_IsMove, __simple,
596 _Category>::__copy_move_b(__first,
601 template<
bool _IsMove,
typename _BI1,
typename _BI2>
603 __copy_move_backward_a2(_BI1 __first, _BI1 __last, _BI2 __result)
605 return _BI2(std::__copy_move_backward_a<_IsMove>
606 (std::__niter_base(__first), std::__niter_base(__last),
607 std::__niter_base(__result)));
628 template<
typename _BI1,
typename _BI2>
630 copy_backward(_BI1 __first, _BI1 __last, _BI2 __result)
633 __glibcxx_function_requires(_BidirectionalIteratorConcept<_BI1>)
634 __glibcxx_function_requires(_Mutable_BidirectionalIteratorConcept<_BI2>)
635 __glibcxx_function_requires(_ConvertibleConcept<
636 typename iterator_traits<_BI1>::value_type,
637 typename iterator_traits<_BI2>::value_type>)
638 __glibcxx_requires_valid_range(__first, __last);
640 return (std::__copy_move_backward_a2<__is_move_iterator<_BI1>::__value>
641 (std::__miter_base(__first), std::__miter_base(__last),
645 #if __cplusplus >= 201103L 664 template<
typename _BI1,
typename _BI2>
669 __glibcxx_function_requires(_BidirectionalIteratorConcept<_BI1>)
670 __glibcxx_function_requires(_Mutable_BidirectionalIteratorConcept<_BI2>)
671 __glibcxx_function_requires(_ConvertibleConcept<
672 typename iterator_traits<_BI1>::value_type,
673 typename iterator_traits<_BI2>::value_type>)
674 __glibcxx_requires_valid_range(__first, __last);
676 return std::__copy_move_backward_a2<true>(std::__miter_base(__first),
677 std::__miter_base(__last),
681 #define _GLIBCXX_MOVE_BACKWARD3(_Tp, _Up, _Vp) std::move_backward(_Tp, _Up, _Vp) 683 #define _GLIBCXX_MOVE_BACKWARD3(_Tp, _Up, _Vp) std::copy_backward(_Tp, _Up, _Vp) 686 template<
typename _ForwardIterator,
typename _Tp>
688 __gnu_cxx::__enable_if<!__is_scalar<_Tp>::__value,
void>::__type
689 __fill_a(_ForwardIterator __first, _ForwardIterator __last,
692 for (; __first != __last; ++__first)
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 const _Tp __tmp = __value;
703 for (; __first != __last; ++__first)
708 template<
typename _Tp>
710 __gnu_cxx::__enable_if<__is_byte<_Tp>::__value,
void>::__type
711 __fill_a(_Tp* __first, _Tp* __last,
const _Tp& __c)
713 const _Tp __tmp = __c;
714 if (
const size_t __len = __last - __first)
715 __builtin_memset(__first, static_cast<unsigned char>(__tmp), __len);
730 template<
typename _ForwardIterator,
typename _Tp>
732 fill(_ForwardIterator __first, _ForwardIterator __last,
const _Tp& __value)
735 __glibcxx_function_requires(_Mutable_ForwardIteratorConcept<
737 __glibcxx_requires_valid_range(__first, __last);
739 std::__fill_a(std::__niter_base(__first), std::__niter_base(__last),
743 template<
typename _OutputIterator,
typename _Size,
typename _Tp>
745 __gnu_cxx::__enable_if<!__is_scalar<_Tp>::__value, _OutputIterator>::__type
746 __fill_n_a(_OutputIterator __first, _Size __n,
const _Tp& __value)
748 for (__decltype(__n + 0) __niter = __n;
749 __niter > 0; --__niter, ++__first)
754 template<
typename _OutputIterator,
typename _Size,
typename _Tp>
756 __gnu_cxx::__enable_if<__is_scalar<_Tp>::__value, _OutputIterator>::__type
757 __fill_n_a(_OutputIterator __first, _Size __n,
const _Tp& __value)
759 const _Tp __tmp = __value;
760 for (__decltype(__n + 0) __niter = __n;
761 __niter > 0; --__niter, ++__first)
766 template<
typename _Size,
typename _Tp>
768 __gnu_cxx::__enable_if<__is_byte<_Tp>::__value, _Tp*>::__type
769 __fill_n_a(_Tp* __first, _Size __n,
const _Tp& __c)
771 std::__fill_a(__first, __first + __n, __c);
772 return __first + __n;
790 template<
typename _OI,
typename _Size,
typename _Tp>
792 fill_n(_OI __first, _Size __n,
const _Tp& __value)
795 __glibcxx_function_requires(_OutputIteratorConcept<_OI, _Tp>)
797 return _OI(std::__fill_n_a(std::__niter_base(__first), __n, __value));
800 template<
bool _BoolType>
803 template<
typename _II1,
typename _II2>
805 equal(_II1 __first1, _II1 __last1, _II2 __first2)
807 for (; __first1 != __last1; ++__first1, ++__first2)
808 if (!(*__first1 == *__first2))
817 template<
typename _Tp>
819 equal(
const _Tp* __first1,
const _Tp* __last1,
const _Tp* __first2)
821 if (
const size_t __len = (__last1 - __first1))
822 return !__builtin_memcmp(__first1, __first2,
sizeof(_Tp) * __len);
827 template<
typename _II1,
typename _II2>
829 __equal_aux(_II1 __first1, _II1 __last1, _II2 __first2)
831 typedef typename iterator_traits<_II1>::value_type _ValueType1;
832 typedef typename iterator_traits<_II2>::value_type _ValueType2;
833 const bool __simple = ((__is_integer<_ValueType1>::__value
834 || __is_pointer<_ValueType1>::__value)
835 && __is_pointer<_II1>::__value
836 && __is_pointer<_II2>::__value
837 && __are_same<_ValueType1, _ValueType2>::__value);
842 template<
typename,
typename>
845 template<
typename _II1,
typename _II2>
847 __newlast1(_II1, _II1 __last1, _II2, _II2)
850 template<
typename _II>
852 __cnd2(_II __first, _II __last)
853 {
return __first != __last; }
857 struct __lc_rai<random_access_iterator_tag, random_access_iterator_tag>
859 template<
typename _RAI1,
typename _RAI2>
861 __newlast1(_RAI1 __first1, _RAI1 __last1,
862 _RAI2 __first2, _RAI2 __last2)
864 const typename iterator_traits<_RAI1>::difference_type
865 __diff1 = __last1 - __first1;
866 const typename iterator_traits<_RAI2>::difference_type
867 __diff2 = __last2 - __first2;
868 return __diff2 < __diff1 ? __first1 + __diff2 : __last1;
871 template<
typename _RAI>
877 template<
typename _II1,
typename _II2,
typename _Compare>
879 __lexicographical_compare_impl(_II1 __first1, _II1 __last1,
880 _II2 __first2, _II2 __last2,
883 typedef typename iterator_traits<_II1>::iterator_category _Category1;
884 typedef typename iterator_traits<_II2>::iterator_category _Category2;
885 typedef std::__lc_rai<_Category1, _Category2> __rai_type;
887 __last1 = __rai_type::__newlast1(__first1, __last1, __first2, __last2);
888 for (; __first1 != __last1 && __rai_type::__cnd2(__first2, __last2);
889 ++__first1, ++__first2)
891 if (__comp(__first1, __first2))
893 if (__comp(__first2, __first1))
896 return __first1 == __last1 && __first2 != __last2;
899 template<
bool _BoolType>
900 struct __lexicographical_compare
902 template<
typename _II1,
typename _II2>
903 static bool __lc(_II1, _II1, _II2, _II2);
906 template<
bool _BoolType>
907 template<
typename _II1,
typename _II2>
909 __lexicographical_compare<_BoolType>::
910 __lc(_II1 __first1, _II1 __last1, _II2 __first2, _II2 __last2)
912 return std::__lexicographical_compare_impl(__first1, __last1,
914 __gnu_cxx::__ops::__iter_less_iter());
918 struct __lexicographical_compare<true>
920 template<
typename _Tp,
typename _Up>
922 __lc(
const _Tp* __first1,
const _Tp* __last1,
923 const _Up* __first2,
const _Up* __last2)
925 const size_t __len1 = __last1 - __first1;
926 const size_t __len2 = __last2 - __first2;
927 if (
const size_t __len =
std::min(__len1, __len2))
928 if (
int __result = __builtin_memcmp(__first1, __first2, __len))
930 return __len1 < __len2;
934 template<
typename _II1,
typename _II2>
936 __lexicographical_compare_aux(_II1 __first1, _II1 __last1,
937 _II2 __first2, _II2 __last2)
939 typedef typename iterator_traits<_II1>::value_type _ValueType1;
940 typedef typename iterator_traits<_II2>::value_type _ValueType2;
941 const bool __simple =
942 (__is_byte<_ValueType1>::__value && __is_byte<_ValueType2>::__value
943 && !__gnu_cxx::__numeric_traits<_ValueType1>::__is_signed
944 && !__gnu_cxx::__numeric_traits<_ValueType2>::__is_signed
945 && __is_pointer<_II1>::__value
946 && __is_pointer<_II2>::__value);
948 return std::__lexicographical_compare<__simple>::__lc(__first1, __last1,
952 template<
typename _ForwardIterator,
typename _Tp,
typename _Compare>
954 __lower_bound(_ForwardIterator __first, _ForwardIterator __last,
955 const _Tp& __val, _Compare __comp)
957 typedef typename iterator_traits<_ForwardIterator>::difference_type
964 _DistanceType __half = __len >> 1;
965 _ForwardIterator __middle = __first;
967 if (__comp(__middle, __val))
971 __len = __len - __half - 1;
990 template<
typename _ForwardIterator,
typename _Tp>
991 inline _ForwardIterator
992 lower_bound(_ForwardIterator __first, _ForwardIterator __last,
996 __glibcxx_function_requires(_ForwardIteratorConcept<_ForwardIterator>)
997 __glibcxx_function_requires(_LessThanOpConcept<
998 typename iterator_traits<_ForwardIterator>::value_type, _Tp>)
999 __glibcxx_requires_partitioned_lower(__first, __last, __val);
1001 return std::__lower_bound(__first, __last, __val,
1002 __gnu_cxx::__ops::__iter_less_val());
1007 inline _GLIBCXX_CONSTEXPR
int 1009 {
return sizeof(int) * __CHAR_BIT__ - 1 - __builtin_clz(__n); }
1011 inline _GLIBCXX_CONSTEXPR
unsigned 1013 {
return sizeof(int) * __CHAR_BIT__ - 1 - __builtin_clz(__n); }
1015 inline _GLIBCXX_CONSTEXPR
long 1017 {
return sizeof(long) * __CHAR_BIT__ - 1 - __builtin_clzl(__n); }
1019 inline _GLIBCXX_CONSTEXPR
unsigned long 1020 __lg(
unsigned long __n)
1021 {
return sizeof(long) * __CHAR_BIT__ - 1 - __builtin_clzl(__n); }
1023 inline _GLIBCXX_CONSTEXPR
long long 1025 {
return sizeof(
long long) * __CHAR_BIT__ - 1 - __builtin_clzll(__n); }
1027 inline _GLIBCXX_CONSTEXPR
unsigned long long 1028 __lg(
unsigned long long __n)
1029 {
return sizeof(
long long) * __CHAR_BIT__ - 1 - __builtin_clzll(__n); }
1031 _GLIBCXX_END_NAMESPACE_VERSION
1033 _GLIBCXX_BEGIN_NAMESPACE_ALGO
1047 template<
typename _II1,
typename _II2>
1049 equal(_II1 __first1, _II1 __last1, _II2 __first2)
1052 __glibcxx_function_requires(_InputIteratorConcept<_II1>)
1053 __glibcxx_function_requires(_InputIteratorConcept<_II2>)
1054 __glibcxx_function_requires(_EqualOpConcept<
1055 typename iterator_traits<_II1>::value_type,
1056 typename iterator_traits<_II2>::value_type>)
1057 __glibcxx_requires_valid_range(__first1, __last1);
1059 return std::__equal_aux(std::__niter_base(__first1),
1060 std::__niter_base(__last1),
1061 std::__niter_base(__first2));
1079 template<
typename _IIter1,
typename _IIter2,
typename _BinaryPredicate>
1081 equal(_IIter1 __first1, _IIter1 __last1,
1082 _IIter2 __first2, _BinaryPredicate __binary_pred)
1085 __glibcxx_function_requires(_InputIteratorConcept<_IIter1>)
1086 __glibcxx_function_requires(_InputIteratorConcept<_IIter2>)
1087 __glibcxx_requires_valid_range(__first1, __last1);
1089 for (; __first1 != __last1; ++__first1, ++__first2)
1090 if (!
bool(__binary_pred(*__first1, *__first2)))
1095 #if __cplusplus > 201103L 1097 #define __cpp_lib_robust_nonmodifying_seq_ops 201304 1112 template<
typename _II1,
typename _II2>
1114 equal(_II1 __first1, _II1 __last1, _II2 __first2, _II2 __last2)
1117 __glibcxx_function_requires(_InputIteratorConcept<_II1>)
1118 __glibcxx_function_requires(_InputIteratorConcept<_II2>)
1119 __glibcxx_function_requires(_EqualOpConcept<
1120 typename iterator_traits<_II1>::value_type,
1121 typename iterator_traits<_II2>::value_type>)
1122 __glibcxx_requires_valid_range(__first1, __last1);
1123 __glibcxx_requires_valid_range(__first2, __last2);
1125 using _RATag = random_access_iterator_tag;
1126 using _Cat1 =
typename iterator_traits<_II1>::iterator_category;
1127 using _Cat2 =
typename iterator_traits<_II2>::iterator_category;
1128 using _RAIters = __and_<is_same<_Cat1, _RATag>, is_same<_Cat2, _RATag>>;
1138 for (; __first1 != __last1 && __first2 != __last2; ++__first1, ++__first2)
1139 if (!(*__first1 == *__first2))
1141 return __first1 == __last1 && __first2 == __last2;
1160 template<
typename _IIter1,
typename _IIter2,
typename _BinaryPredicate>
1162 equal(_IIter1 __first1, _IIter1 __last1,
1163 _IIter2 __first2, _IIter2 __last2, _BinaryPredicate __binary_pred)
1166 __glibcxx_function_requires(_InputIteratorConcept<_IIter1>)
1167 __glibcxx_function_requires(_InputIteratorConcept<_IIter2>)
1168 __glibcxx_requires_valid_range(__first1, __last1);
1169 __glibcxx_requires_valid_range(__first2, __last2);
1171 using _RATag = random_access_iterator_tag;
1172 using _Cat1 =
typename iterator_traits<_IIter1>::iterator_category;
1173 using _Cat2 =
typename iterator_traits<_IIter2>::iterator_category;
1174 using _RAIters = __and_<is_same<_Cat1, _RATag>, is_same<_Cat2, _RATag>>;
1185 for (; __first1 != __last1 && __first2 != __last2; ++__first1, ++__first2)
1186 if (!
bool(__binary_pred(*__first1, *__first2)))
1188 return __first1 == __last1 && __first2 == __last2;
1207 template<
typename _II1,
typename _II2>
1209 lexicographical_compare(_II1 __first1, _II1 __last1,
1210 _II2 __first2, _II2 __last2)
1212 #ifdef _GLIBCXX_CONCEPT_CHECKS 1214 typedef typename iterator_traits<_II1>::value_type _ValueType1;
1215 typedef typename iterator_traits<_II2>::value_type _ValueType2;
1217 __glibcxx_function_requires(_InputIteratorConcept<_II1>)
1218 __glibcxx_function_requires(_InputIteratorConcept<_II2>)
1219 __glibcxx_function_requires(_LessThanOpConcept<_ValueType1, _ValueType2>)
1220 __glibcxx_function_requires(_LessThanOpConcept<_ValueType2, _ValueType1>)
1221 __glibcxx_requires_valid_range(__first1, __last1);
1222 __glibcxx_requires_valid_range(__first2, __last2);
1224 return std::__lexicographical_compare_aux(std::__niter_base(__first1),
1225 std::__niter_base(__last1),
1226 std::__niter_base(__first2),
1227 std::__niter_base(__last2));
1243 template<
typename _II1,
typename _II2,
typename _Compare>
1245 lexicographical_compare(_II1 __first1, _II1 __last1,
1246 _II2 __first2, _II2 __last2, _Compare __comp)
1249 __glibcxx_function_requires(_InputIteratorConcept<_II1>)
1250 __glibcxx_function_requires(_InputIteratorConcept<_II2>)
1251 __glibcxx_requires_valid_range(__first1, __last1);
1252 __glibcxx_requires_valid_range(__first2, __last2);
1254 return std::__lexicographical_compare_impl
1255 (__first1, __last1, __first2, __last2,
1256 __gnu_cxx::__ops::__iter_comp_iter(__comp));
1259 template<
typename _InputIterator1,
typename _InputIterator2,
1260 typename _BinaryPredicate>
1262 __mismatch(_InputIterator1 __first1, _InputIterator1 __last1,
1263 _InputIterator2 __first2, _BinaryPredicate __binary_pred)
1265 while (__first1 != __last1 && __binary_pred(__first1, __first2))
1286 template<
typename _InputIterator1,
typename _InputIterator2>
1288 mismatch(_InputIterator1 __first1, _InputIterator1 __last1,
1289 _InputIterator2 __first2)
1292 __glibcxx_function_requires(_InputIteratorConcept<_InputIterator1>)
1293 __glibcxx_function_requires(_InputIteratorConcept<_InputIterator2>)
1294 __glibcxx_function_requires(_EqualOpConcept<
1295 typename iterator_traits<_InputIterator1>::value_type,
1296 typename iterator_traits<_InputIterator2>::value_type>)
1297 __glibcxx_requires_valid_range(__first1, __last1);
1299 return _GLIBCXX_STD_A::__mismatch(__first1, __last1, __first2,
1300 __gnu_cxx::__ops::__iter_equal_to_iter());
1319 template<
typename _InputIterator1,
typename _InputIterator2,
1320 typename _BinaryPredicate>
1322 mismatch(_InputIterator1 __first1, _InputIterator1 __last1,
1323 _InputIterator2 __first2, _BinaryPredicate __binary_pred)
1326 __glibcxx_function_requires(_InputIteratorConcept<_InputIterator1>)
1327 __glibcxx_function_requires(_InputIteratorConcept<_InputIterator2>)
1328 __glibcxx_requires_valid_range(__first1, __last1);
1330 return _GLIBCXX_STD_A::__mismatch(__first1, __last1, __first2,
1331 __gnu_cxx::__ops::__iter_comp_iter(__binary_pred));
1334 #if __cplusplus > 201103L 1336 template<
typename _InputIterator1,
typename _InputIterator2,
1337 typename _BinaryPredicate>
1339 __mismatch(_InputIterator1 __first1, _InputIterator1 __last1,
1340 _InputIterator2 __first2, _InputIterator2 __last2,
1341 _BinaryPredicate __binary_pred)
1343 while (__first1 != __last1 && __first2 != __last2
1344 && __binary_pred(__first1, __first2))
1366 template<
typename _InputIterator1,
typename _InputIterator2>
1368 mismatch(_InputIterator1 __first1, _InputIterator1 __last1,
1369 _InputIterator2 __first2, _InputIterator2 __last2)
1372 __glibcxx_function_requires(_InputIteratorConcept<_InputIterator1>)
1373 __glibcxx_function_requires(_InputIteratorConcept<_InputIterator2>)
1374 __glibcxx_function_requires(_EqualOpConcept<
1375 typename iterator_traits<_InputIterator1>::value_type,
1376 typename iterator_traits<_InputIterator2>::value_type>)
1377 __glibcxx_requires_valid_range(__first1, __last1);
1378 __glibcxx_requires_valid_range(__first2, __last2);
1380 return _GLIBCXX_STD_A::__mismatch(__first1, __last1, __first2, __last2,
1381 __gnu_cxx::__ops::__iter_equal_to_iter());
1401 template<
typename _InputIterator1,
typename _InputIterator2,
1402 typename _BinaryPredicate>
1404 mismatch(_InputIterator1 __first1, _InputIterator1 __last1,
1405 _InputIterator2 __first2, _InputIterator2 __last2,
1406 _BinaryPredicate __binary_pred)
1409 __glibcxx_function_requires(_InputIteratorConcept<_InputIterator1>)
1410 __glibcxx_function_requires(_InputIteratorConcept<_InputIterator2>)
1411 __glibcxx_requires_valid_range(__first1, __last1);
1412 __glibcxx_requires_valid_range(__first2, __last2);
1414 return _GLIBCXX_STD_A::__mismatch(__first1, __last1, __first2, __last2,
1415 __gnu_cxx::__ops::__iter_comp_iter(__binary_pred));
1419 _GLIBCXX_END_NAMESPACE_ALGO
1425 #ifdef _GLIBCXX_PARALLEL
const _Tp & max(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.
bool equal(_II1 __first1, _II1 __last1, _II2 __first2)
Tests a range for element-wise equality.
void iter_swap(_ForwardIterator1 __a, _ForwardIterator2 __b)
Swaps the contents of two iterators.
void swap(_Tp &, _Tp &) noexcept(__and_< is_nothrow_move_constructible< _Tp >, is_nothrow_move_assignable< _Tp >>::value)
Swaps two values.
Parallel STL function calls corresponding to the stl_algobase.h header. The functions defined here ma...
ISO C++ entities toplevel namespace is std.
Provides input iterator semantics for streambufs.
iterator_traits< _InputIterator >::difference_type distance(_InputIterator __first, _InputIterator __last)
A generalization of pointer arithmetic.
_BI2 move_backward(_BI1 __first, _BI1 __last, _BI2 __result)
Moves the range [first,last) into result.
void advance(_InputIterator &__i, _Distance __n)
A generalization of pointer arithmetic.
Basis for explicit traits specializations.
constexpr std::remove_reference< _Tp >::type && move(_Tp &&__t) noexcept
Convert a value to an rvalue.
const _Tp & min(const _Tp &, const _Tp &)
This does what you think it does.
Struct holding two objects of arbitrary type.
constexpr int __lg(int __n)
This is a helper function for the sort routines and for random.tcc.