64 #if __cplusplus >= 201103L
71 namespace std _GLIBCXX_VISIBILITY(default)
73 _GLIBCXX_BEGIN_NAMESPACE_VERSION
76 template<
typename _Iterator>
79 _Iterator __b, _Iterator __c)
82 __glibcxx_function_requires(_LessThanComparableConcept<
83 typename iterator_traits<_Iterator>::value_type>)
103 template<
typename _Iterator,
typename _Compare>
106 _Iterator __b, _Iterator __c,
110 __glibcxx_function_requires(_BinaryFunctionConcept<_Compare,
bool,
111 typename iterator_traits<_Iterator>::value_type,
112 typename iterator_traits<_Iterator>::value_type>)
114 if (__comp(*__a, *__b))
116 if (__comp(*__b, *__c))
118 else if (__comp(*__a, *__c))
123 else if (__comp(*__a, *__c))
125 else if (__comp(*__b, *__c))
134 template<
typename _InputIterator,
typename _Tp>
135 inline _InputIterator
136 __find(_InputIterator __first, _InputIterator __last,
139 while (__first != __last && !(*__first == __val))
145 template<
typename _InputIterator,
typename _Predicate>
146 inline _InputIterator
147 __find_if(_InputIterator __first, _InputIterator __last,
150 while (__first != __last && !
bool(__pred(*__first)))
156 template<
typename _RandomAccessIterator,
typename _Tp>
157 _RandomAccessIterator
158 __find(_RandomAccessIterator __first, _RandomAccessIterator __last,
161 typename iterator_traits<_RandomAccessIterator>::difference_type
162 __trip_count = (__last - __first) >> 2;
164 for (; __trip_count > 0; --__trip_count)
166 if (*__first == __val)
170 if (*__first == __val)
174 if (*__first == __val)
178 if (*__first == __val)
183 switch (__last - __first)
186 if (*__first == __val)
190 if (*__first == __val)
194 if (*__first == __val)
204 template<
typename _RandomAccessIterator,
typename _Predicate>
205 _RandomAccessIterator
206 __find_if(_RandomAccessIterator __first, _RandomAccessIterator __last,
209 typename iterator_traits<_RandomAccessIterator>::difference_type
210 __trip_count = (__last - __first) >> 2;
212 for (; __trip_count > 0; --__trip_count)
214 if (__pred(*__first))
218 if (__pred(*__first))
222 if (__pred(*__first))
226 if (__pred(*__first))
231 switch (__last - __first)
234 if (__pred(*__first))
238 if (__pred(*__first))
242 if (__pred(*__first))
252 template<
typename _InputIterator,
typename _Predicate>
253 inline _InputIterator
257 while (__first != __last &&
bool(__pred(*__first)))
263 template<
typename _RandomAccessIterator,
typename _Predicate>
264 _RandomAccessIterator
268 typename iterator_traits<_RandomAccessIterator>::difference_type
269 __trip_count = (__last - __first) >> 2;
271 for (; __trip_count > 0; --__trip_count)
273 if (!
bool(__pred(*__first)))
277 if (!
bool(__pred(*__first)))
281 if (!
bool(__pred(*__first)))
285 if (!
bool(__pred(*__first)))
290 switch (__last - __first)
293 if (!
bool(__pred(*__first)))
297 if (!
bool(__pred(*__first)))
301 if (!
bool(__pred(*__first)))
311 template<
typename _InputIterator,
typename _Predicate>
312 inline _InputIterator
323 template<
typename _InputIterator,
typename _Predicate,
typename _Distance>
327 for (; __len; --__len, ++__first)
328 if (!
bool(__pred(*__first)))
351 template<
typename _ForwardIterator,
typename _Integer,
typename _Tp>
353 __search_n(_ForwardIterator __first, _ForwardIterator __last,
354 _Integer __count,
const _Tp& __val,
358 while (__first != __last)
360 typename iterator_traits<_ForwardIterator>::difference_type
362 _ForwardIterator __i = __first;
364 while (__i != __last && __n != 1 && *__i == __val)
383 template<
typename _RandomAccessIter,
typename _Integer,
typename _Tp>
385 __search_n(_RandomAccessIter __first, _RandomAccessIter __last,
386 _Integer __count,
const _Tp& __val,
390 typedef typename std::iterator_traits<_RandomAccessIter>::difference_type
393 _DistanceType __tailSize = __last - __first;
394 _DistanceType __remainder = __count;
396 while (__remainder <= __tailSize)
398 __first += __remainder;
399 __tailSize -= __remainder;
402 _RandomAccessIter __backTrack = __first;
403 while (*--__backTrack == __val)
405 if (--__remainder == 0)
406 return (__first - __count);
408 __remainder = __count + 1 - (__first - __backTrack);
421 template<
typename _ForwardIterator,
typename _Integer,
typename _Tp,
422 typename _BinaryPredicate>
424 __search_n(_ForwardIterator __first, _ForwardIterator __last,
425 _Integer __count,
const _Tp& __val,
428 while (__first != __last && !
bool(__binary_pred(*__first, __val)))
431 while (__first != __last)
433 typename iterator_traits<_ForwardIterator>::difference_type
435 _ForwardIterator __i = __first;
437 while (__i != __last && __n != 1 &&
bool(__binary_pred(*__i, __val)))
447 while (__first != __last
448 && !
bool(__binary_pred(*__first, __val)))
460 template<
typename _RandomAccessIter,
typename _Integer,
typename _Tp,
461 typename _BinaryPredicate>
463 __search_n(_RandomAccessIter __first, _RandomAccessIter __last,
464 _Integer __count,
const _Tp& __val,
468 typedef typename std::iterator_traits<_RandomAccessIter>::difference_type
471 _DistanceType __tailSize = __last - __first;
472 _DistanceType __remainder = __count;
474 while (__remainder <= __tailSize)
476 __first += __remainder;
477 __tailSize -= __remainder;
480 _RandomAccessIter __backTrack = __first;
481 while (__binary_pred(*--__backTrack, __val))
483 if (--__remainder == 0)
484 return (__first - __count);
486 __remainder = __count + 1 - (__first - __backTrack);
492 template<
typename _ForwardIterator1,
typename _ForwardIterator2>
494 __find_end(_ForwardIterator1 __first1, _ForwardIterator1 __last1,
495 _ForwardIterator2 __first2, _ForwardIterator2 __last2,
496 forward_iterator_tag, forward_iterator_tag)
498 if (__first2 == __last2)
502 _ForwardIterator1 __result = __last1;
505 _ForwardIterator1 __new_result
507 if (__new_result == __last1)
511 __result = __new_result;
512 __first1 = __new_result;
519 template<
typename _ForwardIterator1,
typename _ForwardIterator2,
520 typename _BinaryPredicate>
522 __find_end(_ForwardIterator1 __first1, _ForwardIterator1 __last1,
523 _ForwardIterator2 __first2, _ForwardIterator2 __last2,
524 forward_iterator_tag, forward_iterator_tag,
525 _BinaryPredicate __comp)
527 if (__first2 == __last2)
531 _ForwardIterator1 __result = __last1;
534 _ForwardIterator1 __new_result
537 if (__new_result == __last1)
541 __result = __new_result;
542 __first1 = __new_result;
550 template<
typename _B
idirectionalIterator1,
typename _B
idirectionalIterator2>
551 _BidirectionalIterator1
552 __find_end(_BidirectionalIterator1 __first1,
553 _BidirectionalIterator1 __last1,
554 _BidirectionalIterator2 __first2,
555 _BidirectionalIterator2 __last2,
556 bidirectional_iterator_tag, bidirectional_iterator_tag)
559 __glibcxx_function_requires(_BidirectionalIteratorConcept<
560 _BidirectionalIterator1>)
561 __glibcxx_function_requires(_BidirectionalIteratorConcept<
562 _BidirectionalIterator2>)
564 typedef reverse_iterator<_BidirectionalIterator1> _RevIterator1;
565 typedef reverse_iterator<_BidirectionalIterator2> _RevIterator2;
567 _RevIterator1 __rlast1(__first1);
568 _RevIterator2 __rlast2(__first2);
569 _RevIterator1 __rresult = _GLIBCXX_STD_A::search(_RevIterator1(__last1),
571 _RevIterator2(__last2),
574 if (__rresult == __rlast1)
578 _BidirectionalIterator1 __result = __rresult.base();
584 template<
typename _BidirectionalIterator1,
typename _BidirectionalIterator2,
585 typename _BinaryPredicate>
586 _BidirectionalIterator1
587 __find_end(_BidirectionalIterator1 __first1,
588 _BidirectionalIterator1 __last1,
589 _BidirectionalIterator2 __first2,
590 _BidirectionalIterator2 __last2,
591 bidirectional_iterator_tag, bidirectional_iterator_tag,
592 _BinaryPredicate __comp)
595 __glibcxx_function_requires(_BidirectionalIteratorConcept<
596 _BidirectionalIterator1>)
597 __glibcxx_function_requires(_BidirectionalIteratorConcept<
598 _BidirectionalIterator2>)
600 typedef reverse_iterator<_BidirectionalIterator1> _RevIterator1;
601 typedef reverse_iterator<_BidirectionalIterator2> _RevIterator2;
603 _RevIterator1 __rlast1(__first1);
604 _RevIterator2 __rlast2(__first2);
605 _RevIterator1 __rresult =
std::search(_RevIterator1(__last1), __rlast1,
606 _RevIterator2(__last2), __rlast2,
609 if (__rresult == __rlast1)
613 _BidirectionalIterator1 __result = __rresult.base();
645 template<
typename _ForwardIterator1,
typename _ForwardIterator2>
646 inline _ForwardIterator1
647 find_end(_ForwardIterator1 __first1, _ForwardIterator1 __last1,
648 _ForwardIterator2 __first2, _ForwardIterator2 __last2)
651 __glibcxx_function_requires(_ForwardIteratorConcept<_ForwardIterator1>)
652 __glibcxx_function_requires(_ForwardIteratorConcept<_ForwardIterator2>)
653 __glibcxx_function_requires(_EqualOpConcept<
654 typename iterator_traits<_ForwardIterator1>::value_type,
655 typename iterator_traits<_ForwardIterator2>::value_type>)
656 __glibcxx_requires_valid_range(__first1, __last1);
657 __glibcxx_requires_valid_range(__first2, __last2);
659 return std::__find_end(__first1, __last1, __first2, __last2,
692 template<
typename _ForwardIterator1,
typename _ForwardIterator2,
693 typename _BinaryPredicate>
694 inline _ForwardIterator1
695 find_end(_ForwardIterator1 __first1, _ForwardIterator1 __last1,
696 _ForwardIterator2 __first2, _ForwardIterator2 __last2,
697 _BinaryPredicate __comp)
700 __glibcxx_function_requires(_ForwardIteratorConcept<_ForwardIterator1>)
701 __glibcxx_function_requires(_ForwardIteratorConcept<_ForwardIterator2>)
702 __glibcxx_function_requires(_BinaryPredicateConcept<_BinaryPredicate,
703 typename iterator_traits<_ForwardIterator1>::value_type,
704 typename iterator_traits<_ForwardIterator2>::value_type>)
705 __glibcxx_requires_valid_range(__first1, __last1);
706 __glibcxx_requires_valid_range(__first2, __last2);
708 return std::__find_end(__first1, __last1, __first2, __last2,
714 #if __cplusplus >= 201103L
727 template<
typename _InputIterator,
typename _Predicate>
729 all_of(_InputIterator __first, _InputIterator __last, _Predicate __pred)
744 template<
typename _InputIterator,
typename _Predicate>
746 none_of(_InputIterator __first, _InputIterator __last, _Predicate __pred)
762 template<
typename _InputIterator,
typename _Predicate>
764 any_of(_InputIterator __first, _InputIterator __last, _Predicate __pred)
777 template<
typename _InputIterator,
typename _Predicate>
778 inline _InputIterator
779 find_if_not(_InputIterator __first, _InputIterator __last,
783 __glibcxx_function_requires(_InputIteratorConcept<_InputIterator>)
784 __glibcxx_function_requires(_UnaryPredicateConcept<_Predicate,
785 typename iterator_traits<_InputIterator>::value_type>)
786 __glibcxx_requires_valid_range(__first, __last);
800 template<
typename _InputIterator,
typename _Predicate>
802 is_partitioned(_InputIterator __first, _InputIterator __last,
818 template<
typename _ForwardIterator,
typename _Predicate>
820 partition_point(_ForwardIterator __first, _ForwardIterator __last,
824 __glibcxx_function_requires(_ForwardIteratorConcept<_ForwardIterator>)
825 __glibcxx_function_requires(_UnaryPredicateConcept<_Predicate,
826 typename iterator_traits<_ForwardIterator>::value_type>)
829 __glibcxx_requires_valid_range(__first, __last);
831 typedef typename iterator_traits<_ForwardIterator>::difference_type
835 _DistanceType __half;
836 _ForwardIterator __middle;
843 if (__pred(*__middle))
847 __len = __len - __half - 1;
871 template<
typename _InputIterator,
typename _OutputIterator,
typename _Tp>
873 remove_copy(_InputIterator __first, _InputIterator __last,
874 _OutputIterator __result,
const _Tp& __value)
877 __glibcxx_function_requires(_InputIteratorConcept<_InputIterator>)
878 __glibcxx_function_requires(_OutputIteratorConcept<_OutputIterator,
879 typename iterator_traits<_InputIterator>::value_type>)
880 __glibcxx_function_requires(_EqualOpConcept<
881 typename iterator_traits<_InputIterator>::value_type, _Tp>)
882 __glibcxx_requires_valid_range(__first, __last);
884 for (; __first != __last; ++__first)
885 if (!(*__first == __value))
887 *__result = *__first;
908 template<
typename _InputIterator,
typename _OutputIterator,
911 remove_copy_if(_InputIterator __first, _InputIterator __last,
912 _OutputIterator __result, _Predicate __pred)
915 __glibcxx_function_requires(_InputIteratorConcept<_InputIterator>)
916 __glibcxx_function_requires(_OutputIteratorConcept<_OutputIterator,
917 typename iterator_traits<_InputIterator>::value_type>)
918 __glibcxx_function_requires(_UnaryPredicateConcept<_Predicate,
919 typename iterator_traits<_InputIterator>::value_type>)
920 __glibcxx_requires_valid_range(__first, __last);
922 for (; __first != __last; ++__first)
923 if (!
bool(__pred(*__first)))
925 *__result = *__first;
931 #if __cplusplus >= 201103L
947 template<
typename _InputIterator,
typename _OutputIterator,
950 copy_if(_InputIterator __first, _InputIterator __last,
951 _OutputIterator __result, _Predicate __pred)
954 __glibcxx_function_requires(_InputIteratorConcept<_InputIterator>)
955 __glibcxx_function_requires(_OutputIteratorConcept<_OutputIterator,
956 typename iterator_traits<_InputIterator>::value_type>)
957 __glibcxx_function_requires(_UnaryPredicateConcept<_Predicate,
958 typename iterator_traits<_InputIterator>::value_type>)
959 __glibcxx_requires_valid_range(__first, __last);
961 for (; __first != __last; ++__first)
962 if (__pred(*__first))
964 *__result = *__first;
971 template<
typename _InputIterator,
typename _Size,
typename _OutputIterator>
973 __copy_n(_InputIterator __first, _Size __n,
974 _OutputIterator __result, input_iterator_tag)
980 *__result = *__first;
991 template<
typename _RandomAccessIterator,
typename _Size,
992 typename _OutputIterator>
993 inline _OutputIterator
994 __copy_n(_RandomAccessIterator __first, _Size __n,
995 _OutputIterator __result, random_access_iterator_tag)
996 {
return std::copy(__first, __first + __n, __result); }
1011 template<
typename _InputIterator,
typename _Size,
typename _OutputIterator>
1012 inline _OutputIterator
1013 copy_n(_InputIterator __first, _Size __n, _OutputIterator __result)
1016 __glibcxx_function_requires(_InputIteratorConcept<_InputIterator>)
1017 __glibcxx_function_requires(_OutputIteratorConcept<_OutputIterator,
1018 typename iterator_traits<_InputIterator>::value_type>)
1020 return std::__copy_n(__first, __n, __result,
1039 template<
typename _InputIterator,
typename _OutputIterator1,
1040 typename _OutputIterator2,
typename _Predicate>
1041 pair<_OutputIterator1, _OutputIterator2>
1042 partition_copy(_InputIterator __first, _InputIterator __last,
1043 _OutputIterator1 __out_true, _OutputIterator2 __out_false,
1047 __glibcxx_function_requires(_InputIteratorConcept<_InputIterator>)
1048 __glibcxx_function_requires(_OutputIteratorConcept<_OutputIterator1,
1049 typename iterator_traits<_InputIterator>::value_type>)
1050 __glibcxx_function_requires(_OutputIteratorConcept<_OutputIterator2,
1051 typename iterator_traits<_InputIterator>::value_type>)
1052 __glibcxx_function_requires(_UnaryPredicateConcept<_Predicate,
1053 typename iterator_traits<_InputIterator>::value_type>)
1054 __glibcxx_requires_valid_range(__first, __last);
1056 for (; __first != __last; ++__first)
1057 if (__pred(*__first))
1059 *__out_true = *__first;
1064 *__out_false = *__first;
1089 template<
typename _ForwardIterator,
typename _Tp>
1091 remove(_ForwardIterator __first, _ForwardIterator __last,
1095 __glibcxx_function_requires(_Mutable_ForwardIteratorConcept<
1097 __glibcxx_function_requires(_EqualOpConcept<
1098 typename iterator_traits<_ForwardIterator>::value_type, _Tp>)
1099 __glibcxx_requires_valid_range(__first, __last);
1102 if(__first == __last)
1104 _ForwardIterator __result = __first;
1106 for(; __first != __last; ++__first)
1107 if(!(*__first == __value))
1109 *__result = _GLIBCXX_MOVE(*__first);
1132 template<
typename _ForwardIterator,
typename _Predicate>
1134 remove_if(_ForwardIterator __first, _ForwardIterator __last,
1138 __glibcxx_function_requires(_Mutable_ForwardIteratorConcept<
1140 __glibcxx_function_requires(_UnaryPredicateConcept<_Predicate,
1141 typename iterator_traits<_ForwardIterator>::value_type>)
1142 __glibcxx_requires_valid_range(__first, __last);
1145 if(__first == __last)
1147 _ForwardIterator __result = __first;
1149 for(; __first != __last; ++__first)
1150 if(!
bool(__pred(*__first)))
1152 *__result = _GLIBCXX_MOVE(*__first);
1172 template<
typename _ForwardIterator>
1174 unique(_ForwardIterator __first, _ForwardIterator __last)
1177 __glibcxx_function_requires(_Mutable_ForwardIteratorConcept<
1179 __glibcxx_function_requires(_EqualityComparableConcept<
1180 typename iterator_traits<_ForwardIterator>::value_type>)
1181 __glibcxx_requires_valid_range(__first, __last);
1185 if (__first == __last)
1189 _ForwardIterator __dest = __first;
1191 while (++__first != __last)
1192 if (!(*__dest == *__first))
1193 *++__dest = _GLIBCXX_MOVE(*__first);
1212 template<
typename _ForwardIterator,
typename _BinaryPredicate>
1214 unique(_ForwardIterator __first, _ForwardIterator __last,
1215 _BinaryPredicate __binary_pred)
1218 __glibcxx_function_requires(_Mutable_ForwardIteratorConcept<
1220 __glibcxx_function_requires(_BinaryPredicateConcept<_BinaryPredicate,
1221 typename iterator_traits<_ForwardIterator>::value_type,
1222 typename iterator_traits<_ForwardIterator>::value_type>)
1223 __glibcxx_requires_valid_range(__first, __last);
1227 if (__first == __last)
1231 _ForwardIterator __dest = __first;
1233 while (++__first != __last)
1234 if (!
bool(__binary_pred(*__dest, *__first)))
1235 *++__dest = _GLIBCXX_MOVE(*__first);
1244 template<
typename _ForwardIterator,
typename _OutputIterator>
1247 _OutputIterator __result,
1251 _ForwardIterator __next = __first;
1252 *__result = *__first;
1253 while (++__next != __last)
1254 if (!(*__first == *__next))
1257 *++__result = *__first;
1267 template<
typename _InputIterator,
typename _OutputIterator>
1270 _OutputIterator __result,
1274 typename iterator_traits<_InputIterator>::value_type __value = *__first;
1275 *__result = __value;
1276 while (++__first != __last)
1277 if (!(__value == *__first))
1280 *++__result = __value;
1290 template<
typename _InputIterator,
typename _ForwardIterator>
1293 _ForwardIterator __result,
1297 *__result = *__first;
1298 while (++__first != __last)
1299 if (!(*__result == *__first))
1300 *++__result = *__first;
1310 template<
typename _ForwardIterator,
typename _OutputIterator,
1311 typename _BinaryPredicate>
1314 _OutputIterator __result, _BinaryPredicate __binary_pred,
1318 __glibcxx_function_requires(_BinaryPredicateConcept<_BinaryPredicate,
1319 typename iterator_traits<_ForwardIterator>::value_type,
1320 typename iterator_traits<_ForwardIterator>::value_type>)
1322 _ForwardIterator __next = __first;
1323 *__result = *__first;
1324 while (++__next != __last)
1325 if (!
bool(__binary_pred(*__first, *__next)))
1328 *++__result = *__first;
1339 template<
typename _InputIterator,
typename _OutputIterator,
1340 typename _BinaryPredicate>
1343 _OutputIterator __result, _BinaryPredicate __binary_pred,
1347 __glibcxx_function_requires(_BinaryPredicateConcept<_BinaryPredicate,
1348 typename iterator_traits<_InputIterator>::value_type,
1349 typename iterator_traits<_InputIterator>::value_type>)
1351 typename iterator_traits<_InputIterator>::value_type __value = *__first;
1352 *__result = __value;
1353 while (++__first != __last)
1354 if (!
bool(__binary_pred(__value, *__first)))
1357 *++__result = __value;
1368 template<
typename _InputIterator,
typename _ForwardIterator,
1369 typename _BinaryPredicate>
1372 _ForwardIterator __result, _BinaryPredicate __binary_pred,
1376 __glibcxx_function_requires(_BinaryPredicateConcept<_BinaryPredicate,
1377 typename iterator_traits<_ForwardIterator>::value_type,
1378 typename iterator_traits<_InputIterator>::value_type>)
1380 *__result = *__first;
1381 while (++__first != __last)
1382 if (!
bool(__binary_pred(*__result, *__first)))
1383 *++__result = *__first;
1392 template<
typename _B
idirectionalIterator>
1394 __reverse(_BidirectionalIterator __first, _BidirectionalIterator __last,
1398 if (__first == __last || __first == --__last)
1412 template<
typename _RandomAccessIterator>
1414 __reverse(_RandomAccessIterator __first, _RandomAccessIterator __last,
1417 if (__first == __last)
1420 while (__first < __last)
1440 template<
typename _B
idirectionalIterator>
1442 reverse(_BidirectionalIterator __first, _BidirectionalIterator __last)
1445 __glibcxx_function_requires(_Mutable_BidirectionalIteratorConcept<
1446 _BidirectionalIterator>)
1447 __glibcxx_requires_valid_range(__first, __last);
1467 template<
typename _B
idirectionalIterator,
typename _OutputIterator>
1469 reverse_copy(_BidirectionalIterator __first, _BidirectionalIterator __last,
1470 _OutputIterator __result)
1473 __glibcxx_function_requires(_BidirectionalIteratorConcept<
1474 _BidirectionalIterator>)
1475 __glibcxx_function_requires(_OutputIteratorConcept<_OutputIterator,
1476 typename iterator_traits<_BidirectionalIterator>::value_type>)
1477 __glibcxx_requires_valid_range(__first, __last);
1479 while (__first != __last)
1482 *__result = *__last;
1492 template<
typename _Eucl
ideanRingElement>
1493 _EuclideanRingElement
1494 __gcd(_EuclideanRingElement __m, _EuclideanRingElement __n)
1498 _EuclideanRingElement __t = __m % __n;
1506 template<
typename _ForwardIterator>
1509 _ForwardIterator __middle,
1510 _ForwardIterator __last,
1513 if (__first == __middle || __last == __middle)
1516 _ForwardIterator __first2 = __middle;
1522 if (__first == __middle)
1523 __middle = __first2;
1525 while (__first2 != __last);
1527 __first2 = __middle;
1529 while (__first2 != __last)
1534 if (__first == __middle)
1535 __middle = __first2;
1536 else if (__first2 == __last)
1537 __first2 = __middle;
1542 template<
typename _B
idirectionalIterator>
1545 _BidirectionalIterator __middle,
1546 _BidirectionalIterator __last,
1550 __glibcxx_function_requires(_Mutable_BidirectionalIteratorConcept<
1551 _BidirectionalIterator>)
1553 if (__first == __middle || __last == __middle)
1559 while (__first != __middle && __middle != __last)
1565 if (__first == __middle)
1572 template<
typename _RandomAccessIterator>
1575 _RandomAccessIterator __middle,
1576 _RandomAccessIterator __last,
1580 __glibcxx_function_requires(_Mutable_RandomAccessIteratorConcept<
1581 _RandomAccessIterator>)
1583 if (__first == __middle || __last == __middle)
1586 typedef typename iterator_traits<_RandomAccessIterator>::difference_type
1588 typedef typename iterator_traits<_RandomAccessIterator>::value_type
1591 _Distance __n = __last - __first;
1592 _Distance __k = __middle - __first;
1594 if (__k == __n - __k)
1600 _RandomAccessIterator __p = __first;
1604 if (__k < __n - __k)
1606 if (__is_pod(_ValueType) && __k == 1)
1608 _ValueType __t = _GLIBCXX_MOVE(*__p);
1609 _GLIBCXX_MOVE3(__p + 1, __p + __n, __p);
1610 *(__p + __n - 1) = _GLIBCXX_MOVE(__t);
1613 _RandomAccessIterator __q = __p + __k;
1614 for (_Distance __i = 0; __i < __n - __k; ++ __i)
1629 if (__is_pod(_ValueType) && __k == 1)
1631 _ValueType __t = _GLIBCXX_MOVE(*(__p + __n - 1));
1632 _GLIBCXX_MOVE_BACKWARD3(__p, __p + __n - 1, __p + __n);
1633 *__p = _GLIBCXX_MOVE(__t);
1636 _RandomAccessIterator __q = __p + __n;
1638 for (_Distance __i = 0; __i < __n - __k; ++ __i)
1673 template<
typename _ForwardIterator>
1675 rotate(_ForwardIterator __first, _ForwardIterator __middle,
1676 _ForwardIterator __last)
1679 __glibcxx_function_requires(_Mutable_ForwardIteratorConcept<
1681 __glibcxx_requires_valid_range(__first, __middle);
1682 __glibcxx_requires_valid_range(__middle, __last);
1684 typedef typename iterator_traits<_ForwardIterator>::iterator_category
1709 template<
typename _ForwardIterator,
typename _OutputIterator>
1711 rotate_copy(_ForwardIterator __first, _ForwardIterator __middle,
1712 _ForwardIterator __last, _OutputIterator __result)
1715 __glibcxx_function_requires(_ForwardIteratorConcept<_ForwardIterator>)
1716 __glibcxx_function_requires(_OutputIteratorConcept<_OutputIterator,
1717 typename iterator_traits<_ForwardIterator>::value_type>)
1718 __glibcxx_requires_valid_range(__first, __middle);
1719 __glibcxx_requires_valid_range(__middle, __last);
1721 return std::copy(__first, __middle,
1722 std::copy(__middle, __last, __result));
1726 template<
typename _ForwardIterator,
typename _Predicate>
1731 if (__first == __last)
1734 while (__pred(*__first))
1735 if (++__first == __last)
1738 _ForwardIterator __next = __first;
1740 while (++__next != __last)
1741 if (__pred(*__next))
1751 template<
typename _B
idirectionalIterator,
typename _Predicate>
1752 _BidirectionalIterator
1753 __partition(_BidirectionalIterator __first, _BidirectionalIterator __last,
1759 if (__first == __last)
1761 else if (__pred(*__first))
1767 if (__first == __last)
1769 else if (!
bool(__pred(*__last)))
1783 template<
typename _ForwardIterator,
typename _Predicate,
typename _Distance>
1786 _Predicate __pred, _Distance __len)
1790 _ForwardIterator __middle = __first;
1792 _ForwardIterator __left_split =
1796 _Distance __right_len = __len - __len / 2;
1797 _ForwardIterator __right_split =
1803 std::rotate(__left_split, __middle, __right_split);
1805 return __left_split;
1814 template<
typename _ForwardIterator,
typename _Pointer,
typename _Predicate,
1818 _ForwardIterator __last,
1819 _Predicate __pred, _Distance __len,
1821 _Distance __buffer_size)
1823 if (__len <= __buffer_size)
1825 _ForwardIterator __result1 = __first;
1826 _Pointer __result2 = __buffer;
1830 *__result2 = _GLIBCXX_MOVE(*__first);
1833 for (; __first != __last; ++__first)
1834 if (__pred(*__first))
1836 *__result1 = _GLIBCXX_MOVE(*__first);
1841 *__result2 = _GLIBCXX_MOVE(*__first);
1844 _GLIBCXX_MOVE3(__buffer, __result2, __result1);
1849 _ForwardIterator __middle = __first;
1851 _ForwardIterator __left_split =
1853 __len / 2, __buffer,
1857 _Distance __right_len = __len - __len / 2;
1858 _ForwardIterator __right_split =
1864 __buffer, __buffer_size);
1865 std::rotate(__left_split, __middle, __right_split);
1867 return __left_split;
1888 template<
typename _ForwardIterator,
typename _Predicate>
1890 stable_partition(_ForwardIterator __first, _ForwardIterator __last,
1894 __glibcxx_function_requires(_Mutable_ForwardIteratorConcept<
1896 __glibcxx_function_requires(_UnaryPredicateConcept<_Predicate,
1897 typename iterator_traits<_ForwardIterator>::value_type>)
1898 __glibcxx_requires_valid_range(__first, __last);
1902 if (__first == __last)
1906 typedef typename iterator_traits<_ForwardIterator>::value_type
1908 typedef typename iterator_traits<_ForwardIterator>::difference_type
1913 if (__buf.
size() > 0)
1918 _DistanceType(__buf.
size()));
1927 template<
typename _RandomAccessIterator>
1930 _RandomAccessIterator __middle,
1931 _RandomAccessIterator __last)
1934 for (_RandomAccessIterator __i = __middle; __i < __last; ++__i)
1935 if (*__i < *__first)
1936 std::__pop_heap(__first, __middle, __i);
1940 template<
typename _RandomAccessIterator,
typename _Compare>
1943 _RandomAccessIterator __middle,
1944 _RandomAccessIterator __last, _Compare __comp)
1947 for (_RandomAccessIterator __i = __middle; __i < __last; ++__i)
1948 if (__comp(*__i, *__first))
1949 std::__pop_heap(__first, __middle, __i, __comp);
1972 template<
typename _InputIterator,
typename _RandomAccessIterator>
1973 _RandomAccessIterator
1974 partial_sort_copy(_InputIterator __first, _InputIterator __last,
1975 _RandomAccessIterator __result_first,
1976 _RandomAccessIterator __result_last)
1978 typedef typename iterator_traits<_InputIterator>::value_type
1980 typedef typename iterator_traits<_RandomAccessIterator>::value_type
1982 typedef typename iterator_traits<_RandomAccessIterator>::difference_type
1986 __glibcxx_function_requires(_InputIteratorConcept<_InputIterator>)
1987 __glibcxx_function_requires(_ConvertibleConcept<_InputValueType,
1989 __glibcxx_function_requires(_LessThanOpConcept<_InputValueType,
1991 __glibcxx_function_requires(_LessThanComparableConcept<_OutputValueType>)
1992 __glibcxx_requires_valid_range(__first, __last);
1993 __glibcxx_requires_valid_range(__result_first, __result_last);
1995 if (__result_first == __result_last)
1996 return __result_last;
1997 _RandomAccessIterator __result_real_last = __result_first;
1998 while(__first != __last && __result_real_last != __result_last)
2000 *__result_real_last = *__first;
2001 ++__result_real_last;
2005 while (__first != __last)
2007 if (*__first < *__result_first)
2008 std::__adjust_heap(__result_first, _DistanceType(0),
2009 _DistanceType(__result_real_last
2011 _InputValueType(*__first));
2015 return __result_real_last;
2038 template<
typename _InputIterator,
typename _RandomAccessIterator,
typename _Compare>
2039 _RandomAccessIterator
2040 partial_sort_copy(_InputIterator __first, _InputIterator __last,
2041 _RandomAccessIterator __result_first,
2042 _RandomAccessIterator __result_last,
2045 typedef typename iterator_traits<_InputIterator>::value_type
2047 typedef typename iterator_traits<_RandomAccessIterator>::value_type
2049 typedef typename iterator_traits<_RandomAccessIterator>::difference_type
2053 __glibcxx_function_requires(_InputIteratorConcept<_InputIterator>)
2054 __glibcxx_function_requires(_Mutable_RandomAccessIteratorConcept<
2055 _RandomAccessIterator>)
2056 __glibcxx_function_requires(_ConvertibleConcept<_InputValueType,
2058 __glibcxx_function_requires(_BinaryPredicateConcept<_Compare,
2059 _InputValueType, _OutputValueType>)
2060 __glibcxx_function_requires(_BinaryPredicateConcept<_Compare,
2061 _OutputValueType, _OutputValueType>)
2062 __glibcxx_requires_valid_range(__first, __last);
2063 __glibcxx_requires_valid_range(__result_first, __result_last);
2065 if (__result_first == __result_last)
2066 return __result_last;
2067 _RandomAccessIterator __result_real_last = __result_first;
2068 while(__first != __last && __result_real_last != __result_last)
2070 *__result_real_last = *__first;
2071 ++__result_real_last;
2075 while (__first != __last)
2077 if (__comp(*__first, *__result_first))
2078 std::__adjust_heap(__result_first, _DistanceType(0),
2079 _DistanceType(__result_real_last
2081 _InputValueType(*__first),
2086 return __result_real_last;
2090 template<
typename _RandomAccessIterator>
2094 typename iterator_traits<_RandomAccessIterator>::value_type
2095 __val = _GLIBCXX_MOVE(*__last);
2096 _RandomAccessIterator __next = __last;
2098 while (__val < *__next)
2100 *__last = _GLIBCXX_MOVE(*__next);
2104 *__last = _GLIBCXX_MOVE(__val);
2108 template<
typename _RandomAccessIterator,
typename _Compare>
2113 typename iterator_traits<_RandomAccessIterator>::value_type
2114 __val = _GLIBCXX_MOVE(*__last);
2115 _RandomAccessIterator __next = __last;
2117 while (__comp(__val, *__next))
2119 *__last = _GLIBCXX_MOVE(*__next);
2123 *__last = _GLIBCXX_MOVE(__val);
2127 template<
typename _RandomAccessIterator>
2130 _RandomAccessIterator __last)
2132 if (__first == __last)
2135 for (_RandomAccessIterator __i = __first + 1; __i != __last; ++__i)
2137 if (*__i < *__first)
2139 typename iterator_traits<_RandomAccessIterator>::value_type
2140 __val = _GLIBCXX_MOVE(*__i);
2141 _GLIBCXX_MOVE_BACKWARD3(__first, __i, __i + 1);
2142 *__first = _GLIBCXX_MOVE(__val);
2150 template<
typename _RandomAccessIterator,
typename _Compare>
2153 _RandomAccessIterator __last, _Compare __comp)
2155 if (__first == __last)
return;
2157 for (_RandomAccessIterator __i = __first + 1; __i != __last; ++__i)
2159 if (__comp(*__i, *__first))
2161 typename iterator_traits<_RandomAccessIterator>::value_type
2162 __val = _GLIBCXX_MOVE(*__i);
2163 _GLIBCXX_MOVE_BACKWARD3(__first, __i, __i + 1);
2164 *__first = _GLIBCXX_MOVE(__val);
2172 template<
typename _RandomAccessIterator>
2175 _RandomAccessIterator __last)
2177 typedef typename iterator_traits<_RandomAccessIterator>::value_type
2180 for (_RandomAccessIterator __i = __first; __i != __last; ++__i)
2185 template<
typename _RandomAccessIterator,
typename _Compare>
2188 _RandomAccessIterator __last, _Compare __comp)
2190 typedef typename iterator_traits<_RandomAccessIterator>::value_type
2193 for (_RandomAccessIterator __i = __first; __i != __last; ++__i)
2201 enum { _S_threshold = 16 };
2204 template<
typename _RandomAccessIterator>
2207 _RandomAccessIterator __last)
2209 if (__last - __first >
int(_S_threshold))
2219 template<
typename _RandomAccessIterator,
typename _Compare>
2222 _RandomAccessIterator __last, _Compare __comp)
2224 if (__last - __first >
int(_S_threshold))
2235 template<
typename _RandomAccessIterator,
typename _Tp>
2236 _RandomAccessIterator
2238 _RandomAccessIterator __last,
const _Tp& __pivot)
2242 while (*__first < __pivot)
2245 while (__pivot < *__last)
2247 if (!(__first < __last))
2255 template<
typename _RandomAccessIterator,
typename _Tp,
typename _Compare>
2256 _RandomAccessIterator
2258 _RandomAccessIterator __last,
2259 const _Tp& __pivot, _Compare __comp)
2263 while (__comp(*__first, __pivot))
2266 while (__comp(__pivot, *__last))
2268 if (!(__first < __last))
2276 template<
typename _RandomAccessIterator>
2277 inline _RandomAccessIterator
2279 _RandomAccessIterator __last)
2281 _RandomAccessIterator __mid = __first + (__last - __first) / 2;
2288 template<
typename _RandomAccessIterator,
typename _Compare>
2289 inline _RandomAccessIterator
2291 _RandomAccessIterator __last, _Compare __comp)
2293 _RandomAccessIterator __mid = __first + (__last - __first) / 2;
2300 template<
typename _RandomAccessIterator,
typename _Size>
2303 _RandomAccessIterator __last,
2304 _Size __depth_limit)
2306 while (__last - __first >
int(_S_threshold))
2308 if (__depth_limit == 0)
2314 _RandomAccessIterator __cut =
2322 template<
typename _RandomAccessIterator,
typename _Size,
typename _Compare>
2325 _RandomAccessIterator __last,
2326 _Size __depth_limit, _Compare __comp)
2328 while (__last - __first >
int(_S_threshold))
2330 if (__depth_limit == 0)
2336 _RandomAccessIterator __cut =
2345 template<
typename _RandomAccessIterator,
typename _Size>
2347 __introselect(_RandomAccessIterator __first, _RandomAccessIterator __nth,
2348 _RandomAccessIterator __last, _Size __depth_limit)
2350 typedef typename iterator_traits<_RandomAccessIterator>::value_type
2353 while (__last - __first > 3)
2355 if (__depth_limit == 0)
2360 std::iter_swap(__first, __nth);
2364 _RandomAccessIterator __cut =
2374 template<
typename _RandomAccessIterator,
typename _Size,
typename _Compare>
2376 __introselect(_RandomAccessIterator __first, _RandomAccessIterator __nth,
2377 _RandomAccessIterator __last, _Size __depth_limit,
2380 typedef typename iterator_traits<_RandomAccessIterator>::value_type
2383 while (__last - __first > 3)
2385 if (__depth_limit == 0)
2393 _RandomAccessIterator __cut =
2423 template<
typename _ForwardIterator,
typename _Tp,
typename _Compare>
2425 lower_bound(_ForwardIterator __first, _ForwardIterator __last,
2426 const _Tp& __val, _Compare __comp)
2428 typedef typename iterator_traits<_ForwardIterator>::value_type
2430 typedef typename iterator_traits<_ForwardIterator>::difference_type
2434 __glibcxx_function_requires(_ForwardIteratorConcept<_ForwardIterator>)
2435 __glibcxx_function_requires(_BinaryPredicateConcept<_Compare,
2437 __glibcxx_requires_partitioned_lower_pred(__first, __last,
2444 _DistanceType __half = __len >> 1;
2445 _ForwardIterator __middle = __first;
2447 if (__comp(*__middle, __val))
2451 __len = __len - __half - 1;
2470 template<
typename _ForwardIterator,
typename _Tp>
2472 upper_bound(_ForwardIterator __first, _ForwardIterator __last,
2475 typedef typename iterator_traits<_ForwardIterator>::value_type
2477 typedef typename iterator_traits<_ForwardIterator>::difference_type
2481 __glibcxx_function_requires(_ForwardIteratorConcept<_ForwardIterator>)
2482 __glibcxx_function_requires(_LessThanOpConcept<_Tp, _ValueType>)
2483 __glibcxx_requires_partitioned_upper(__first, __last, __val);
2489 _DistanceType __half = __len >> 1;
2490 _ForwardIterator __middle = __first;
2492 if (__val < *__middle)
2498 __len = __len - __half - 1;
2519 template<
typename _ForwardIterator,
typename _Tp,
typename _Compare>
2521 upper_bound(_ForwardIterator __first, _ForwardIterator __last,
2522 const _Tp& __val, _Compare __comp)
2524 typedef typename iterator_traits<_ForwardIterator>::value_type
2526 typedef typename iterator_traits<_ForwardIterator>::difference_type
2530 __glibcxx_function_requires(_ForwardIteratorConcept<_ForwardIterator>)
2531 __glibcxx_function_requires(_BinaryPredicateConcept<_Compare,
2533 __glibcxx_requires_partitioned_upper_pred(__first, __last,
2540 _DistanceType __half = __len >> 1;
2541 _ForwardIterator __middle = __first;
2543 if (__comp(__val, *__middle))
2549 __len = __len - __half - 1;
2572 template<
typename _ForwardIterator,
typename _Tp>
2573 pair<_ForwardIterator, _ForwardIterator>
2574 equal_range(_ForwardIterator __first, _ForwardIterator __last,
2577 typedef typename iterator_traits<_ForwardIterator>::value_type
2579 typedef typename iterator_traits<_ForwardIterator>::difference_type
2583 __glibcxx_function_requires(_ForwardIteratorConcept<_ForwardIterator>)
2584 __glibcxx_function_requires(_LessThanOpConcept<_ValueType, _Tp>)
2585 __glibcxx_function_requires(_LessThanOpConcept<_Tp, _ValueType>)
2586 __glibcxx_requires_partitioned_lower(__first, __last, __val);
2587 __glibcxx_requires_partitioned_upper(__first, __last, __val);
2593 _DistanceType __half = __len >> 1;
2594 _ForwardIterator __middle = __first;
2596 if (*__middle < __val)
2600 __len = __len - __half - 1;
2602 else if (__val < *__middle)
2634 template<
typename _ForwardIterator,
typename _Tp,
typename _Compare>
2635 pair<_ForwardIterator, _ForwardIterator>
2636 equal_range(_ForwardIterator __first, _ForwardIterator __last,
2637 const _Tp& __val, _Compare __comp)
2639 typedef typename iterator_traits<_ForwardIterator>::value_type
2641 typedef typename iterator_traits<_ForwardIterator>::difference_type
2645 __glibcxx_function_requires(_ForwardIteratorConcept<_ForwardIterator>)
2646 __glibcxx_function_requires(_BinaryPredicateConcept<_Compare,
2648 __glibcxx_function_requires(_BinaryPredicateConcept<_Compare,
2650 __glibcxx_requires_partitioned_lower_pred(__first, __last,
2652 __glibcxx_requires_partitioned_upper_pred(__first, __last,
2659 _DistanceType __half = __len >> 1;
2660 _ForwardIterator __middle = __first;
2662 if (__comp(*__middle, __val))
2666 __len = __len - __half - 1;
2668 else if (__comp(__val, *__middle))
2695 template<
typename _ForwardIterator,
typename _Tp>
2697 binary_search(_ForwardIterator __first, _ForwardIterator __last,
2700 typedef typename iterator_traits<_ForwardIterator>::value_type
2704 __glibcxx_function_requires(_ForwardIteratorConcept<_ForwardIterator>)
2705 __glibcxx_function_requires(_LessThanOpConcept<_Tp, _ValueType>)
2706 __glibcxx_requires_partitioned_lower(__first, __last, __val);
2707 __glibcxx_requires_partitioned_upper(__first, __last, __val);
2710 return __i != __last && !(__val < *__i);
2728 template<
typename _ForwardIterator,
typename _Tp,
typename _Compare>
2730 binary_search(_ForwardIterator __first, _ForwardIterator __last,
2731 const _Tp& __val, _Compare __comp)
2733 typedef typename iterator_traits<_ForwardIterator>::value_type
2737 __glibcxx_function_requires(_ForwardIteratorConcept<_ForwardIterator>)
2738 __glibcxx_function_requires(_BinaryPredicateConcept<_Compare,
2740 __glibcxx_requires_partitioned_lower_pred(__first, __last,
2742 __glibcxx_requires_partitioned_upper_pred(__first, __last,
2746 return __i != __last && !bool(__comp(__val, *__i));
2752 template<
typename _InputIterator1,
typename _InputIterator2,
2753 typename _OutputIterator>
2756 _InputIterator2 __first2, _InputIterator2 __last2,
2757 _OutputIterator __result)
2759 while (__first1 != __last1 && __first2 != __last2)
2761 if (*__first2 < *__first1)
2763 *__result = _GLIBCXX_MOVE(*__first2);
2768 *__result = _GLIBCXX_MOVE(*__first1);
2773 if (__first1 != __last1)
2774 _GLIBCXX_MOVE3(__first1, __last1, __result);
2778 template<
typename _InputIterator1,
typename _InputIterator2,
2779 typename _OutputIterator,
typename _Compare>
2782 _InputIterator2 __first2, _InputIterator2 __last2,
2783 _OutputIterator __result, _Compare __comp)
2785 while (__first1 != __last1 && __first2 != __last2)
2787 if (__comp(*__first2, *__first1))
2789 *__result = _GLIBCXX_MOVE(*__first2);
2794 *__result = _GLIBCXX_MOVE(*__first1);
2799 if (__first1 != __last1)
2800 _GLIBCXX_MOVE3(__first1, __last1, __result);
2804 template<
typename _BidirectionalIterator1,
typename _BidirectionalIterator2,
2805 typename _BidirectionalIterator3>
2808 _BidirectionalIterator1 __last1,
2809 _BidirectionalIterator2 __first2,
2810 _BidirectionalIterator2 __last2,
2811 _BidirectionalIterator3 __result)
2813 if (__first1 == __last1)
2815 _GLIBCXX_MOVE_BACKWARD3(__first2, __last2, __result);
2818 else if (__first2 == __last2)
2825 if (*__last2 < *__last1)
2827 *--__result = _GLIBCXX_MOVE(*__last1);
2828 if (__first1 == __last1)
2830 _GLIBCXX_MOVE_BACKWARD3(__first2, ++__last2, __result);
2837 *--__result = _GLIBCXX_MOVE(*__last2);
2838 if (__first2 == __last2)
2846 template<
typename _BidirectionalIterator1,
typename _BidirectionalIterator2,
2847 typename _BidirectionalIterator3,
typename _Compare>
2850 _BidirectionalIterator1 __last1,
2851 _BidirectionalIterator2 __first2,
2852 _BidirectionalIterator2 __last2,
2853 _BidirectionalIterator3 __result,
2856 if (__first1 == __last1)
2858 _GLIBCXX_MOVE_BACKWARD3(__first2, __last2, __result);
2861 else if (__first2 == __last2)
2868 if (__comp(*__last2, *__last1))
2870 *--__result = _GLIBCXX_MOVE(*__last1);
2871 if (__first1 == __last1)
2873 _GLIBCXX_MOVE_BACKWARD3(__first2, ++__last2, __result);
2880 *--__result = _GLIBCXX_MOVE(*__last2);
2881 if (__first2 == __last2)
2889 template<
typename _BidirectionalIterator1,
typename _BidirectionalIterator2,
2891 _BidirectionalIterator1
2893 _BidirectionalIterator1 __middle,
2894 _BidirectionalIterator1 __last,
2895 _Distance __len1, _Distance __len2,
2896 _BidirectionalIterator2 __buffer,
2897 _Distance __buffer_size)
2899 _BidirectionalIterator2 __buffer_end;
2900 if (__len1 > __len2 && __len2 <= __buffer_size)
2904 __buffer_end = _GLIBCXX_MOVE3(__middle, __last, __buffer);
2905 _GLIBCXX_MOVE_BACKWARD3(__first, __middle, __last);
2906 return _GLIBCXX_MOVE3(__buffer, __buffer_end, __first);
2911 else if (__len1 <= __buffer_size)
2915 __buffer_end = _GLIBCXX_MOVE3(__first, __middle, __buffer);
2916 _GLIBCXX_MOVE3(__middle, __last, __first);
2917 return _GLIBCXX_MOVE_BACKWARD3(__buffer, __buffer_end, __last);
2931 template<
typename _BidirectionalIterator,
typename _Distance,
2935 _BidirectionalIterator __middle,
2936 _BidirectionalIterator __last,
2937 _Distance __len1, _Distance __len2,
2938 _Pointer __buffer, _Distance __buffer_size)
2940 if (__len1 <= __len2 && __len1 <= __buffer_size)
2942 _Pointer __buffer_end = _GLIBCXX_MOVE3(__first, __middle, __buffer);
2946 else if (__len2 <= __buffer_size)
2948 _Pointer __buffer_end = _GLIBCXX_MOVE3(__middle, __last, __buffer);
2950 __buffer_end, __last);
2954 _BidirectionalIterator __first_cut = __first;
2955 _BidirectionalIterator __second_cut = __middle;
2956 _Distance __len11 = 0;
2957 _Distance __len22 = 0;
2958 if (__len1 > __len2)
2960 __len11 = __len1 / 2;
2968 __len22 = __len2 / 2;
2974 _BidirectionalIterator __new_middle =
2976 __len1 - __len11, __len22, __buffer,
2979 __len22, __buffer, __buffer_size);
2982 __len2 - __len22, __buffer, __buffer_size);
2987 template<
typename _BidirectionalIterator,
typename _Distance,
2988 typename _Pointer,
typename _Compare>
2991 _BidirectionalIterator __middle,
2992 _BidirectionalIterator __last,
2993 _Distance __len1, _Distance __len2,
2994 _Pointer __buffer, _Distance __buffer_size,
2997 if (__len1 <= __len2 && __len1 <= __buffer_size)
2999 _Pointer __buffer_end = _GLIBCXX_MOVE3(__first, __middle, __buffer);
3003 else if (__len2 <= __buffer_size)
3005 _Pointer __buffer_end = _GLIBCXX_MOVE3(__middle, __last, __buffer);
3007 __buffer_end, __last, __comp);
3011 _BidirectionalIterator __first_cut = __first;
3012 _BidirectionalIterator __second_cut = __middle;
3013 _Distance __len11 = 0;
3014 _Distance __len22 = 0;
3015 if (__len1 > __len2)
3017 __len11 = __len1 / 2;
3025 __len22 = __len2 / 2;
3031 _BidirectionalIterator __new_middle =
3033 __len1 - __len11, __len22, __buffer,
3036 __len22, __buffer, __buffer_size, __comp);
3039 __len2 - __len22, __buffer,
3040 __buffer_size, __comp);
3045 template<
typename _B
idirectionalIterator,
typename _Distance>
3048 _BidirectionalIterator __middle,
3049 _BidirectionalIterator __last,
3050 _Distance __len1, _Distance __len2)
3052 if (__len1 == 0 || __len2 == 0)
3054 if (__len1 + __len2 == 2)
3056 if (*__middle < *__first)
3060 _BidirectionalIterator __first_cut = __first;
3061 _BidirectionalIterator __second_cut = __middle;
3062 _Distance __len11 = 0;
3063 _Distance __len22 = 0;
3064 if (__len1 > __len2)
3066 __len11 = __len1 / 2;
3073 __len22 = __len2 / 2;
3079 _BidirectionalIterator __new_middle = __first_cut;
3084 __len1 - __len11, __len2 - __len22);
3088 template<
typename _BidirectionalIterator,
typename _Distance,
3092 _BidirectionalIterator __middle,
3093 _BidirectionalIterator __last,
3094 _Distance __len1, _Distance __len2,
3097 if (__len1 == 0 || __len2 == 0)
3099 if (__len1 + __len2 == 2)
3101 if (__comp(*__middle, *__first))
3105 _BidirectionalIterator __first_cut = __first;
3106 _BidirectionalIterator __second_cut = __middle;
3107 _Distance __len11 = 0;
3108 _Distance __len22 = 0;
3109 if (__len1 > __len2)
3111 __len11 = __len1 / 2;
3119 __len22 = __len2 / 2;
3126 _BidirectionalIterator __new_middle = __first_cut;
3129 __len11, __len22, __comp);
3131 __len1 - __len11, __len2 - __len22, __comp);
3152 template<
typename _B
idirectionalIterator>
3154 inplace_merge(_BidirectionalIterator __first,
3155 _BidirectionalIterator __middle,
3156 _BidirectionalIterator __last)
3158 typedef typename iterator_traits<_BidirectionalIterator>::value_type
3160 typedef typename iterator_traits<_BidirectionalIterator>::difference_type
3164 __glibcxx_function_requires(_Mutable_BidirectionalIteratorConcept<
3165 _BidirectionalIterator>)
3166 __glibcxx_function_requires(_LessThanComparableConcept<_ValueType>)
3167 __glibcxx_requires_sorted(__first, __middle);
3168 __glibcxx_requires_sorted(__middle, __last);
3170 if (__first == __middle || __middle == __last)
3178 if (__buf.
begin() == 0)
3182 __buf.
begin(), _DistanceType(__buf.
size()));
3207 template<
typename _B
idirectionalIterator,
typename _Compare>
3209 inplace_merge(_BidirectionalIterator __first,
3210 _BidirectionalIterator __middle,
3211 _BidirectionalIterator __last,
3214 typedef typename iterator_traits<_BidirectionalIterator>::value_type
3216 typedef typename iterator_traits<_BidirectionalIterator>::difference_type
3220 __glibcxx_function_requires(_Mutable_BidirectionalIteratorConcept<
3221 _BidirectionalIterator>)
3222 __glibcxx_function_requires(_BinaryPredicateConcept<_Compare,
3223 _ValueType, _ValueType>)
3224 __glibcxx_requires_sorted_pred(__first, __middle, __comp);
3225 __glibcxx_requires_sorted_pred(__middle, __last, __comp);
3227 if (__first == __middle || __middle == __last)
3230 const _DistanceType __len1 =
std::distance(__first, __middle);
3231 const _DistanceType __len2 =
std::distance(__middle, __last);
3235 if (__buf.
begin() == 0)
3240 __buf.
begin(), _DistanceType(__buf.
size()),
3246 template<
typename _InputIterator1,
typename _InputIterator2,
3247 typename _OutputIterator>
3250 _InputIterator2 __first2, _InputIterator2 __last2,
3251 _OutputIterator __result)
3253 while (__first1 != __last1 && __first2 != __last2)
3255 if (*__first2 < *__first1)
3257 *__result = _GLIBCXX_MOVE(*__first2);
3262 *__result = _GLIBCXX_MOVE(*__first1);
3267 return _GLIBCXX_MOVE3(__first2, __last2,
3268 _GLIBCXX_MOVE3(__first1, __last1,
3273 template<
typename _InputIterator1,
typename _InputIterator2,
3274 typename _OutputIterator,
typename _Compare>
3277 _InputIterator2 __first2, _InputIterator2 __last2,
3278 _OutputIterator __result, _Compare __comp)
3280 while (__first1 != __last1 && __first2 != __last2)
3282 if (__comp(*__first2, *__first1))
3284 *__result = _GLIBCXX_MOVE(*__first2);
3289 *__result = _GLIBCXX_MOVE(*__first1);
3294 return _GLIBCXX_MOVE3(__first2, __last2,
3295 _GLIBCXX_MOVE3(__first1, __last1,
3299 template<
typename _RandomAccessIterator1,
typename _RandomAccessIterator2,
3302 __merge_sort_loop(_RandomAccessIterator1 __first,
3303 _RandomAccessIterator1 __last,
3304 _RandomAccessIterator2 __result,
3305 _Distance __step_size)
3307 const _Distance __two_step = 2 * __step_size;
3309 while (__last - __first >= __two_step)
3312 __first + __step_size,
3313 __first + __two_step, __result);
3314 __first += __two_step;
3317 __step_size =
std::min(_Distance(__last - __first), __step_size);
3319 __first + __step_size, __last, __result);
3322 template<
typename _RandomAccessIterator1,
typename _RandomAccessIterator2,
3323 typename _Distance,
typename _Compare>
3325 __merge_sort_loop(_RandomAccessIterator1 __first,
3326 _RandomAccessIterator1 __last,
3327 _RandomAccessIterator2 __result, _Distance __step_size,
3330 const _Distance __two_step = 2 * __step_size;
3332 while (__last - __first >= __two_step)
3335 __first + __step_size,
3336 __first + __two_step,
3338 __first += __two_step;
3340 __step_size =
std::min(_Distance(__last - __first), __step_size);
3343 __first + __step_size, __last, __result, __comp);
3346 template<
typename _RandomAccessIterator,
typename _Distance>
3348 __chunk_insertion_sort(_RandomAccessIterator __first,
3349 _RandomAccessIterator __last,
3350 _Distance __chunk_size)
3352 while (__last - __first >= __chunk_size)
3355 __first += __chunk_size;
3360 template<
typename _RandomAccessIterator,
typename _Distance,
3363 __chunk_insertion_sort(_RandomAccessIterator __first,
3364 _RandomAccessIterator __last,
3365 _Distance __chunk_size, _Compare __comp)
3367 while (__last - __first >= __chunk_size)
3370 __first += __chunk_size;
3375 enum { _S_chunk_size = 7 };
3377 template<
typename _RandomAccessIterator,
typename _Po
inter>
3379 __merge_sort_with_buffer(_RandomAccessIterator __first,
3380 _RandomAccessIterator __last,
3383 typedef typename iterator_traits<_RandomAccessIterator>::difference_type
3386 const _Distance __len = __last - __first;
3387 const _Pointer __buffer_last = __buffer + __len;
3389 _Distance __step_size = _S_chunk_size;
3390 std::__chunk_insertion_sort(__first, __last, __step_size);
3392 while (__step_size < __len)
3394 std::__merge_sort_loop(__first, __last, __buffer, __step_size);
3396 std::__merge_sort_loop(__buffer, __buffer_last, __first, __step_size);
3401 template<
typename _RandomAccessIterator,
typename _Po
inter,
typename _Compare>
3403 __merge_sort_with_buffer(_RandomAccessIterator __first,
3404 _RandomAccessIterator __last,
3405 _Pointer __buffer, _Compare __comp)
3407 typedef typename iterator_traits<_RandomAccessIterator>::difference_type
3410 const _Distance __len = __last - __first;
3411 const _Pointer __buffer_last = __buffer + __len;
3413 _Distance __step_size = _S_chunk_size;
3414 std::__chunk_insertion_sort(__first, __last, __step_size, __comp);
3416 while (__step_size < __len)
3418 std::__merge_sort_loop(__first, __last, __buffer,
3419 __step_size, __comp);
3421 std::__merge_sort_loop(__buffer, __buffer_last, __first,
3422 __step_size, __comp);
3427 template<
typename _RandomAccessIterator,
typename _Pointer,
3430 __stable_sort_adaptive(_RandomAccessIterator __first,
3431 _RandomAccessIterator __last,
3432 _Pointer __buffer, _Distance __buffer_size)
3434 const _Distance __len = (__last - __first + 1) / 2;
3435 const _RandomAccessIterator __middle = __first + __len;
3436 if (__len > __buffer_size)
3438 std::__stable_sort_adaptive(__first, __middle,
3439 __buffer, __buffer_size);
3440 std::__stable_sort_adaptive(__middle, __last,
3441 __buffer, __buffer_size);
3445 std::__merge_sort_with_buffer(__first, __middle, __buffer);
3446 std::__merge_sort_with_buffer(__middle, __last, __buffer);
3449 _Distance(__middle - __first),
3450 _Distance(__last - __middle),
3451 __buffer, __buffer_size);
3454 template<
typename _RandomAccessIterator,
typename _Pointer,
3455 typename _Distance,
typename _Compare>
3457 __stable_sort_adaptive(_RandomAccessIterator __first,
3458 _RandomAccessIterator __last,
3459 _Pointer __buffer, _Distance __buffer_size,
3462 const _Distance __len = (__last - __first + 1) / 2;
3463 const _RandomAccessIterator __middle = __first + __len;
3464 if (__len > __buffer_size)
3466 std::__stable_sort_adaptive(__first, __middle, __buffer,
3467 __buffer_size, __comp);
3468 std::__stable_sort_adaptive(__middle, __last, __buffer,
3469 __buffer_size, __comp);
3473 std::__merge_sort_with_buffer(__first, __middle, __buffer, __comp);
3474 std::__merge_sort_with_buffer(__middle, __last, __buffer, __comp);
3477 _Distance(__middle - __first),
3478 _Distance(__last - __middle),
3479 __buffer, __buffer_size,
3484 template<
typename _RandomAccessIterator>
3487 _RandomAccessIterator __last)
3489 if (__last - __first < 15)
3494 _RandomAccessIterator __middle = __first + (__last - __first) / 2;
3503 template<
typename _RandomAccessIterator,
typename _Compare>
3506 _RandomAccessIterator __last, _Compare __comp)
3508 if (__last - __first < 15)
3513 _RandomAccessIterator __middle = __first + (__last - __first) / 2;
3547 template<
typename _InputIterator1,
typename _InputIterator2>
3549 includes(_InputIterator1 __first1, _InputIterator1 __last1,
3550 _InputIterator2 __first2, _InputIterator2 __last2)
3552 typedef typename iterator_traits<_InputIterator1>::value_type
3554 typedef typename iterator_traits<_InputIterator2>::value_type
3558 __glibcxx_function_requires(_InputIteratorConcept<_InputIterator1>)
3559 __glibcxx_function_requires(_InputIteratorConcept<_InputIterator2>)
3560 __glibcxx_function_requires(_LessThanOpConcept<_ValueType1, _ValueType2>)
3561 __glibcxx_function_requires(_LessThanOpConcept<_ValueType2, _ValueType1>)
3562 __glibcxx_requires_sorted_set(__first1, __last1, __first2);
3563 __glibcxx_requires_sorted_set(__first2, __last2, __first1);
3565 while (__first1 != __last1 && __first2 != __last2)
3566 if (*__first2 < *__first1)
3568 else if(*__first1 < *__first2)
3571 ++__first1, ++__first2;
3573 return __first2 == __last2;
3597 template<
typename _InputIterator1,
typename _InputIterator2,
3600 includes(_InputIterator1 __first1, _InputIterator1 __last1,
3601 _InputIterator2 __first2, _InputIterator2 __last2,
3604 typedef typename iterator_traits<_InputIterator1>::value_type
3606 typedef typename iterator_traits<_InputIterator2>::value_type
3610 __glibcxx_function_requires(_InputIteratorConcept<_InputIterator1>)
3611 __glibcxx_function_requires(_InputIteratorConcept<_InputIterator2>)
3612 __glibcxx_function_requires(_BinaryPredicateConcept<_Compare,
3613 _ValueType1, _ValueType2>)
3614 __glibcxx_function_requires(_BinaryPredicateConcept<_Compare,
3615 _ValueType2, _ValueType1>)
3616 __glibcxx_requires_sorted_set_pred(__first1, __last1, __first2, __comp);
3617 __glibcxx_requires_sorted_set_pred(__first2, __last2, __first1, __comp);
3619 while (__first1 != __last1 && __first2 != __last2)
3620 if (__comp(*__first2, *__first1))
3622 else if(__comp(*__first1, *__first2))
3625 ++__first1, ++__first2;
3627 return __first2 == __last2;
3652 template<
typename _B
idirectionalIterator>
3654 next_permutation(_BidirectionalIterator __first,
3655 _BidirectionalIterator __last)
3658 __glibcxx_function_requires(_BidirectionalIteratorConcept<
3659 _BidirectionalIterator>)
3660 __glibcxx_function_requires(_LessThanComparableConcept<
3661 typename iterator_traits<_BidirectionalIterator>::value_type>)
3662 __glibcxx_requires_valid_range(__first, __last);
3664 if (__first == __last)
3666 _BidirectionalIterator __i = __first;
3675 _BidirectionalIterator __ii = __i;
3679 _BidirectionalIterator __j = __last;
3680 while (!(*__i < *--__j))
3709 template<
typename _B
idirectionalIterator,
typename _Compare>
3711 next_permutation(_BidirectionalIterator __first,
3712 _BidirectionalIterator __last, _Compare __comp)
3715 __glibcxx_function_requires(_BidirectionalIteratorConcept<
3716 _BidirectionalIterator>)
3717 __glibcxx_function_requires(_BinaryPredicateConcept<_Compare,
3718 typename iterator_traits<_BidirectionalIterator>::value_type,
3719 typename iterator_traits<_BidirectionalIterator>::value_type>)
3720 __glibcxx_requires_valid_range(__first, __last);
3722 if (__first == __last)
3724 _BidirectionalIterator __i = __first;
3733 _BidirectionalIterator __ii = __i;
3735 if (__comp(*__i, *__ii))
3737 _BidirectionalIterator __j = __last;
3738 while (!
bool(__comp(*__i, *--__j)))
3765 template<
typename _B
idirectionalIterator>
3767 prev_permutation(_BidirectionalIterator __first,
3768 _BidirectionalIterator __last)
3771 __glibcxx_function_requires(_BidirectionalIteratorConcept<
3772 _BidirectionalIterator>)
3773 __glibcxx_function_requires(_LessThanComparableConcept<
3774 typename iterator_traits<_BidirectionalIterator>::value_type>)
3775 __glibcxx_requires_valid_range(__first, __last);
3777 if (__first == __last)
3779 _BidirectionalIterator __i = __first;
3788 _BidirectionalIterator __ii = __i;
3792 _BidirectionalIterator __j = __last;
3793 while (!(*--__j < *__i))
3822 template<
typename _B
idirectionalIterator,
typename _Compare>
3824 prev_permutation(_BidirectionalIterator __first,
3825 _BidirectionalIterator __last, _Compare __comp)
3828 __glibcxx_function_requires(_BidirectionalIteratorConcept<
3829 _BidirectionalIterator>)
3830 __glibcxx_function_requires(_BinaryPredicateConcept<_Compare,
3831 typename iterator_traits<_BidirectionalIterator>::value_type,
3832 typename iterator_traits<_BidirectionalIterator>::value_type>)
3833 __glibcxx_requires_valid_range(__first, __last);
3835 if (__first == __last)
3837 _BidirectionalIterator __i = __first;
3846 _BidirectionalIterator __ii = __i;
3848 if (__comp(*__ii, *__i))
3850 _BidirectionalIterator __j = __last;
3851 while (!
bool(__comp(*--__j, *__i)))
3882 template<
typename _InputIterator,
typename _OutputIterator,
typename _Tp>
3884 replace_copy(_InputIterator __first, _InputIterator __last,
3885 _OutputIterator __result,
3886 const _Tp& __old_value,
const _Tp& __new_value)
3889 __glibcxx_function_requires(_InputIteratorConcept<_InputIterator>)
3890 __glibcxx_function_requires(_OutputIteratorConcept<_OutputIterator,
3891 typename iterator_traits<_InputIterator>::value_type>)
3892 __glibcxx_function_requires(_EqualOpConcept<
3893 typename iterator_traits<_InputIterator>::value_type, _Tp>)
3894 __glibcxx_requires_valid_range(__first, __last);
3896 for (; __first != __last; ++__first, ++__result)
3897 if (*__first == __old_value)
3898 *__result = __new_value;
3900 *__result = *__first;
3919 template<
typename _InputIterator,
typename _OutputIterator,
3920 typename _Predicate,
typename _Tp>
3922 replace_copy_if(_InputIterator __first, _InputIterator __last,
3923 _OutputIterator __result,
3924 _Predicate __pred,
const _Tp& __new_value)
3927 __glibcxx_function_requires(_InputIteratorConcept<_InputIterator>)
3928 __glibcxx_function_requires(_OutputIteratorConcept<_OutputIterator,
3929 typename iterator_traits<_InputIterator>::value_type>)
3930 __glibcxx_function_requires(_UnaryPredicateConcept<_Predicate,
3931 typename iterator_traits<_InputIterator>::value_type>)
3932 __glibcxx_requires_valid_range(__first, __last);
3934 for (; __first != __last; ++__first, ++__result)
3935 if (__pred(*__first))
3936 *__result = __new_value;
3938 *__result = *__first;
3942 #if __cplusplus >= 201103L
3950 template<
typename _ForwardIterator>
3952 is_sorted(_ForwardIterator __first, _ForwardIterator __last)
3964 template<
typename _ForwardIterator,
typename _Compare>
3966 is_sorted(_ForwardIterator __first, _ForwardIterator __last,
3978 template<
typename _ForwardIterator>
3980 is_sorted_until(_ForwardIterator __first, _ForwardIterator __last)
3983 __glibcxx_function_requires(_ForwardIteratorConcept<_ForwardIterator>)
3984 __glibcxx_function_requires(_LessThanComparableConcept<
3985 typename iterator_traits<_ForwardIterator>::value_type>)
3986 __glibcxx_requires_valid_range(__first, __last);
3988 if (__first == __last)
3991 _ForwardIterator __next = __first;
3992 for (++__next; __next != __last; __first = __next, ++__next)
3993 if (*__next < *__first)
4007 template<
typename _ForwardIterator,
typename _Compare>
4009 is_sorted_until(_ForwardIterator __first, _ForwardIterator __last,
4013 __glibcxx_function_requires(_ForwardIteratorConcept<_ForwardIterator>)
4014 __glibcxx_function_requires(_BinaryPredicateConcept<_Compare,
4015 typename iterator_traits<_ForwardIterator>::value_type,
4016 typename iterator_traits<_ForwardIterator>::value_type>)
4017 __glibcxx_requires_valid_range(__first, __last);
4019 if (__first == __last)
4022 _ForwardIterator __next = __first;
4023 for (++__next; __next != __last; __first = __next, ++__next)
4024 if (__comp(*__next, *__first))
4037 template<
typename _Tp>
4038 inline pair<const _Tp&, const _Tp&>
4042 __glibcxx_function_requires(_LessThanComparableConcept<_Tp>)
4044 return __b < __a ? pair<const _Tp&, const _Tp&>(__b, __a)
4057 template<
typename _Tp,
typename _Compare>
4058 inline pair<const _Tp&, const _Tp&>
4059 minmax(
const _Tp& __a,
const _Tp& __b, _Compare __comp)
4076 template<
typename _ForwardIterator>
4077 pair<_ForwardIterator, _ForwardIterator>
4078 minmax_element(_ForwardIterator __first, _ForwardIterator __last)
4081 __glibcxx_function_requires(_ForwardIteratorConcept<_ForwardIterator>)
4082 __glibcxx_function_requires(_LessThanComparableConcept<
4083 typename iterator_traits<_ForwardIterator>::value_type>)
4084 __glibcxx_requires_valid_range(__first, __last);
4086 _ForwardIterator __next = __first;
4087 if (__first == __last
4088 || ++__next == __last)
4091 _ForwardIterator __min, __max;
4092 if (*__next < *__first)
4106 while (__first != __last)
4109 if (++__next == __last)
4111 if (*__first < *__min)
4113 else if (!(*__first < *__max))
4118 if (*__next < *__first)
4120 if (*__next < *__min)
4122 if (!(*__first < *__max))
4127 if (*__first < *__min)
4129 if (!(*__next < *__max))
4152 template<
typename _ForwardIterator,
typename _Compare>
4153 pair<_ForwardIterator, _ForwardIterator>
4154 minmax_element(_ForwardIterator __first, _ForwardIterator __last,
4158 __glibcxx_function_requires(_ForwardIteratorConcept<_ForwardIterator>)
4159 __glibcxx_function_requires(_BinaryPredicateConcept<_Compare,
4160 typename iterator_traits<_ForwardIterator>::value_type,
4161 typename iterator_traits<_ForwardIterator>::value_type>)
4162 __glibcxx_requires_valid_range(__first, __last);
4164 _ForwardIterator __next = __first;
4165 if (__first == __last
4166 || ++__next == __last)
4169 _ForwardIterator __min, __max;
4170 if (__comp(*__next, *__first))
4184 while (__first != __last)
4187 if (++__next == __last)
4189 if (__comp(*__first, *__min))
4191 else if (!__comp(*__first, *__max))
4196 if (__comp(*__next, *__first))
4198 if (__comp(*__next, *__min))
4200 if (!__comp(*__first, *__max))
4205 if (__comp(*__first, *__min))
4207 if (!__comp(*__next, *__max))
4219 template<
typename _Tp>
4221 min(initializer_list<_Tp> __l)
4222 {
return *std::min_element(__l.begin(), __l.end()); }
4224 template<
typename _Tp,
typename _Compare>
4226 min(initializer_list<_Tp> __l, _Compare __comp)
4229 template<
typename _Tp>
4231 max(initializer_list<_Tp> __l)
4234 template<
typename _Tp,
typename _Compare>
4236 max(initializer_list<_Tp> __l, _Compare __comp)
4239 template<
typename _Tp>
4240 inline pair<_Tp, _Tp>
4241 minmax(initializer_list<_Tp> __l)
4243 pair<const _Tp*, const _Tp*> __p =
4248 template<
typename _Tp,
typename _Compare>
4249 inline pair<_Tp, _Tp>
4250 minmax(initializer_list<_Tp> __l, _Compare __comp)
4252 pair<const _Tp*, const _Tp*> __p =
4269 template<
typename _ForwardIterator1,
typename _ForwardIterator2>
4271 is_permutation(_ForwardIterator1 __first1, _ForwardIterator1 __last1,
4272 _ForwardIterator2 __first2)
4276 for (; __first1 != __last1; ++__first1, ++__first2)
4277 if (!(*__first1 == *__first2))
4280 if (__first1 == __last1)
4285 _ForwardIterator2 __last2 = __first2;
4287 for (_ForwardIterator1 __scan = __first1; __scan != __last1; ++__scan)
4292 auto __matches =
std::count(__first2, __last2, *__scan);
4294 ||
std::count(__scan, __last1, *__scan) != __matches)
4314 template<
typename _ForwardIterator1,
typename _ForwardIterator2,
4315 typename _BinaryPredicate>
4317 is_permutation(_ForwardIterator1 __first1, _ForwardIterator1 __last1,
4318 _ForwardIterator2 __first2, _BinaryPredicate __pred)
4322 for (; __first1 != __last1; ++__first1, ++__first2)
4323 if (!
bool(__pred(*__first1, *__first2)))
4326 if (__first1 == __last1)
4331 _ForwardIterator2 __last2 = __first2;
4333 for (_ForwardIterator1 __scan = __first1; __scan != __last1; ++__scan)
4335 using std::placeholders::_1;
4338 std::bind(__pred, _1, *__scan)))
4342 std::bind(__pred, _1, *__scan));
4345 std::bind(__pred, _1, *__scan)) != __matches)
4351 #ifdef _GLIBCXX_USE_C99_STDINT_TR1
4364 template<
typename _RandomAccessIterator,
4365 typename _UniformRandomNumberGenerator>
4367 shuffle(_RandomAccessIterator __first, _RandomAccessIterator __last,
4368 _UniformRandomNumberGenerator&& __g)
4371 __glibcxx_function_requires(_Mutable_RandomAccessIteratorConcept<
4372 _RandomAccessIterator>)
4373 __glibcxx_requires_valid_range(__first, __last);
4375 if (__first == __last)
4378 typedef typename iterator_traits<_RandomAccessIterator>::difference_type
4381 typedef typename std::make_unsigned<_DistanceType>::type __ud_type;
4383 typedef typename __distr_type::param_type __p_type;
4386 for (_RandomAccessIterator __i = __first + 1; __i != __last; ++__i)
4387 std::iter_swap(__i, __first + __d(__g, __p_type(0, __i - __first)));
4393 _GLIBCXX_END_NAMESPACE_VERSION
4395 _GLIBCXX_BEGIN_NAMESPACE_ALGO
4409 template<
typename _InputIterator,
typename _Function>
4411 for_each(_InputIterator __first, _InputIterator __last, _Function __f)
4414 __glibcxx_function_requires(_InputIteratorConcept<_InputIterator>)
4415 __glibcxx_requires_valid_range(__first, __last);
4416 for (; __first != __last; ++__first)
4418 return _GLIBCXX_MOVE(__f);
4430 template<
typename _InputIterator,
typename _Tp>
4431 inline _InputIterator
4432 find(_InputIterator __first, _InputIterator __last,
4436 __glibcxx_function_requires(_InputIteratorConcept<_InputIterator>)
4437 __glibcxx_function_requires(_EqualOpConcept<
4438 typename iterator_traits<_InputIterator>::value_type, _Tp>)
4439 __glibcxx_requires_valid_range(__first, __last);
4454 template<
typename _InputIterator,
typename _Predicate>
4455 inline _InputIterator
4456 find_if(_InputIterator __first, _InputIterator __last,
4460 __glibcxx_function_requires(_InputIteratorConcept<_InputIterator>)
4461 __glibcxx_function_requires(_UnaryPredicateConcept<_Predicate,
4462 typename iterator_traits<_InputIterator>::value_type>)
4463 __glibcxx_requires_valid_range(__first, __last);
4484 template<
typename _InputIterator,
typename _ForwardIterator>
4486 find_first_of(_InputIterator __first1, _InputIterator __last1,
4487 _ForwardIterator __first2, _ForwardIterator __last2)
4490 __glibcxx_function_requires(_InputIteratorConcept<_InputIterator>)
4491 __glibcxx_function_requires(_ForwardIteratorConcept<_ForwardIterator>)
4492 __glibcxx_function_requires(_EqualOpConcept<
4493 typename iterator_traits<_InputIterator>::value_type,
4494 typename iterator_traits<_ForwardIterator>::value_type>)
4495 __glibcxx_requires_valid_range(__first1, __last1);
4496 __glibcxx_requires_valid_range(__first2, __last2);
4498 for (; __first1 != __last1; ++__first1)
4499 for (_ForwardIterator __iter = __first2; __iter != __last2; ++__iter)
4500 if (*__first1 == *__iter)
4524 template<
typename _InputIterator,
typename _ForwardIterator,
4525 typename _BinaryPredicate>
4527 find_first_of(_InputIterator __first1, _InputIterator __last1,
4528 _ForwardIterator __first2, _ForwardIterator __last2,
4529 _BinaryPredicate __comp)
4532 __glibcxx_function_requires(_InputIteratorConcept<_InputIterator>)
4533 __glibcxx_function_requires(_ForwardIteratorConcept<_ForwardIterator>)
4534 __glibcxx_function_requires(_BinaryPredicateConcept<_BinaryPredicate,
4535 typename iterator_traits<_InputIterator>::value_type,
4536 typename iterator_traits<_ForwardIterator>::value_type>)
4537 __glibcxx_requires_valid_range(__first1, __last1);
4538 __glibcxx_requires_valid_range(__first2, __last2);
4540 for (; __first1 != __last1; ++__first1)
4541 for (_ForwardIterator __iter = __first2; __iter != __last2; ++__iter)
4542 if (__comp(*__first1, *__iter))
4556 template<
typename _ForwardIterator>
4558 adjacent_find(_ForwardIterator __first, _ForwardIterator __last)
4561 __glibcxx_function_requires(_ForwardIteratorConcept<_ForwardIterator>)
4562 __glibcxx_function_requires(_EqualityComparableConcept<
4563 typename iterator_traits<_ForwardIterator>::value_type>)
4564 __glibcxx_requires_valid_range(__first, __last);
4565 if (__first == __last)
4567 _ForwardIterator __next = __first;
4568 while(++__next != __last)
4570 if (*__first == *__next)
4588 template<
typename _ForwardIterator,
typename _BinaryPredicate>
4590 adjacent_find(_ForwardIterator __first, _ForwardIterator __last,
4591 _BinaryPredicate __binary_pred)
4594 __glibcxx_function_requires(_ForwardIteratorConcept<_ForwardIterator>)
4595 __glibcxx_function_requires(_BinaryPredicateConcept<_BinaryPredicate,
4596 typename iterator_traits<_ForwardIterator>::value_type,
4597 typename iterator_traits<_ForwardIterator>::value_type>)
4598 __glibcxx_requires_valid_range(__first, __last);
4599 if (__first == __last)
4601 _ForwardIterator __next = __first;
4602 while(++__next != __last)
4604 if (__binary_pred(*__first, *__next))
4620 template<
typename _InputIterator,
typename _Tp>
4621 typename iterator_traits<_InputIterator>::difference_type
4622 count(_InputIterator __first, _InputIterator __last,
const _Tp& __value)
4625 __glibcxx_function_requires(_InputIteratorConcept<_InputIterator>)
4626 __glibcxx_function_requires(_EqualOpConcept<
4627 typename iterator_traits<_InputIterator>::value_type, _Tp>)
4628 __glibcxx_requires_valid_range(__first, __last);
4629 typename iterator_traits<_InputIterator>::difference_type __n = 0;
4630 for (; __first != __last; ++__first)
4631 if (*__first == __value)
4645 template<
typename _InputIterator,
typename _Predicate>
4646 typename iterator_traits<_InputIterator>::difference_type
4647 count_if(_InputIterator __first, _InputIterator __last, _Predicate __pred)
4650 __glibcxx_function_requires(_InputIteratorConcept<_InputIterator>)
4651 __glibcxx_function_requires(_UnaryPredicateConcept<_Predicate,
4652 typename iterator_traits<_InputIterator>::value_type>)
4653 __glibcxx_requires_valid_range(__first, __last);
4654 typename iterator_traits<_InputIterator>::difference_type __n = 0;
4655 for (; __first != __last; ++__first)
4656 if (__pred(*__first))
4687 template<
typename _ForwardIterator1,
typename _ForwardIterator2>
4689 search(_ForwardIterator1 __first1, _ForwardIterator1 __last1,
4690 _ForwardIterator2 __first2, _ForwardIterator2 __last2)
4693 __glibcxx_function_requires(_ForwardIteratorConcept<_ForwardIterator1>)
4694 __glibcxx_function_requires(_ForwardIteratorConcept<_ForwardIterator2>)
4695 __glibcxx_function_requires(_EqualOpConcept<
4696 typename iterator_traits<_ForwardIterator1>::value_type,
4697 typename iterator_traits<_ForwardIterator2>::value_type>)
4698 __glibcxx_requires_valid_range(__first1, __last1);
4699 __glibcxx_requires_valid_range(__first2, __last2);
4702 if (__first1 == __last1 || __first2 == __last2)
4706 _ForwardIterator2 __p1(__first2);
4707 if (++__p1 == __last2)
4711 _ForwardIterator2 __p;
4712 _ForwardIterator1 __current = __first1;
4717 if (__first1 == __last1)
4721 __current = __first1;
4722 if (++__current == __last1)
4725 while (*__current == *__p)
4727 if (++__p == __last2)
4729 if (++__current == __last1)
4758 template<
typename _ForwardIterator1,
typename _ForwardIterator2,
4759 typename _BinaryPredicate>
4761 search(_ForwardIterator1 __first1, _ForwardIterator1 __last1,
4762 _ForwardIterator2 __first2, _ForwardIterator2 __last2,
4763 _BinaryPredicate __predicate)
4766 __glibcxx_function_requires(_ForwardIteratorConcept<_ForwardIterator1>)
4767 __glibcxx_function_requires(_ForwardIteratorConcept<_ForwardIterator2>)
4768 __glibcxx_function_requires(_BinaryPredicateConcept<_BinaryPredicate,
4769 typename iterator_traits<_ForwardIterator1>::value_type,
4770 typename iterator_traits<_ForwardIterator2>::value_type>)
4771 __glibcxx_requires_valid_range(__first1, __last1);
4772 __glibcxx_requires_valid_range(__first2, __last2);
4775 if (__first1 == __last1 || __first2 == __last2)
4779 _ForwardIterator2 __p1(__first2);
4780 if (++__p1 == __last2)
4782 while (__first1 != __last1
4783 && !
bool(__predicate(*__first1, *__first2)))
4789 _ForwardIterator2 __p;
4790 _ForwardIterator1 __current = __first1;
4794 while (__first1 != __last1
4795 && !
bool(__predicate(*__first1, *__first2)))
4797 if (__first1 == __last1)
4801 __current = __first1;
4802 if (++__current == __last1)
4805 while (__predicate(*__current, *__p))
4807 if (++__p == __last2)
4809 if (++__current == __last1)
4833 template<
typename _ForwardIterator,
typename _Integer,
typename _Tp>
4835 search_n(_ForwardIterator __first, _ForwardIterator __last,
4836 _Integer __count,
const _Tp& __val)
4839 __glibcxx_function_requires(_ForwardIteratorConcept<_ForwardIterator>)
4840 __glibcxx_function_requires(_EqualOpConcept<
4841 typename iterator_traits<_ForwardIterator>::value_type, _Tp>)
4842 __glibcxx_requires_valid_range(__first, __last);
4870 template<
typename _ForwardIterator,
typename _Integer,
typename _Tp,
4871 typename _BinaryPredicate>
4873 search_n(_ForwardIterator __first, _ForwardIterator __last,
4874 _Integer __count,
const _Tp& __val,
4875 _BinaryPredicate __binary_pred)
4878 __glibcxx_function_requires(_ForwardIteratorConcept<_ForwardIterator>)
4879 __glibcxx_function_requires(_BinaryPredicateConcept<_BinaryPredicate,
4880 typename iterator_traits<_ForwardIterator>::value_type, _Tp>)
4881 __glibcxx_requires_valid_range(__first, __last);
4887 while (__first != __last && !
bool(__binary_pred(*__first, __val)))
4891 return std::__search_n(__first, __last, __count, __val, __binary_pred,
4912 template<
typename _InputIterator,
typename _OutputIterator,
4913 typename _UnaryOperation>
4915 transform(_InputIterator __first, _InputIterator __last,
4916 _OutputIterator __result, _UnaryOperation __unary_op)
4919 __glibcxx_function_requires(_InputIteratorConcept<_InputIterator>)
4920 __glibcxx_function_requires(_OutputIteratorConcept<_OutputIterator,
4922 __typeof__(__unary_op(*__first))>)
4923 __glibcxx_requires_valid_range(__first, __last);
4925 for (; __first != __last; ++__first, ++__result)
4926 *__result = __unary_op(*__first);
4949 template<
typename _InputIterator1,
typename _InputIterator2,
4950 typename _OutputIterator,
typename _BinaryOperation>
4952 transform(_InputIterator1 __first1, _InputIterator1 __last1,
4953 _InputIterator2 __first2, _OutputIterator __result,
4954 _BinaryOperation __binary_op)
4957 __glibcxx_function_requires(_InputIteratorConcept<_InputIterator1>)
4958 __glibcxx_function_requires(_InputIteratorConcept<_InputIterator2>)
4959 __glibcxx_function_requires(_OutputIteratorConcept<_OutputIterator,
4961 __typeof__(__binary_op(*__first1,*__first2))>)
4962 __glibcxx_requires_valid_range(__first1, __last1);
4964 for (; __first1 != __last1; ++__first1, ++__first2, ++__result)
4965 *__result = __binary_op(*__first1, *__first2);
4982 template<
typename _ForwardIterator,
typename _Tp>
4984 replace(_ForwardIterator __first, _ForwardIterator __last,
4985 const _Tp& __old_value,
const _Tp& __new_value)
4988 __glibcxx_function_requires(_Mutable_ForwardIteratorConcept<
4990 __glibcxx_function_requires(_EqualOpConcept<
4991 typename iterator_traits<_ForwardIterator>::value_type, _Tp>)
4992 __glibcxx_function_requires(_ConvertibleConcept<_Tp,
4993 typename iterator_traits<_ForwardIterator>::value_type>)
4994 __glibcxx_requires_valid_range(__first, __last);
4996 for (; __first != __last; ++__first)
4997 if (*__first == __old_value)
4998 *__first = __new_value;
5014 template<
typename _ForwardIterator,
typename _Predicate,
typename _Tp>
5016 replace_if(_ForwardIterator __first, _ForwardIterator __last,
5017 _Predicate __pred,
const _Tp& __new_value)
5020 __glibcxx_function_requires(_Mutable_ForwardIteratorConcept<
5022 __glibcxx_function_requires(_ConvertibleConcept<_Tp,
5023 typename iterator_traits<_ForwardIterator>::value_type>)
5024 __glibcxx_function_requires(_UnaryPredicateConcept<_Predicate,
5025 typename iterator_traits<_ForwardIterator>::value_type>)
5026 __glibcxx_requires_valid_range(__first, __last);
5028 for (; __first != __last; ++__first)
5029 if (__pred(*__first))
5030 *__first = __new_value;
5046 template<
typename _ForwardIterator,
typename _Generator>
5048 generate(_ForwardIterator __first, _ForwardIterator __last,
5052 __glibcxx_function_requires(_ForwardIteratorConcept<_ForwardIterator>)
5053 __glibcxx_function_requires(_GeneratorConcept<_Generator,
5054 typename iterator_traits<_ForwardIterator>::value_type>)
5055 __glibcxx_requires_valid_range(__first, __last);
5057 for (; __first != __last; ++__first)
5077 template<
typename _OutputIterator,
typename _Size,
typename _Generator>
5079 generate_n(_OutputIterator __first, _Size __n, _Generator __gen)
5082 __glibcxx_function_requires(_OutputIteratorConcept<_OutputIterator,
5084 __typeof__(__gen())>)
5086 for (__decltype(__n + 0) __niter = __n;
5087 __niter > 0; --__niter, ++__first)
5114 template<
typename _InputIterator,
typename _OutputIterator>
5115 inline _OutputIterator
5116 unique_copy(_InputIterator __first, _InputIterator __last,
5117 _OutputIterator __result)
5120 __glibcxx_function_requires(_InputIteratorConcept<_InputIterator>)
5121 __glibcxx_function_requires(_OutputIteratorConcept<_OutputIterator,
5122 typename iterator_traits<_InputIterator>::value_type>)
5123 __glibcxx_function_requires(_EqualityComparableConcept<
5124 typename iterator_traits<_InputIterator>::value_type>)
5125 __glibcxx_requires_valid_range(__first, __last);
5127 if (__first == __last)
5153 template<
typename _InputIterator,
typename _OutputIterator,
5154 typename _BinaryPredicate>
5155 inline _OutputIterator
5156 unique_copy(_InputIterator __first, _InputIterator __last,
5157 _OutputIterator __result,
5158 _BinaryPredicate __binary_pred)
5161 __glibcxx_function_requires(_InputIteratorConcept<_InputIterator>)
5162 __glibcxx_function_requires(_OutputIteratorConcept<_OutputIterator,
5163 typename iterator_traits<_InputIterator>::value_type>)
5164 __glibcxx_requires_valid_range(__first, __last);
5166 if (__first == __last)
5185 template<
typename _RandomAccessIterator>
5187 random_shuffle(_RandomAccessIterator __first, _RandomAccessIterator __last)
5190 __glibcxx_function_requires(_Mutable_RandomAccessIteratorConcept<
5191 _RandomAccessIterator>)
5192 __glibcxx_requires_valid_range(__first, __last);
5194 if (__first != __last)
5195 for (_RandomAccessIterator __i = __first + 1; __i != __last; ++__i)
5197 _RandomAccessIterator __j = __first
5198 + std::rand() % ((__i - __first) + 1);
5218 template<
typename _RandomAccessIterator,
typename _RandomNumberGenerator>
5220 random_shuffle(_RandomAccessIterator __first, _RandomAccessIterator __last,
5221 #
if __cplusplus >= 201103L
5222 _RandomNumberGenerator&& __rand)
5224 _RandomNumberGenerator& __rand)
5228 __glibcxx_function_requires(_Mutable_RandomAccessIteratorConcept<
5229 _RandomAccessIterator>)
5230 __glibcxx_requires_valid_range(__first, __last);
5232 if (__first == __last)
5234 for (_RandomAccessIterator __i = __first + 1; __i != __last; ++__i)
5236 _RandomAccessIterator __j = __first + __rand((__i - __first) + 1);
5258 template<
typename _ForwardIterator,
typename _Predicate>
5259 inline _ForwardIterator
5260 partition(_ForwardIterator __first, _ForwardIterator __last,
5264 __glibcxx_function_requires(_Mutable_ForwardIteratorConcept<
5266 __glibcxx_function_requires(_UnaryPredicateConcept<_Predicate,
5267 typename iterator_traits<_ForwardIterator>::value_type>)
5268 __glibcxx_requires_valid_range(__first, __last);
5292 template<
typename _RandomAccessIterator>
5294 partial_sort(_RandomAccessIterator __first,
5295 _RandomAccessIterator __middle,
5296 _RandomAccessIterator __last)
5298 typedef typename iterator_traits<_RandomAccessIterator>::value_type
5302 __glibcxx_function_requires(_Mutable_RandomAccessIteratorConcept<
5303 _RandomAccessIterator>)
5304 __glibcxx_function_requires(_LessThanComparableConcept<_ValueType>)
5305 __glibcxx_requires_valid_range(__first, __middle);
5306 __glibcxx_requires_valid_range(__middle, __last);
5331 template<
typename _RandomAccessIterator,
typename _Compare>
5333 partial_sort(_RandomAccessIterator __first,
5334 _RandomAccessIterator __middle,
5335 _RandomAccessIterator __last,
5338 typedef typename iterator_traits<_RandomAccessIterator>::value_type
5342 __glibcxx_function_requires(_Mutable_RandomAccessIteratorConcept<
5343 _RandomAccessIterator>)
5344 __glibcxx_function_requires(_BinaryPredicateConcept<_Compare,
5345 _ValueType, _ValueType>)
5346 __glibcxx_requires_valid_range(__first, __middle);
5347 __glibcxx_requires_valid_range(__middle, __last);
5368 template<
typename _RandomAccessIterator>
5370 nth_element(_RandomAccessIterator __first, _RandomAccessIterator __nth,
5371 _RandomAccessIterator __last)
5373 typedef typename iterator_traits<_RandomAccessIterator>::value_type
5377 __glibcxx_function_requires(_Mutable_RandomAccessIteratorConcept<
5378 _RandomAccessIterator>)
5379 __glibcxx_function_requires(_LessThanComparableConcept<_ValueType>)
5380 __glibcxx_requires_valid_range(__first, __nth);
5381 __glibcxx_requires_valid_range(__nth, __last);
5383 if (__first == __last || __nth == __last)
5386 std::__introselect(__first, __nth, __last,
5407 template<
typename _RandomAccessIterator,
typename _Compare>
5409 nth_element(_RandomAccessIterator __first, _RandomAccessIterator __nth,
5410 _RandomAccessIterator __last, _Compare __comp)
5412 typedef typename iterator_traits<_RandomAccessIterator>::value_type
5416 __glibcxx_function_requires(_Mutable_RandomAccessIteratorConcept<
5417 _RandomAccessIterator>)
5418 __glibcxx_function_requires(_BinaryPredicateConcept<_Compare,
5419 _ValueType, _ValueType>)
5420 __glibcxx_requires_valid_range(__first, __nth);
5421 __glibcxx_requires_valid_range(__nth, __last);
5423 if (__first == __last || __nth == __last)
5426 std::__introselect(__first, __nth, __last,
5427 std::__lg(__last - __first) * 2, __comp);
5445 template<
typename _RandomAccessIterator>
5447 sort(_RandomAccessIterator __first, _RandomAccessIterator __last)
5449 typedef typename iterator_traits<_RandomAccessIterator>::value_type
5453 __glibcxx_function_requires(_Mutable_RandomAccessIteratorConcept<
5454 _RandomAccessIterator>)
5455 __glibcxx_function_requires(_LessThanComparableConcept<_ValueType>)
5456 __glibcxx_requires_valid_range(__first, __last);
5458 if (__first != __last)
5481 template<
typename _RandomAccessIterator,
typename _Compare>
5483 sort(_RandomAccessIterator __first, _RandomAccessIterator __last,
5486 typedef typename iterator_traits<_RandomAccessIterator>::value_type
5490 __glibcxx_function_requires(_Mutable_RandomAccessIteratorConcept<
5491 _RandomAccessIterator>)
5492 __glibcxx_function_requires(_BinaryPredicateConcept<_Compare, _ValueType,
5494 __glibcxx_requires_valid_range(__first, __last);
5496 if (__first != __last)
5499 std::__lg(__last - __first) * 2, __comp);
5523 template<
typename _InputIterator1,
typename _InputIterator2,
5524 typename _OutputIterator>
5526 merge(_InputIterator1 __first1, _InputIterator1 __last1,
5527 _InputIterator2 __first2, _InputIterator2 __last2,
5528 _OutputIterator __result)
5530 typedef typename iterator_traits<_InputIterator1>::value_type
5532 typedef typename iterator_traits<_InputIterator2>::value_type
5536 __glibcxx_function_requires(_InputIteratorConcept<_InputIterator1>)
5537 __glibcxx_function_requires(_InputIteratorConcept<_InputIterator2>)
5538 __glibcxx_function_requires(_OutputIteratorConcept<_OutputIterator,
5540 __glibcxx_function_requires(_OutputIteratorConcept<_OutputIterator,
5542 __glibcxx_function_requires(_LessThanOpConcept<_ValueType2, _ValueType1>)
5543 __glibcxx_requires_sorted_set(__first1, __last1, __first2);
5544 __glibcxx_requires_sorted_set(__first2, __last2, __first1);
5546 while (__first1 != __last1 && __first2 != __last2)
5548 if (*__first2 < *__first1)
5550 *__result = *__first2;
5555 *__result = *__first1;
5560 return std::copy(__first2, __last2, std::copy(__first1, __last1,
5587 template<
typename _InputIterator1,
typename _InputIterator2,
5588 typename _OutputIterator,
typename _Compare>
5590 merge(_InputIterator1 __first1, _InputIterator1 __last1,
5591 _InputIterator2 __first2, _InputIterator2 __last2,
5592 _OutputIterator __result, _Compare __comp)
5594 typedef typename iterator_traits<_InputIterator1>::value_type
5596 typedef typename iterator_traits<_InputIterator2>::value_type
5600 __glibcxx_function_requires(_InputIteratorConcept<_InputIterator1>)
5601 __glibcxx_function_requires(_InputIteratorConcept<_InputIterator2>)
5602 __glibcxx_function_requires(_OutputIteratorConcept<_OutputIterator,
5604 __glibcxx_function_requires(_OutputIteratorConcept<_OutputIterator,
5606 __glibcxx_function_requires(_BinaryPredicateConcept<_Compare,
5607 _ValueType2, _ValueType1>)
5608 __glibcxx_requires_sorted_set_pred(__first1, __last1, __first2, __comp);
5609 __glibcxx_requires_sorted_set_pred(__first2, __last2, __first1, __comp);
5611 while (__first1 != __last1 && __first2 != __last2)
5613 if (__comp(*__first2, *__first1))
5615 *__result = *__first2;
5620 *__result = *__first1;
5625 return std::copy(__first2, __last2, std::copy(__first1, __last1,
5647 template<
typename _RandomAccessIterator>
5649 stable_sort(_RandomAccessIterator __first, _RandomAccessIterator __last)
5651 typedef typename iterator_traits<_RandomAccessIterator>::value_type
5653 typedef typename iterator_traits<_RandomAccessIterator>::difference_type
5657 __glibcxx_function_requires(_Mutable_RandomAccessIteratorConcept<
5658 _RandomAccessIterator>)
5659 __glibcxx_function_requires(_LessThanComparableConcept<_ValueType>)
5660 __glibcxx_requires_valid_range(__first, __last);
5664 if (__buf.
begin() == 0)
5667 std::__stable_sort_adaptive(__first, __last, __buf.
begin(),
5668 _DistanceType(__buf.
size()));
5689 template<
typename _RandomAccessIterator,
typename _Compare>
5691 stable_sort(_RandomAccessIterator __first, _RandomAccessIterator __last,
5694 typedef typename iterator_traits<_RandomAccessIterator>::value_type
5696 typedef typename iterator_traits<_RandomAccessIterator>::difference_type
5700 __glibcxx_function_requires(_Mutable_RandomAccessIteratorConcept<
5701 _RandomAccessIterator>)
5702 __glibcxx_function_requires(_BinaryPredicateConcept<_Compare,
5705 __glibcxx_requires_valid_range(__first, __last);
5709 if (__buf.
begin() == 0)
5712 std::__stable_sort_adaptive(__first, __last, __buf.
begin(),
5713 _DistanceType(__buf.
size()), __comp);
5735 template<
typename _InputIterator1,
typename _InputIterator2,
5736 typename _OutputIterator>
5738 set_union(_InputIterator1 __first1, _InputIterator1 __last1,
5739 _InputIterator2 __first2, _InputIterator2 __last2,
5740 _OutputIterator __result)
5742 typedef typename iterator_traits<_InputIterator1>::value_type
5744 typedef typename iterator_traits<_InputIterator2>::value_type
5748 __glibcxx_function_requires(_InputIteratorConcept<_InputIterator1>)
5749 __glibcxx_function_requires(_InputIteratorConcept<_InputIterator2>)
5750 __glibcxx_function_requires(_OutputIteratorConcept<_OutputIterator,
5752 __glibcxx_function_requires(_OutputIteratorConcept<_OutputIterator,
5754 __glibcxx_function_requires(_LessThanOpConcept<_ValueType1, _ValueType2>)
5755 __glibcxx_function_requires(_LessThanOpConcept<_ValueType2, _ValueType1>)
5756 __glibcxx_requires_sorted_set(__first1, __last1, __first2);
5757 __glibcxx_requires_sorted_set(__first2, __last2, __first1);
5759 while (__first1 != __last1 && __first2 != __last2)
5761 if (*__first1 < *__first2)
5763 *__result = *__first1;
5766 else if (*__first2 < *__first1)
5768 *__result = *__first2;
5773 *__result = *__first1;
5779 return std::copy(__first2, __last2, std::copy(__first1, __last1,
5802 template<
typename _InputIterator1,
typename _InputIterator2,
5803 typename _OutputIterator,
typename _Compare>
5805 set_union(_InputIterator1 __first1, _InputIterator1 __last1,
5806 _InputIterator2 __first2, _InputIterator2 __last2,
5807 _OutputIterator __result, _Compare __comp)
5809 typedef typename iterator_traits<_InputIterator1>::value_type
5811 typedef typename iterator_traits<_InputIterator2>::value_type
5815 __glibcxx_function_requires(_InputIteratorConcept<_InputIterator1>)
5816 __glibcxx_function_requires(_InputIteratorConcept<_InputIterator2>)
5817 __glibcxx_function_requires(_OutputIteratorConcept<_OutputIterator,
5819 __glibcxx_function_requires(_OutputIteratorConcept<_OutputIterator,
5821 __glibcxx_function_requires(_BinaryPredicateConcept<_Compare,
5822 _ValueType1, _ValueType2>)
5823 __glibcxx_function_requires(_BinaryPredicateConcept<_Compare,
5824 _ValueType2, _ValueType1>)
5825 __glibcxx_requires_sorted_set_pred(__first1, __last1, __first2, __comp);
5826 __glibcxx_requires_sorted_set_pred(__first2, __last2, __first1, __comp);
5828 while (__first1 != __last1 && __first2 != __last2)
5830 if (__comp(*__first1, *__first2))
5832 *__result = *__first1;
5835 else if (__comp(*__first2, *__first1))
5837 *__result = *__first2;
5842 *__result = *__first1;
5848 return std::copy(__first2, __last2, std::copy(__first1, __last1,
5869 template<
typename _InputIterator1,
typename _InputIterator2,
5870 typename _OutputIterator>
5872 set_intersection(_InputIterator1 __first1, _InputIterator1 __last1,
5873 _InputIterator2 __first2, _InputIterator2 __last2,
5874 _OutputIterator __result)
5876 typedef typename iterator_traits<_InputIterator1>::value_type
5878 typedef typename iterator_traits<_InputIterator2>::value_type
5882 __glibcxx_function_requires(_InputIteratorConcept<_InputIterator1>)
5883 __glibcxx_function_requires(_InputIteratorConcept<_InputIterator2>)
5884 __glibcxx_function_requires(_OutputIteratorConcept<_OutputIterator,
5886 __glibcxx_function_requires(_LessThanOpConcept<_ValueType1, _ValueType2>)
5887 __glibcxx_function_requires(_LessThanOpConcept<_ValueType2, _ValueType1>)
5888 __glibcxx_requires_sorted_set(__first1, __last1, __first2);
5889 __glibcxx_requires_sorted_set(__first2, __last2, __first1);
5891 while (__first1 != __last1 && __first2 != __last2)
5892 if (*__first1 < *__first2)
5894 else if (*__first2 < *__first1)
5898 *__result = *__first1;
5926 template<
typename _InputIterator1,
typename _InputIterator2,
5927 typename _OutputIterator,
typename _Compare>
5929 set_intersection(_InputIterator1 __first1, _InputIterator1 __last1,
5930 _InputIterator2 __first2, _InputIterator2 __last2,
5931 _OutputIterator __result, _Compare __comp)
5933 typedef typename iterator_traits<_InputIterator1>::value_type
5935 typedef typename iterator_traits<_InputIterator2>::value_type
5939 __glibcxx_function_requires(_InputIteratorConcept<_InputIterator1>)
5940 __glibcxx_function_requires(_InputIteratorConcept<_InputIterator2>)
5941 __glibcxx_function_requires(_OutputIteratorConcept<_OutputIterator,
5943 __glibcxx_function_requires(_BinaryPredicateConcept<_Compare,
5944 _ValueType1, _ValueType2>)
5945 __glibcxx_function_requires(_BinaryPredicateConcept<_Compare,
5946 _ValueType2, _ValueType1>)
5947 __glibcxx_requires_sorted_set_pred(__first1, __last1, __first2, __comp);
5948 __glibcxx_requires_sorted_set_pred(__first2, __last2, __first1, __comp);
5950 while (__first1 != __last1 && __first2 != __last2)
5951 if (__comp(*__first1, *__first2))
5953 else if (__comp(*__first2, *__first1))
5957 *__result = *__first1;
5984 template<
typename _InputIterator1,
typename _InputIterator2,
5985 typename _OutputIterator>
5987 set_difference(_InputIterator1 __first1, _InputIterator1 __last1,
5988 _InputIterator2 __first2, _InputIterator2 __last2,
5989 _OutputIterator __result)
5991 typedef typename iterator_traits<_InputIterator1>::value_type
5993 typedef typename iterator_traits<_InputIterator2>::value_type
5997 __glibcxx_function_requires(_InputIteratorConcept<_InputIterator1>)
5998 __glibcxx_function_requires(_InputIteratorConcept<_InputIterator2>)
5999 __glibcxx_function_requires(_OutputIteratorConcept<_OutputIterator,
6001 __glibcxx_function_requires(_LessThanOpConcept<_ValueType1, _ValueType2>)
6002 __glibcxx_function_requires(_LessThanOpConcept<_ValueType2, _ValueType1>)
6003 __glibcxx_requires_sorted_set(__first1, __last1, __first2);
6004 __glibcxx_requires_sorted_set(__first2, __last2, __first1);
6006 while (__first1 != __last1 && __first2 != __last2)
6007 if (*__first1 < *__first2)
6009 *__result = *__first1;
6013 else if (*__first2 < *__first1)
6020 return std::copy(__first1, __last1, __result);
6045 template<
typename _InputIterator1,
typename _InputIterator2,
6046 typename _OutputIterator,
typename _Compare>
6048 set_difference(_InputIterator1 __first1, _InputIterator1 __last1,
6049 _InputIterator2 __first2, _InputIterator2 __last2,
6050 _OutputIterator __result, _Compare __comp)
6052 typedef typename iterator_traits<_InputIterator1>::value_type
6054 typedef typename iterator_traits<_InputIterator2>::value_type
6058 __glibcxx_function_requires(_InputIteratorConcept<_InputIterator1>)
6059 __glibcxx_function_requires(_InputIteratorConcept<_InputIterator2>)
6060 __glibcxx_function_requires(_OutputIteratorConcept<_OutputIterator,
6062 __glibcxx_function_requires(_BinaryPredicateConcept<_Compare,
6063 _ValueType1, _ValueType2>)
6064 __glibcxx_function_requires(_BinaryPredicateConcept<_Compare,
6065 _ValueType2, _ValueType1>)
6066 __glibcxx_requires_sorted_set_pred(__first1, __last1, __first2, __comp);
6067 __glibcxx_requires_sorted_set_pred(__first2, __last2, __first1, __comp);
6069 while (__first1 != __last1 && __first2 != __last2)
6070 if (__comp(*__first1, *__first2))
6072 *__result = *__first1;
6076 else if (__comp(*__first2, *__first1))
6083 return std::copy(__first1, __last1, __result);
6103 template<
typename _InputIterator1,
typename _InputIterator2,
6104 typename _OutputIterator>
6106 set_symmetric_difference(_InputIterator1 __first1, _InputIterator1 __last1,
6107 _InputIterator2 __first2, _InputIterator2 __last2,
6108 _OutputIterator __result)
6110 typedef typename iterator_traits<_InputIterator1>::value_type
6112 typedef typename iterator_traits<_InputIterator2>::value_type
6116 __glibcxx_function_requires(_InputIteratorConcept<_InputIterator1>)
6117 __glibcxx_function_requires(_InputIteratorConcept<_InputIterator2>)
6118 __glibcxx_function_requires(_OutputIteratorConcept<_OutputIterator,
6120 __glibcxx_function_requires(_OutputIteratorConcept<_OutputIterator,
6122 __glibcxx_function_requires(_LessThanOpConcept<_ValueType1, _ValueType2>)
6123 __glibcxx_function_requires(_LessThanOpConcept<_ValueType2, _ValueType1>)
6124 __glibcxx_requires_sorted_set(__first1, __last1, __first2);
6125 __glibcxx_requires_sorted_set(__first2, __last2, __first1);
6127 while (__first1 != __last1 && __first2 != __last2)
6128 if (*__first1 < *__first2)
6130 *__result = *__first1;
6134 else if (*__first2 < *__first1)
6136 *__result = *__first2;
6145 return std::copy(__first2, __last2, std::copy(__first1,
6146 __last1, __result));
6169 template<
typename _InputIterator1,
typename _InputIterator2,
6170 typename _OutputIterator,
typename _Compare>
6172 set_symmetric_difference(_InputIterator1 __first1, _InputIterator1 __last1,
6173 _InputIterator2 __first2, _InputIterator2 __last2,
6174 _OutputIterator __result,
6177 typedef typename iterator_traits<_InputIterator1>::value_type
6179 typedef typename iterator_traits<_InputIterator2>::value_type
6183 __glibcxx_function_requires(_InputIteratorConcept<_InputIterator1>)
6184 __glibcxx_function_requires(_InputIteratorConcept<_InputIterator2>)
6185 __glibcxx_function_requires(_OutputIteratorConcept<_OutputIterator,
6187 __glibcxx_function_requires(_OutputIteratorConcept<_OutputIterator,
6189 __glibcxx_function_requires(_BinaryPredicateConcept<_Compare,
6190 _ValueType1, _ValueType2>)
6191 __glibcxx_function_requires(_BinaryPredicateConcept<_Compare,
6192 _ValueType2, _ValueType1>)
6193 __glibcxx_requires_sorted_set_pred(__first1, __last1, __first2, __comp);
6194 __glibcxx_requires_sorted_set_pred(__first2, __last2, __first1, __comp);
6196 while (__first1 != __last1 && __first2 != __last2)
6197 if (__comp(*__first1, *__first2))
6199 *__result = *__first1;
6203 else if (__comp(*__first2, *__first1))
6205 *__result = *__first2;
6214 return std::copy(__first2, __last2,
6215 std::copy(__first1, __last1, __result));
6226 template<
typename _ForwardIterator>
6228 min_element(_ForwardIterator __first, _ForwardIterator __last)
6231 __glibcxx_function_requires(_ForwardIteratorConcept<_ForwardIterator>)
6232 __glibcxx_function_requires(_LessThanComparableConcept<
6233 typename iterator_traits<_ForwardIterator>::value_type>)
6234 __glibcxx_requires_valid_range(__first, __last);
6236 if (__first == __last)
6238 _ForwardIterator __result = __first;
6239 while (++__first != __last)
6240 if (*__first < *__result)
6254 template<
typename _ForwardIterator,
typename _Compare>
6256 min_element(_ForwardIterator __first, _ForwardIterator __last,
6260 __glibcxx_function_requires(_ForwardIteratorConcept<_ForwardIterator>)
6261 __glibcxx_function_requires(_BinaryPredicateConcept<_Compare,
6262 typename iterator_traits<_ForwardIterator>::value_type,
6263 typename iterator_traits<_ForwardIterator>::value_type>)
6264 __glibcxx_requires_valid_range(__first, __last);
6266 if (__first == __last)
6268 _ForwardIterator __result = __first;
6269 while (++__first != __last)
6270 if (__comp(*__first, *__result))
6282 template<
typename _ForwardIterator>
6284 max_element(_ForwardIterator __first, _ForwardIterator __last)
6287 __glibcxx_function_requires(_ForwardIteratorConcept<_ForwardIterator>)
6288 __glibcxx_function_requires(_LessThanComparableConcept<
6289 typename iterator_traits<_ForwardIterator>::value_type>)
6290 __glibcxx_requires_valid_range(__first, __last);
6292 if (__first == __last)
6294 _ForwardIterator __result = __first;
6295 while (++__first != __last)
6296 if (*__result < *__first)
6310 template<
typename _ForwardIterator,
typename _Compare>
6312 max_element(_ForwardIterator __first, _ForwardIterator __last,
6316 __glibcxx_function_requires(_ForwardIteratorConcept<_ForwardIterator>)
6317 __glibcxx_function_requires(_BinaryPredicateConcept<_Compare,
6318 typename iterator_traits<_ForwardIterator>::value_type,
6319 typename iterator_traits<_ForwardIterator>::value_type>)
6320 __glibcxx_requires_valid_range(__first, __last);
6322 if (__first == __last)
return __first;
6323 _ForwardIterator __result = __first;
6324 while (++__first != __last)
6325 if (__comp(*__result, *__first))
6330 _GLIBCXX_END_NAMESPACE_ALGO
bool none_of(_InputIterator __first, _InputIterator __last, _Predicate __pred)
Checks that a predicate is false for all the elements of a sequence.
iterator begin()
As per Table mumble.
_ForwardIterator lower_bound(_ForwardIterator __first, _ForwardIterator __last, const _Tp &__val)
Finds the first position in which val could be inserted without changing the ordering.
_ForwardIterator adjacent_find(_ForwardIterator __first, _ForwardIterator __last, _BinaryPredicate __binary_pred)
Find two adjacent values in a sequence using a predicate.
_ForwardIterator2 swap_ranges(_ForwardIterator1 __first1, _ForwardIterator1 __last1, _ForwardIterator2 __first2)
Swap the elements of two sequences.
_RandomAccessIterator __unguarded_partition_pivot(_RandomAccessIterator __first, _RandomAccessIterator __last)
This is a helper function...
const _Tp & max(const _Tp &, const _Tp &)
This does what you think it does.
void __introsort_loop(_RandomAccessIterator __first, _RandomAccessIterator __last, _Size __depth_limit)
This is a helper function for the sort routine.
void __merge_adaptive(_BidirectionalIterator __first, _BidirectionalIterator __middle, _BidirectionalIterator __last, _Distance __len1, _Distance __len2, _Pointer __buffer, _Distance __buffer_size)
This is a helper function for the merge routines.
iterator_traits< _InputIterator >::difference_type distance(_InputIterator __first, _InputIterator __last)
A generalization of pointer arithmetic.
Marking output iterators.
pair< _ForwardIterator, _ForwardIterator > minmax_element(_ForwardIterator __first, _ForwardIterator __last, _Compare __comp)
Return a pair of iterators pointing to the minimum and maximum elements in a range.
_ForwardIterator __partition(_ForwardIterator __first, _ForwardIterator __last, _Predicate __pred, forward_iterator_tag)
This is a helper function...
void make_heap(_RandomAccessIterator __first, _RandomAccessIterator __last, _Compare __comp)
Construct a heap over a range using comparison functor.
void rotate(_ForwardIterator __first, _ForwardIterator __middle, _ForwardIterator __last)
Rotate the elements of a sequence.
Random-access iterators support a superset of bidirectional iterator operations.
void __move_median_to_first(_Iterator __result, _Iterator __a, _Iterator __b, _Iterator __c)
Swaps the median value of *__a, *__b and *__c to *__result.
_OutputIterator __move_merge(_InputIterator1 __first1, _InputIterator1 __last1, _InputIterator2 __first2, _InputIterator2 __last2, _OutputIterator __result)
This is a helper function for the __merge_sort_loop routines.
_RandomAccessIterator __unguarded_partition(_RandomAccessIterator __first, _RandomAccessIterator __last, const _Tp &__pivot)
This is a helper function...
void __move_merge_adaptive(_InputIterator1 __first1, _InputIterator1 __last1, _InputIterator2 __first2, _InputIterator2 __last2, _OutputIterator __result)
This is a helper function for the __merge_adaptive routines.
constexpr pair< typename __decay_and_strip< _T1 >::__type, typename __decay_and_strip< _T2 >::__type > make_pair(_T1 &&__x, _T2 &&__y)
A convenience wrapper for creating a pair from two objects.
_OutputIterator __unique_copy(_ForwardIterator __first, _ForwardIterator __last, _OutputIterator __result, forward_iterator_tag, output_iterator_tag)
void __insertion_sort(_RandomAccessIterator __first, _RandomAccessIterator __last)
This is a helper function for the sort routine.
void __unguarded_linear_insert(_RandomAccessIterator __last)
This is a helper function for the sort routine.
void advance(_InputIterator &__i, _Distance __n)
A generalization of pointer arithmetic.
ISO C++ entities toplevel namespace is std.
constexpr int __lg(int __n)
This is a helper function for the sort routines and for random.tcc.
iterator_traits< _Iter >::iterator_category __iterator_category(const _Iter &)
void sort_heap(_RandomAccessIterator __first, _RandomAccessIterator __last, _Compare __comp)
Sort a heap using comparison functor.
_EuclideanRingElement __gcd(_EuclideanRingElement __m, _EuclideanRingElement __n)
_ForwardIterator __inplace_stable_partition(_ForwardIterator __first, _Predicate __pred, _Distance __len)
This is a helper function... Requires __len != 0 and !__pred(*__first), same as __stable_partition_ad...
_InputIterator __find_if_not(_InputIterator __first, _InputIterator __last, _Predicate __pred, input_iterator_tag)
This is an overload used by find_if_not() for the Input Iterator case.
_BidirectionalIterator1 __rotate_adaptive(_BidirectionalIterator1 __first, _BidirectionalIterator1 __middle, _BidirectionalIterator1 __last, _Distance __len1, _Distance __len2, _BidirectionalIterator2 __buffer, _Distance __buffer_size)
This is a helper function for the merge routines.
void __reverse(_BidirectionalIterator __first, _BidirectionalIterator __last, bidirectional_iterator_tag)
_InputIterator __find(_InputIterator __first, _InputIterator __last, const _Tp &__val, input_iterator_tag)
This is an overload used by find() for the Input Iterator case.
void partial_sort(_RandomAccessIterator __first, _RandomAccessIterator __middle, _RandomAccessIterator __last, _Compare __comp)
Sort the smallest elements of a sequence using a predicate for comparison.
void __move_merge_adaptive_backward(_BidirectionalIterator1 __first1, _BidirectionalIterator1 __last1, _BidirectionalIterator2 __first2, _BidirectionalIterator2 __last2, _BidirectionalIterator3 __result)
This is a helper function for the __merge_adaptive routines.
_InputIterator find_if(_InputIterator __first, _InputIterator __last, _Predicate __pred)
Find the first element in a sequence for which a predicate is true.
pair< const _Tp &, const _Tp & > minmax(const _Tp &, const _Tp &)
Determines min and max at once as an ordered pair.
void __final_insertion_sort(_RandomAccessIterator __first, _RandomAccessIterator __last)
This is a helper function for the sort routine.
_InputIterator __find_if(_InputIterator __first, _InputIterator __last, _Predicate __pred, input_iterator_tag)
This is an overload used by find_if() for the Input Iterator case.
Forward iterators support a superset of input iterator operations.
size_type size() const
As per Table mumble.
void reverse(_BidirectionalIterator __first, _BidirectionalIterator __last)
Reverse a sequence.
_ForwardIterator upper_bound(_ForwardIterator __first, _ForwardIterator __last, const _Tp &__val, _Compare __comp)
Finds the last position in which __val could be inserted without changing the ordering.
_ForwardIterator1 search(_ForwardIterator1 __first1, _ForwardIterator1 __last1, _ForwardIterator2 __first2, _ForwardIterator2 __last2, _BinaryPredicate __predicate)
Search a sequence for a matching sub-sequence using a predicate.
_ForwardIterator __stable_partition_adaptive(_ForwardIterator __first, _ForwardIterator __last, _Predicate __pred, _Distance __len, _Pointer __buffer, _Distance __buffer_size)
This is a helper function... Requires __first != __last and !__pred(*__first) and __len == distance(_...
void __rotate(_ForwardIterator __first, _ForwardIterator __middle, _ForwardIterator __last, forward_iterator_tag)
This is a helper function for the rotate algorithm.
void __heap_select(_RandomAccessIterator __first, _RandomAccessIterator __middle, _RandomAccessIterator __last)
This is a helper function for the sort routines.
void swap(_Tp &, _Tp &) noexcept(__and_< is_nothrow_move_constructible< _Tp >, is_nothrow_move_assignable< _Tp >>::value)
Swaps two values.
void __merge_without_buffer(_BidirectionalIterator __first, _BidirectionalIterator __middle, _BidirectionalIterator __last, _Distance __len1, _Distance __len2)
This is a helper function for the merge routines.
iterator_traits< _InputIterator >::difference_type count_if(_InputIterator __first, _InputIterator __last, _Predicate __pred)
Count the elements of a sequence for which a predicate is true.
void __unguarded_insertion_sort(_RandomAccessIterator __first, _RandomAccessIterator __last)
This is a helper function for the sort routine.
iterator_traits< _InputIterator >::difference_type count(_InputIterator __first, _InputIterator __last, const _Tp &__value)
Count the number of copies of a value in a sequence.
_InputIterator __find_if_not_n(_InputIterator __first, _Distance &__len, _Predicate __pred)
Like find_if_not(), but uses and updates a count of the remaining range length instead of comparing a...
_ForwardIterator __search_n(_ForwardIterator __first, _ForwardIterator __last, _Integer __count, const _Tp &__val, std::forward_iterator_tag)
Struct holding two objects of arbitrary type.
void __inplace_stable_sort(_RandomAccessIterator __first, _RandomAccessIterator __last)
This is a helper function for the stable sorting routines.
void iter_swap(_ForwardIterator1 __a, _ForwardIterator2 __b)
Swaps the contents of two iterators.
_ForwardIterator is_sorted_until(_ForwardIterator __first, _ForwardIterator __last, _Compare __comp)
Determines the end of a sorted sequence using comparison functor.
const _Tp & min(const _Tp &, const _Tp &)
This does what you think it does.
_ForwardIterator min_element(_ForwardIterator __first, _ForwardIterator __last, _Compare __comp)
Return the minimum element in a range using comparison functor.
Uniform discrete distribution for random numbers. A discrete random distribution on the range with e...
_InputIterator find_if_not(_InputIterator __first, _InputIterator __last, _Predicate __pred)
Find the first element in a sequence for which a predicate is false.
_InputIterator find(_InputIterator __first, _InputIterator __last, const _Tp &__val)
Find the first occurrence of a value in a sequence.
_ForwardIterator max_element(_ForwardIterator __first, _ForwardIterator __last, _Compare __comp)
Return the maximum element in a range using comparison functor.
Bidirectional iterators support a superset of forward iterator operations.
size_type requested_size() const
Returns the size requested by the constructor; may be >size().