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)
324 *__result = std::move(*__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)
359 *__result = std::move(*__first);
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 376 using __assignable = conditional<_IsMove,
377 is_move_assignable<_Tp>,
378 is_copy_assignable<_Tp>>;
380 static_assert( __assignable::type::value,
"type is not assignable" );
382 const ptrdiff_t _Num = __last - __first;
384 __builtin_memmove(__result, __first,
sizeof(_Tp) * _Num);
385 return __result + _Num;
389 template<
bool _IsMove,
typename _II,
typename _OI>
391 __copy_move_a(_II __first, _II __last, _OI __result)
393 typedef typename iterator_traits<_II>::value_type _ValueTypeI;
394 typedef typename iterator_traits<_OI>::value_type _ValueTypeO;
395 typedef typename iterator_traits<_II>::iterator_category _Category;
396 const bool __simple = (__is_trivial(_ValueTypeI)
397 && __is_pointer<_II>::__value
398 && __is_pointer<_OI>::__value
399 && __are_same<_ValueTypeI, _ValueTypeO>::__value);
401 return std::__copy_move<_IsMove, __simple,
402 _Category>::__copy_m(__first, __last, __result);
407 template<
typename _CharT>
410 template<
typename _CharT,
typename _Traits>
413 template<
typename _CharT,
typename _Traits>
416 template<
bool _IsMove,
typename _CharT>
417 typename __gnu_cxx::__enable_if<__is_char<_CharT>::__value,
419 __copy_move_a2(_CharT*, _CharT*,
422 template<
bool _IsMove,
typename _CharT>
423 typename __gnu_cxx::__enable_if<__is_char<_CharT>::__value,
425 __copy_move_a2(
const _CharT*,
const _CharT*,
428 template<
bool _IsMove,
typename _CharT>
429 typename __gnu_cxx::__enable_if<__is_char<_CharT>::__value,
434 template<
bool _IsMove,
typename _II,
typename _OI>
436 __copy_move_a2(_II __first, _II __last, _OI __result)
438 return _OI(std::__copy_move_a<_IsMove>(std::__niter_base(__first),
439 std::__niter_base(__last),
440 std::__niter_base(__result)));
460 template<
typename _II,
typename _OI>
462 copy(_II __first, _II __last, _OI __result)
465 __glibcxx_function_requires(_InputIteratorConcept<_II>)
466 __glibcxx_function_requires(_OutputIteratorConcept<_OI,
467 typename iterator_traits<_II>::value_type>)
468 __glibcxx_requires_valid_range(__first, __last);
470 return (std::__copy_move_a2<__is_move_iterator<_II>::__value>
471 (std::__miter_base(__first), std::__miter_base(__last),
475 #if __cplusplus >= 201103L 493 template<
typename _II,
typename _OI>
495 move(_II __first, _II __last, _OI __result)
498 __glibcxx_function_requires(_InputIteratorConcept<_II>)
499 __glibcxx_function_requires(_OutputIteratorConcept<_OI,
500 typename iterator_traits<_II>::value_type>)
501 __glibcxx_requires_valid_range(__first, __last);
503 return std::__copy_move_a2<true>(std::__miter_base(__first),
504 std::__miter_base(__last), __result);
507 #define _GLIBCXX_MOVE3(_Tp, _Up, _Vp) std::move(_Tp, _Up, _Vp) 509 #define _GLIBCXX_MOVE3(_Tp, _Up, _Vp) std::copy(_Tp, _Up, _Vp) 512 template<
bool,
bool,
typename>
513 struct __copy_move_backward
515 template<
typename _BI1,
typename _BI2>
517 __copy_move_b(_BI1 __first, _BI1 __last, _BI2 __result)
519 while (__first != __last)
520 *--__result = *--__last;
525 #if __cplusplus >= 201103L 526 template<
typename _Category>
527 struct __copy_move_backward<true, false, _Category>
529 template<
typename _BI1,
typename _BI2>
531 __copy_move_b(_BI1 __first, _BI1 __last, _BI2 __result)
533 while (__first != __last)
534 *--__result = std::move(*--__last);
541 struct __copy_move_backward<false, false, random_access_iterator_tag>
543 template<
typename _BI1,
typename _BI2>
545 __copy_move_b(_BI1 __first, _BI1 __last, _BI2 __result)
547 typename iterator_traits<_BI1>::difference_type __n;
548 for (__n = __last - __first; __n > 0; --__n)
549 *--__result = *--__last;
554 #if __cplusplus >= 201103L 556 struct __copy_move_backward<true, false, random_access_iterator_tag>
558 template<
typename _BI1,
typename _BI2>
560 __copy_move_b(_BI1 __first, _BI1 __last, _BI2 __result)
562 typename iterator_traits<_BI1>::difference_type __n;
563 for (__n = __last - __first; __n > 0; --__n)
564 *--__result = std::move(*--__last);
570 template<
bool _IsMove>
571 struct __copy_move_backward<_IsMove, true, random_access_iterator_tag>
573 template<
typename _Tp>
575 __copy_move_b(
const _Tp* __first,
const _Tp* __last, _Tp* __result)
577 #if __cplusplus >= 201103L 578 using __assignable = conditional<_IsMove,
579 is_move_assignable<_Tp>,
580 is_copy_assignable<_Tp>>;
582 static_assert( __assignable::type::value,
"type is not assignable" );
584 const ptrdiff_t _Num = __last - __first;
586 __builtin_memmove(__result - _Num, __first,
sizeof(_Tp) * _Num);
587 return __result - _Num;
591 template<
bool _IsMove,
typename _BI1,
typename _BI2>
593 __copy_move_backward_a(_BI1 __first, _BI1 __last, _BI2 __result)
595 typedef typename iterator_traits<_BI1>::value_type _ValueType1;
596 typedef typename iterator_traits<_BI2>::value_type _ValueType2;
597 typedef typename iterator_traits<_BI1>::iterator_category _Category;
598 const bool __simple = (__is_trivial(_ValueType1)
599 && __is_pointer<_BI1>::__value
600 && __is_pointer<_BI2>::__value
601 && __are_same<_ValueType1, _ValueType2>::__value);
603 return std::__copy_move_backward<_IsMove, __simple,
604 _Category>::__copy_move_b(__first,
609 template<
bool _IsMove,
typename _BI1,
typename _BI2>
611 __copy_move_backward_a2(_BI1 __first, _BI1 __last, _BI2 __result)
613 return _BI2(std::__copy_move_backward_a<_IsMove>
614 (std::__niter_base(__first), std::__niter_base(__last),
615 std::__niter_base(__result)));
636 template<
typename _BI1,
typename _BI2>
638 copy_backward(_BI1 __first, _BI1 __last, _BI2 __result)
641 __glibcxx_function_requires(_BidirectionalIteratorConcept<_BI1>)
642 __glibcxx_function_requires(_Mutable_BidirectionalIteratorConcept<_BI2>)
643 __glibcxx_function_requires(_ConvertibleConcept<
644 typename iterator_traits<_BI1>::value_type,
645 typename iterator_traits<_BI2>::value_type>)
646 __glibcxx_requires_valid_range(__first, __last);
648 return (std::__copy_move_backward_a2<__is_move_iterator<_BI1>::__value>
649 (std::__miter_base(__first), std::__miter_base(__last),
653 #if __cplusplus >= 201103L 672 template<
typename _BI1,
typename _BI2>
674 move_backward(_BI1 __first, _BI1 __last, _BI2 __result)
677 __glibcxx_function_requires(_BidirectionalIteratorConcept<_BI1>)
678 __glibcxx_function_requires(_Mutable_BidirectionalIteratorConcept<_BI2>)
679 __glibcxx_function_requires(_ConvertibleConcept<
680 typename iterator_traits<_BI1>::value_type,
681 typename iterator_traits<_BI2>::value_type>)
682 __glibcxx_requires_valid_range(__first, __last);
684 return std::__copy_move_backward_a2<true>(std::__miter_base(__first),
685 std::__miter_base(__last),
689 #define _GLIBCXX_MOVE_BACKWARD3(_Tp, _Up, _Vp) std::move_backward(_Tp, _Up, _Vp) 691 #define _GLIBCXX_MOVE_BACKWARD3(_Tp, _Up, _Vp) std::copy_backward(_Tp, _Up, _Vp) 694 template<
typename _ForwardIterator,
typename _Tp>
696 __gnu_cxx::__enable_if<!__is_scalar<_Tp>::__value,
void>::__type
697 __fill_a(_ForwardIterator __first, _ForwardIterator __last,
700 for (; __first != __last; ++__first)
704 template<
typename _ForwardIterator,
typename _Tp>
706 __gnu_cxx::__enable_if<__is_scalar<_Tp>::__value,
void>::__type
707 __fill_a(_ForwardIterator __first, _ForwardIterator __last,
710 const _Tp __tmp = __value;
711 for (; __first != __last; ++__first)
716 template<
typename _Tp>
718 __gnu_cxx::__enable_if<__is_byte<_Tp>::__value,
void>::__type
719 __fill_a(_Tp* __first, _Tp* __last,
const _Tp& __c)
721 const _Tp __tmp = __c;
722 if (
const size_t __len = __last - __first)
723 __builtin_memset(__first, static_cast<unsigned char>(__tmp), __len);
738 template<
typename _ForwardIterator,
typename _Tp>
740 fill(_ForwardIterator __first, _ForwardIterator __last,
const _Tp& __value)
743 __glibcxx_function_requires(_Mutable_ForwardIteratorConcept<
745 __glibcxx_requires_valid_range(__first, __last);
747 std::__fill_a(std::__niter_base(__first), std::__niter_base(__last),
751 template<
typename _OutputIterator,
typename _Size,
typename _Tp>
753 __gnu_cxx::__enable_if<!__is_scalar<_Tp>::__value, _OutputIterator>::__type
754 __fill_n_a(_OutputIterator __first, _Size __n,
const _Tp& __value)
756 for (__decltype(__n + 0) __niter = __n;
757 __niter > 0; --__niter, ++__first)
762 template<
typename _OutputIterator,
typename _Size,
typename _Tp>
764 __gnu_cxx::__enable_if<__is_scalar<_Tp>::__value, _OutputIterator>::__type
765 __fill_n_a(_OutputIterator __first, _Size __n,
const _Tp& __value)
767 const _Tp __tmp = __value;
768 for (__decltype(__n + 0) __niter = __n;
769 __niter > 0; --__niter, ++__first)
774 template<
typename _Size,
typename _Tp>
776 __gnu_cxx::__enable_if<__is_byte<_Tp>::__value, _Tp*>::__type
777 __fill_n_a(_Tp* __first, _Size __n,
const _Tp& __c)
779 std::__fill_a(__first, __first + __n, __c);
780 return __first + __n;
798 template<
typename _OI,
typename _Size,
typename _Tp>
800 fill_n(_OI __first, _Size __n,
const _Tp& __value)
803 __glibcxx_function_requires(_OutputIteratorConcept<_OI, _Tp>)
805 return _OI(std::__fill_n_a(std::__niter_base(__first), __n, __value));
808 template<
bool _BoolType>
811 template<
typename _II1,
typename _II2>
813 equal(_II1 __first1, _II1 __last1, _II2 __first2)
815 for (; __first1 != __last1; ++__first1, ++__first2)
816 if (!(*__first1 == *__first2))
825 template<
typename _Tp>
827 equal(
const _Tp* __first1,
const _Tp* __last1,
const _Tp* __first2)
829 if (
const size_t __len = (__last1 - __first1))
830 return !__builtin_memcmp(__first1, __first2,
sizeof(_Tp) * __len);
835 template<
typename _II1,
typename _II2>
837 __equal_aux(_II1 __first1, _II1 __last1, _II2 __first2)
839 typedef typename iterator_traits<_II1>::value_type _ValueType1;
840 typedef typename iterator_traits<_II2>::value_type _ValueType2;
841 const bool __simple = ((__is_integer<_ValueType1>::__value
842 || __is_pointer<_ValueType1>::__value)
843 && __is_pointer<_II1>::__value
844 && __is_pointer<_II2>::__value
845 && __are_same<_ValueType1, _ValueType2>::__value);
850 template<
typename,
typename>
853 template<
typename _II1,
typename _II2>
855 __newlast1(_II1, _II1 __last1, _II2, _II2)
858 template<
typename _II>
860 __cnd2(_II __first, _II __last)
861 {
return __first != __last; }
865 struct __lc_rai<random_access_iterator_tag, random_access_iterator_tag>
867 template<
typename _RAI1,
typename _RAI2>
869 __newlast1(_RAI1 __first1, _RAI1 __last1,
870 _RAI2 __first2, _RAI2 __last2)
872 const typename iterator_traits<_RAI1>::difference_type
873 __diff1 = __last1 - __first1;
874 const typename iterator_traits<_RAI2>::difference_type
875 __diff2 = __last2 - __first2;
876 return __diff2 < __diff1 ? __first1 + __diff2 : __last1;
879 template<
typename _RAI>
885 template<
typename _II1,
typename _II2,
typename _Compare>
887 __lexicographical_compare_impl(_II1 __first1, _II1 __last1,
888 _II2 __first2, _II2 __last2,
891 typedef typename iterator_traits<_II1>::iterator_category _Category1;
892 typedef typename iterator_traits<_II2>::iterator_category _Category2;
893 typedef std::__lc_rai<_Category1, _Category2> __rai_type;
895 __last1 = __rai_type::__newlast1(__first1, __last1, __first2, __last2);
896 for (; __first1 != __last1 && __rai_type::__cnd2(__first2, __last2);
897 ++__first1, ++__first2)
899 if (__comp(__first1, __first2))
901 if (__comp(__first2, __first1))
904 return __first1 == __last1 && __first2 != __last2;
907 template<
bool _BoolType>
908 struct __lexicographical_compare
910 template<
typename _II1,
typename _II2>
911 static bool __lc(_II1, _II1, _II2, _II2);
914 template<
bool _BoolType>
915 template<
typename _II1,
typename _II2>
917 __lexicographical_compare<_BoolType>::
918 __lc(_II1 __first1, _II1 __last1, _II2 __first2, _II2 __last2)
920 return std::__lexicographical_compare_impl(__first1, __last1,
922 __gnu_cxx::__ops::__iter_less_iter());
926 struct __lexicographical_compare<true>
928 template<
typename _Tp,
typename _Up>
930 __lc(
const _Tp* __first1,
const _Tp* __last1,
931 const _Up* __first2,
const _Up* __last2)
933 const size_t __len1 = __last1 - __first1;
934 const size_t __len2 = __last2 - __first2;
935 if (
const size_t __len =
std::min(__len1, __len2))
936 if (
int __result = __builtin_memcmp(__first1, __first2, __len))
938 return __len1 < __len2;
942 template<
typename _II1,
typename _II2>
944 __lexicographical_compare_aux(_II1 __first1, _II1 __last1,
945 _II2 __first2, _II2 __last2)
947 typedef typename iterator_traits<_II1>::value_type _ValueType1;
948 typedef typename iterator_traits<_II2>::value_type _ValueType2;
949 const bool __simple =
950 (__is_byte<_ValueType1>::__value && __is_byte<_ValueType2>::__value
951 && !__gnu_cxx::__numeric_traits<_ValueType1>::__is_signed
952 && !__gnu_cxx::__numeric_traits<_ValueType2>::__is_signed
953 && __is_pointer<_II1>::__value
954 && __is_pointer<_II2>::__value);
956 return std::__lexicographical_compare<__simple>::__lc(__first1, __last1,
960 template<
typename _ForwardIterator,
typename _Tp,
typename _Compare>
962 __lower_bound(_ForwardIterator __first, _ForwardIterator __last,
963 const _Tp& __val, _Compare __comp)
965 typedef typename iterator_traits<_ForwardIterator>::difference_type
972 _DistanceType __half = __len >> 1;
973 _ForwardIterator __middle = __first;
975 if (__comp(__middle, __val))
979 __len = __len - __half - 1;
998 template<
typename _ForwardIterator,
typename _Tp>
999 inline _ForwardIterator
1000 lower_bound(_ForwardIterator __first, _ForwardIterator __last,
1004 __glibcxx_function_requires(_ForwardIteratorConcept<_ForwardIterator>)
1005 __glibcxx_function_requires(_LessThanOpConcept<
1006 typename iterator_traits<_ForwardIterator>::value_type, _Tp>)
1007 __glibcxx_requires_partitioned_lower(__first, __last, __val);
1009 return std::__lower_bound(__first, __last, __val,
1010 __gnu_cxx::__ops::__iter_less_val());
1015 inline _GLIBCXX_CONSTEXPR
int 1017 {
return sizeof(int) * __CHAR_BIT__ - 1 - __builtin_clz(__n); }
1019 inline _GLIBCXX_CONSTEXPR
unsigned 1021 {
return sizeof(int) * __CHAR_BIT__ - 1 - __builtin_clz(__n); }
1023 inline _GLIBCXX_CONSTEXPR
long 1025 {
return sizeof(long) * __CHAR_BIT__ - 1 - __builtin_clzl(__n); }
1027 inline _GLIBCXX_CONSTEXPR
unsigned long 1028 __lg(
unsigned long __n)
1029 {
return sizeof(long) * __CHAR_BIT__ - 1 - __builtin_clzl(__n); }
1031 inline _GLIBCXX_CONSTEXPR
long long 1033 {
return sizeof(
long long) * __CHAR_BIT__ - 1 - __builtin_clzll(__n); }
1035 inline _GLIBCXX_CONSTEXPR
unsigned long long 1036 __lg(
unsigned long long __n)
1037 {
return sizeof(
long long) * __CHAR_BIT__ - 1 - __builtin_clzll(__n); }
1039 _GLIBCXX_END_NAMESPACE_VERSION
1041 _GLIBCXX_BEGIN_NAMESPACE_ALGO
1055 template<
typename _II1,
typename _II2>
1057 equal(_II1 __first1, _II1 __last1, _II2 __first2)
1060 __glibcxx_function_requires(_InputIteratorConcept<_II1>)
1061 __glibcxx_function_requires(_InputIteratorConcept<_II2>)
1062 __glibcxx_function_requires(_EqualOpConcept<
1063 typename iterator_traits<_II1>::value_type,
1064 typename iterator_traits<_II2>::value_type>)
1065 __glibcxx_requires_valid_range(__first1, __last1);
1067 return std::__equal_aux(std::__niter_base(__first1),
1068 std::__niter_base(__last1),
1069 std::__niter_base(__first2));
1087 template<
typename _IIter1,
typename _IIter2,
typename _BinaryPredicate>
1089 equal(_IIter1 __first1, _IIter1 __last1,
1090 _IIter2 __first2, _BinaryPredicate __binary_pred)
1093 __glibcxx_function_requires(_InputIteratorConcept<_IIter1>)
1094 __glibcxx_function_requires(_InputIteratorConcept<_IIter2>)
1095 __glibcxx_requires_valid_range(__first1, __last1);
1097 for (; __first1 != __last1; ++__first1, ++__first2)
1098 if (!
bool(__binary_pred(*__first1, *__first2)))
1103 #if __cplusplus > 201103L 1105 #define __cpp_lib_robust_nonmodifying_seq_ops 201304 1120 template<
typename _II1,
typename _II2>
1122 equal(_II1 __first1, _II1 __last1, _II2 __first2, _II2 __last2)
1125 __glibcxx_function_requires(_InputIteratorConcept<_II1>)
1126 __glibcxx_function_requires(_InputIteratorConcept<_II2>)
1127 __glibcxx_function_requires(_EqualOpConcept<
1128 typename iterator_traits<_II1>::value_type,
1129 typename iterator_traits<_II2>::value_type>)
1130 __glibcxx_requires_valid_range(__first1, __last1);
1131 __glibcxx_requires_valid_range(__first2, __last2);
1133 using _RATag = random_access_iterator_tag;
1134 using _Cat1 =
typename iterator_traits<_II1>::iterator_category;
1135 using _Cat2 =
typename iterator_traits<_II2>::iterator_category;
1136 using _RAIters = __and_<is_same<_Cat1, _RATag>, is_same<_Cat2, _RATag>>;
1146 for (; __first1 != __last1 && __first2 != __last2; ++__first1, ++__first2)
1147 if (!(*__first1 == *__first2))
1149 return __first1 == __last1 && __first2 == __last2;
1168 template<
typename _IIter1,
typename _IIter2,
typename _BinaryPredicate>
1170 equal(_IIter1 __first1, _IIter1 __last1,
1171 _IIter2 __first2, _IIter2 __last2, _BinaryPredicate __binary_pred)
1174 __glibcxx_function_requires(_InputIteratorConcept<_IIter1>)
1175 __glibcxx_function_requires(_InputIteratorConcept<_IIter2>)
1176 __glibcxx_requires_valid_range(__first1, __last1);
1177 __glibcxx_requires_valid_range(__first2, __last2);
1179 using _RATag = random_access_iterator_tag;
1180 using _Cat1 =
typename iterator_traits<_IIter1>::iterator_category;
1181 using _Cat2 =
typename iterator_traits<_IIter2>::iterator_category;
1182 using _RAIters = __and_<is_same<_Cat1, _RATag>, is_same<_Cat2, _RATag>>;
1193 for (; __first1 != __last1 && __first2 != __last2; ++__first1, ++__first2)
1194 if (!
bool(__binary_pred(*__first1, *__first2)))
1196 return __first1 == __last1 && __first2 == __last2;
1215 template<
typename _II1,
typename _II2>
1217 lexicographical_compare(_II1 __first1, _II1 __last1,
1218 _II2 __first2, _II2 __last2)
1220 #ifdef _GLIBCXX_CONCEPT_CHECKS 1222 typedef typename iterator_traits<_II1>::value_type _ValueType1;
1223 typedef typename iterator_traits<_II2>::value_type _ValueType2;
1225 __glibcxx_function_requires(_InputIteratorConcept<_II1>)
1226 __glibcxx_function_requires(_InputIteratorConcept<_II2>)
1227 __glibcxx_function_requires(_LessThanOpConcept<_ValueType1, _ValueType2>)
1228 __glibcxx_function_requires(_LessThanOpConcept<_ValueType2, _ValueType1>)
1229 __glibcxx_requires_valid_range(__first1, __last1);
1230 __glibcxx_requires_valid_range(__first2, __last2);
1232 return std::__lexicographical_compare_aux(std::__niter_base(__first1),
1233 std::__niter_base(__last1),
1234 std::__niter_base(__first2),
1235 std::__niter_base(__last2));
1251 template<
typename _II1,
typename _II2,
typename _Compare>
1253 lexicographical_compare(_II1 __first1, _II1 __last1,
1254 _II2 __first2, _II2 __last2, _Compare __comp)
1257 __glibcxx_function_requires(_InputIteratorConcept<_II1>)
1258 __glibcxx_function_requires(_InputIteratorConcept<_II2>)
1259 __glibcxx_requires_valid_range(__first1, __last1);
1260 __glibcxx_requires_valid_range(__first2, __last2);
1262 return std::__lexicographical_compare_impl
1263 (__first1, __last1, __first2, __last2,
1264 __gnu_cxx::__ops::__iter_comp_iter(__comp));
1267 template<
typename _InputIterator1,
typename _InputIterator2,
1268 typename _BinaryPredicate>
1270 __mismatch(_InputIterator1 __first1, _InputIterator1 __last1,
1271 _InputIterator2 __first2, _BinaryPredicate __binary_pred)
1273 while (__first1 != __last1 && __binary_pred(__first1, __first2))
1294 template<
typename _InputIterator1,
typename _InputIterator2>
1296 mismatch(_InputIterator1 __first1, _InputIterator1 __last1,
1297 _InputIterator2 __first2)
1300 __glibcxx_function_requires(_InputIteratorConcept<_InputIterator1>)
1301 __glibcxx_function_requires(_InputIteratorConcept<_InputIterator2>)
1302 __glibcxx_function_requires(_EqualOpConcept<
1303 typename iterator_traits<_InputIterator1>::value_type,
1304 typename iterator_traits<_InputIterator2>::value_type>)
1305 __glibcxx_requires_valid_range(__first1, __last1);
1307 return _GLIBCXX_STD_A::__mismatch(__first1, __last1, __first2,
1308 __gnu_cxx::__ops::__iter_equal_to_iter());
1327 template<
typename _InputIterator1,
typename _InputIterator2,
1328 typename _BinaryPredicate>
1330 mismatch(_InputIterator1 __first1, _InputIterator1 __last1,
1331 _InputIterator2 __first2, _BinaryPredicate __binary_pred)
1334 __glibcxx_function_requires(_InputIteratorConcept<_InputIterator1>)
1335 __glibcxx_function_requires(_InputIteratorConcept<_InputIterator2>)
1336 __glibcxx_requires_valid_range(__first1, __last1);
1338 return _GLIBCXX_STD_A::__mismatch(__first1, __last1, __first2,
1339 __gnu_cxx::__ops::__iter_comp_iter(__binary_pred));
1342 #if __cplusplus > 201103L 1344 template<
typename _InputIterator1,
typename _InputIterator2,
1345 typename _BinaryPredicate>
1347 __mismatch(_InputIterator1 __first1, _InputIterator1 __last1,
1348 _InputIterator2 __first2, _InputIterator2 __last2,
1349 _BinaryPredicate __binary_pred)
1351 while (__first1 != __last1 && __first2 != __last2
1352 && __binary_pred(__first1, __first2))
1374 template<
typename _InputIterator1,
typename _InputIterator2>
1376 mismatch(_InputIterator1 __first1, _InputIterator1 __last1,
1377 _InputIterator2 __first2, _InputIterator2 __last2)
1380 __glibcxx_function_requires(_InputIteratorConcept<_InputIterator1>)
1381 __glibcxx_function_requires(_InputIteratorConcept<_InputIterator2>)
1382 __glibcxx_function_requires(_EqualOpConcept<
1383 typename iterator_traits<_InputIterator1>::value_type,
1384 typename iterator_traits<_InputIterator2>::value_type>)
1385 __glibcxx_requires_valid_range(__first1, __last1);
1386 __glibcxx_requires_valid_range(__first2, __last2);
1388 return _GLIBCXX_STD_A::__mismatch(__first1, __last1, __first2, __last2,
1389 __gnu_cxx::__ops::__iter_equal_to_iter());
1409 template<
typename _InputIterator1,
typename _InputIterator2,
1410 typename _BinaryPredicate>
1412 mismatch(_InputIterator1 __first1, _InputIterator1 __last1,
1413 _InputIterator2 __first2, _InputIterator2 __last2,
1414 _BinaryPredicate __binary_pred)
1417 __glibcxx_function_requires(_InputIteratorConcept<_InputIterator1>)
1418 __glibcxx_function_requires(_InputIteratorConcept<_InputIterator2>)
1419 __glibcxx_requires_valid_range(__first1, __last1);
1420 __glibcxx_requires_valid_range(__first2, __last2);
1422 return _GLIBCXX_STD_A::__mismatch(__first1, __last1, __first2, __last2,
1423 __gnu_cxx::__ops::__iter_comp_iter(__binary_pred));
1427 _GLIBCXX_END_NAMESPACE_ALGO
1433 #ifdef _GLIBCXX_PARALLEL void advance(_InputIterator &__i, _Distance __n)
A generalization of pointer arithmetic.
Basis for explicit traits specializations.
Provides input iterator semantics for streambufs.
Provides output iterator semantics for streambufs.
void iter_swap(_ForwardIterator1 __a, _ForwardIterator2 __b)
Swaps the contents of two iterators.
iterator_traits< _InputIterator >::difference_type distance(_InputIterator __first, _InputIterator __last)
A generalization of pointer arithmetic.
_OI move(_II __first, _II __last, _OI __result)
Moves the range [first,last) into result.
bool equal(_IIter1 __first1, _IIter1 __last1, _IIter2 __first2, _IIter2 __last2, _BinaryPredicate __binary_pred)
Tests a range for element-wise equality.
_GLIBCXX14_CONSTEXPR const _Tp & min(const _Tp &, const _Tp &)
This does what you think it does.
_GLIBCXX14_CONSTEXPR const _Tp & max(const _Tp &, const _Tp &)
This does what you think it does.
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.
Struct holding two objects of arbitrary type.
ISO C++ entities toplevel namespace is std.