65 #if __cplusplus >= 201103L 71 namespace std _GLIBCXX_VISIBILITY(default)
73 _GLIBCXX_BEGIN_NAMESPACE_VERSION
76 template<
typename _Iterator,
typename _Compare>
79 _Iterator __c, _Compare __comp)
85 else if (__comp(__a, __c))
90 else if (__comp(__a, __c))
92 else if (__comp(__b, __c))
99 template<
typename _InputIterator,
typename _Predicate>
100 inline _InputIterator
101 __find_if(_InputIterator __first, _InputIterator __last,
104 while (__first != __last && !__pred(__first))
110 template<
typename _RandomAccessIterator,
typename _Predicate>
111 _RandomAccessIterator
112 __find_if(_RandomAccessIterator __first, _RandomAccessIterator __last,
115 typename iterator_traits<_RandomAccessIterator>::difference_type
116 __trip_count = (__last - __first) >> 2;
118 for (; __trip_count > 0; --__trip_count)
137 switch (__last - __first)
157 template<
typename _Iterator,
typename _Predicate>
159 __find_if(_Iterator __first, _Iterator __last, _Predicate __pred)
161 return __find_if(__first, __last, __pred,
166 template<
typename _InputIterator,
typename _Predicate>
167 inline _InputIterator
172 __gnu_cxx::__ops::__negate(__pred),
179 template<
typename _InputIterator,
typename _Predicate,
typename _Distance>
183 for (; __len; --__len, (void) ++__first)
184 if (!__pred(__first))
202 template<
typename _ForwardIterator1,
typename _ForwardIterator2,
203 typename _BinaryPredicate>
205 __search(_ForwardIterator1 __first1, _ForwardIterator1 __last1,
206 _ForwardIterator2 __first2, _ForwardIterator2 __last2,
207 _BinaryPredicate __predicate)
210 if (__first1 == __last1 || __first2 == __last2)
214 _ForwardIterator2 __p1(__first2);
215 if (++__p1 == __last2)
217 __gnu_cxx::__ops::__iter_comp_iter(__predicate, __first2));
220 _ForwardIterator2 __p;
221 _ForwardIterator1 __current = __first1;
227 __gnu_cxx::__ops::__iter_comp_iter(__predicate, __first2));
229 if (__first1 == __last1)
233 __current = __first1;
234 if (++__current == __last1)
237 while (__predicate(__current, __p))
239 if (++__p == __last2)
241 if (++__current == __last1)
254 template<
typename _ForwardIterator,
typename _Integer,
255 typename _UnaryPredicate>
258 _Integer __count, _UnaryPredicate __unary_pred,
262 while (__first != __last)
264 typename iterator_traits<_ForwardIterator>::difference_type
266 _ForwardIterator __i = __first;
268 while (__i != __last && __n != 1 && __unary_pred(__i))
286 template<
typename _RandomAccessIter,
typename _Integer,
287 typename _UnaryPredicate>
290 _Integer __count, _UnaryPredicate __unary_pred,
293 typedef typename std::iterator_traits<_RandomAccessIter>::difference_type
296 _DistanceType __tailSize = __last - __first;
297 _DistanceType __remainder = __count;
299 while (__remainder <= __tailSize)
301 __first += __remainder;
302 __tailSize -= __remainder;
305 _RandomAccessIter __backTrack = __first;
306 while (__unary_pred(--__backTrack))
308 if (--__remainder == 0)
309 return (__first - __count);
311 __remainder = __count + 1 - (__first - __backTrack);
316 template<
typename _ForwardIterator,
typename _Integer,
317 typename _UnaryPredicate>
319 __search_n(_ForwardIterator __first, _ForwardIterator __last,
321 _UnaryPredicate __unary_pred)
334 template<
typename _ForwardIterator1,
typename _ForwardIterator2,
335 typename _BinaryPredicate>
337 __find_end(_ForwardIterator1 __first1, _ForwardIterator1 __last1,
338 _ForwardIterator2 __first2, _ForwardIterator2 __last2,
339 forward_iterator_tag, forward_iterator_tag,
340 _BinaryPredicate __comp)
342 if (__first2 == __last2)
345 _ForwardIterator1 __result = __last1;
348 _ForwardIterator1 __new_result
349 = std::__search(__first1, __last1, __first2, __last2, __comp);
350 if (__new_result == __last1)
354 __result = __new_result;
355 __first1 = __new_result;
362 template<
typename _BidirectionalIterator1,
typename _BidirectionalIterator2,
363 typename _BinaryPredicate>
364 _BidirectionalIterator1
365 __find_end(_BidirectionalIterator1 __first1,
366 _BidirectionalIterator1 __last1,
367 _BidirectionalIterator2 __first2,
368 _BidirectionalIterator2 __last2,
369 bidirectional_iterator_tag, bidirectional_iterator_tag,
370 _BinaryPredicate __comp)
373 __glibcxx_function_requires(_BidirectionalIteratorConcept<
374 _BidirectionalIterator1>)
375 __glibcxx_function_requires(_BidirectionalIteratorConcept<
376 _BidirectionalIterator2>)
378 typedef reverse_iterator<_BidirectionalIterator1> _RevIterator1;
379 typedef reverse_iterator<_BidirectionalIterator2> _RevIterator2;
381 _RevIterator1 __rlast1(__first1);
382 _RevIterator2 __rlast2(__first2);
383 _RevIterator1 __rresult =
std::__search(_RevIterator1(__last1), __rlast1,
384 _RevIterator2(__last2), __rlast2,
387 if (__rresult == __rlast1)
391 _BidirectionalIterator1 __result = __rresult.base();
423 template<
typename _ForwardIterator1,
typename _ForwardIterator2>
424 inline _ForwardIterator1
425 find_end(_ForwardIterator1 __first1, _ForwardIterator1 __last1,
426 _ForwardIterator2 __first2, _ForwardIterator2 __last2)
429 __glibcxx_function_requires(_ForwardIteratorConcept<_ForwardIterator1>)
430 __glibcxx_function_requires(_ForwardIteratorConcept<_ForwardIterator2>)
431 __glibcxx_function_requires(_EqualOpConcept<
432 typename iterator_traits<_ForwardIterator1>::value_type,
433 typename iterator_traits<_ForwardIterator2>::value_type>)
434 __glibcxx_requires_valid_range(__first1, __last1);
435 __glibcxx_requires_valid_range(__first2, __last2);
437 return std::__find_end(__first1, __last1, __first2, __last2,
440 __gnu_cxx::__ops::__iter_equal_to_iter());
471 template<
typename _ForwardIterator1,
typename _ForwardIterator2,
472 typename _BinaryPredicate>
473 inline _ForwardIterator1
474 find_end(_ForwardIterator1 __first1, _ForwardIterator1 __last1,
475 _ForwardIterator2 __first2, _ForwardIterator2 __last2,
476 _BinaryPredicate __comp)
479 __glibcxx_function_requires(_ForwardIteratorConcept<_ForwardIterator1>)
480 __glibcxx_function_requires(_ForwardIteratorConcept<_ForwardIterator2>)
481 __glibcxx_function_requires(_BinaryPredicateConcept<_BinaryPredicate,
482 typename iterator_traits<_ForwardIterator1>::value_type,
483 typename iterator_traits<_ForwardIterator2>::value_type>)
484 __glibcxx_requires_valid_range(__first1, __last1);
485 __glibcxx_requires_valid_range(__first2, __last2);
487 return std::__find_end(__first1, __last1, __first2, __last2,
490 __gnu_cxx::__ops::__iter_comp_iter(__comp));
493 #if __cplusplus >= 201103L 506 template<
typename _InputIterator,
typename _Predicate>
508 all_of(_InputIterator __first, _InputIterator __last, _Predicate __pred)
523 template<
typename _InputIterator,
typename _Predicate>
525 none_of(_InputIterator __first, _InputIterator __last, _Predicate __pred)
541 template<
typename _InputIterator,
typename _Predicate>
543 any_of(_InputIterator __first, _InputIterator __last, _Predicate __pred)
556 template<
typename _InputIterator,
typename _Predicate>
557 inline _InputIterator
558 find_if_not(_InputIterator __first, _InputIterator __last,
562 __glibcxx_function_requires(_InputIteratorConcept<_InputIterator>)
563 __glibcxx_function_requires(_UnaryPredicateConcept<_Predicate,
564 typename iterator_traits<_InputIterator>::value_type>)
565 __glibcxx_requires_valid_range(__first, __last);
567 __gnu_cxx::__ops::__pred_iter(__pred));
580 template<
typename _InputIterator,
typename _Predicate>
582 is_partitioned(_InputIterator __first, _InputIterator __last,
586 if (__first == __last)
601 template<
typename _ForwardIterator,
typename _Predicate>
603 partition_point(_ForwardIterator __first, _ForwardIterator __last,
607 __glibcxx_function_requires(_ForwardIteratorConcept<_ForwardIterator>)
608 __glibcxx_function_requires(_UnaryPredicateConcept<_Predicate,
609 typename iterator_traits<_ForwardIterator>::value_type>)
612 __glibcxx_requires_valid_range(__first, __last);
614 typedef typename iterator_traits<_ForwardIterator>::difference_type
618 _DistanceType __half;
619 _ForwardIterator __middle;
626 if (__pred(*__middle))
630 __len = __len - __half - 1;
639 template<
typename _InputIterator,
typename _OutputIterator,
642 __remove_copy_if(_InputIterator __first, _InputIterator __last,
643 _OutputIterator __result, _Predicate __pred)
645 for (; __first != __last; ++__first)
646 if (!__pred(__first))
648 *__result = *__first;
668 template<
typename _InputIterator,
typename _OutputIterator,
typename _Tp>
669 inline _OutputIterator
670 remove_copy(_InputIterator __first, _InputIterator __last,
671 _OutputIterator __result,
const _Tp& __value)
674 __glibcxx_function_requires(_InputIteratorConcept<_InputIterator>)
675 __glibcxx_function_requires(_OutputIteratorConcept<_OutputIterator,
676 typename iterator_traits<_InputIterator>::value_type>)
677 __glibcxx_function_requires(_EqualOpConcept<
678 typename iterator_traits<_InputIterator>::value_type, _Tp>)
679 __glibcxx_requires_valid_range(__first, __last);
681 return std::__remove_copy_if(__first, __last, __result,
682 __gnu_cxx::__ops::__iter_equals_val(__value));
700 template<
typename _InputIterator,
typename _OutputIterator,
702 inline _OutputIterator
703 remove_copy_if(_InputIterator __first, _InputIterator __last,
704 _OutputIterator __result, _Predicate __pred)
707 __glibcxx_function_requires(_InputIteratorConcept<_InputIterator>)
708 __glibcxx_function_requires(_OutputIteratorConcept<_OutputIterator,
709 typename iterator_traits<_InputIterator>::value_type>)
710 __glibcxx_function_requires(_UnaryPredicateConcept<_Predicate,
711 typename iterator_traits<_InputIterator>::value_type>)
712 __glibcxx_requires_valid_range(__first, __last);
714 return std::__remove_copy_if(__first, __last, __result,
715 __gnu_cxx::__ops::__pred_iter(__pred));
718 #if __cplusplus >= 201103L 734 template<
typename _InputIterator,
typename _OutputIterator,
737 copy_if(_InputIterator __first, _InputIterator __last,
738 _OutputIterator __result, _Predicate __pred)
741 __glibcxx_function_requires(_InputIteratorConcept<_InputIterator>)
742 __glibcxx_function_requires(_OutputIteratorConcept<_OutputIterator,
743 typename iterator_traits<_InputIterator>::value_type>)
744 __glibcxx_function_requires(_UnaryPredicateConcept<_Predicate,
745 typename iterator_traits<_InputIterator>::value_type>)
746 __glibcxx_requires_valid_range(__first, __last);
748 for (; __first != __last; ++__first)
749 if (__pred(*__first))
751 *__result = *__first;
757 template<
typename _InputIterator,
typename _Size,
typename _OutputIterator>
759 __copy_n(_InputIterator __first, _Size __n,
760 _OutputIterator __result, input_iterator_tag)
766 *__result = *__first;
777 template<
typename _RandomAccessIterator,
typename _Size,
778 typename _OutputIterator>
779 inline _OutputIterator
780 __copy_n(_RandomAccessIterator __first, _Size __n,
781 _OutputIterator __result, random_access_iterator_tag)
782 {
return std::copy(__first, __first + __n, __result); }
797 template<
typename _InputIterator,
typename _Size,
typename _OutputIterator>
798 inline _OutputIterator
799 copy_n(_InputIterator __first, _Size __n, _OutputIterator __result)
802 __glibcxx_function_requires(_InputIteratorConcept<_InputIterator>)
803 __glibcxx_function_requires(_OutputIteratorConcept<_OutputIterator,
804 typename iterator_traits<_InputIterator>::value_type>)
806 return std::__copy_n(__first, __n, __result,
825 template<
typename _InputIterator,
typename _OutputIterator1,
826 typename _OutputIterator2,
typename _Predicate>
827 pair<_OutputIterator1, _OutputIterator2>
828 partition_copy(_InputIterator __first, _InputIterator __last,
829 _OutputIterator1 __out_true, _OutputIterator2 __out_false,
833 __glibcxx_function_requires(_InputIteratorConcept<_InputIterator>)
834 __glibcxx_function_requires(_OutputIteratorConcept<_OutputIterator1,
835 typename iterator_traits<_InputIterator>::value_type>)
836 __glibcxx_function_requires(_OutputIteratorConcept<_OutputIterator2,
837 typename iterator_traits<_InputIterator>::value_type>)
838 __glibcxx_function_requires(_UnaryPredicateConcept<_Predicate,
839 typename iterator_traits<_InputIterator>::value_type>)
840 __glibcxx_requires_valid_range(__first, __last);
842 for (; __first != __last; ++__first)
843 if (__pred(*__first))
845 *__out_true = *__first;
850 *__out_false = *__first;
858 template<
typename _ForwardIterator,
typename _Predicate>
860 __remove_if(_ForwardIterator __first, _ForwardIterator __last,
864 if (__first == __last)
866 _ForwardIterator __result = __first;
868 for (; __first != __last; ++__first)
869 if (!__pred(__first))
871 *__result = _GLIBCXX_MOVE(*__first);
894 template<
typename _ForwardIterator,
typename _Tp>
895 inline _ForwardIterator
896 remove(_ForwardIterator __first, _ForwardIterator __last,
900 __glibcxx_function_requires(_Mutable_ForwardIteratorConcept<
902 __glibcxx_function_requires(_EqualOpConcept<
903 typename iterator_traits<_ForwardIterator>::value_type, _Tp>)
904 __glibcxx_requires_valid_range(__first, __last);
906 return std::__remove_if(__first, __last,
907 __gnu_cxx::__ops::__iter_equals_val(__value));
927 template<
typename _ForwardIterator,
typename _Predicate>
928 inline _ForwardIterator
929 remove_if(_ForwardIterator __first, _ForwardIterator __last,
933 __glibcxx_function_requires(_Mutable_ForwardIteratorConcept<
935 __glibcxx_function_requires(_UnaryPredicateConcept<_Predicate,
936 typename iterator_traits<_ForwardIterator>::value_type>)
937 __glibcxx_requires_valid_range(__first, __last);
939 return std::__remove_if(__first, __last,
940 __gnu_cxx::__ops::__pred_iter(__pred));
943 template<
typename _ForwardIterator,
typename _BinaryPredicate>
945 __adjacent_find(_ForwardIterator __first, _ForwardIterator __last,
946 _BinaryPredicate __binary_pred)
948 if (__first == __last)
950 _ForwardIterator __next = __first;
951 while (++__next != __last)
953 if (__binary_pred(__first, __next))
960 template<
typename _ForwardIterator,
typename _BinaryPredicate>
962 __unique(_ForwardIterator __first, _ForwardIterator __last,
963 _BinaryPredicate __binary_pred)
966 __first = std::__adjacent_find(__first, __last, __binary_pred);
967 if (__first == __last)
971 _ForwardIterator __dest = __first;
973 while (++__first != __last)
974 if (!__binary_pred(__dest, __first))
975 *++__dest = _GLIBCXX_MOVE(*__first);
993 template<
typename _ForwardIterator>
994 inline _ForwardIterator
995 unique(_ForwardIterator __first, _ForwardIterator __last)
998 __glibcxx_function_requires(_Mutable_ForwardIteratorConcept<
1000 __glibcxx_function_requires(_EqualityComparableConcept<
1001 typename iterator_traits<_ForwardIterator>::value_type>)
1002 __glibcxx_requires_valid_range(__first, __last);
1004 return std::__unique(__first, __last,
1005 __gnu_cxx::__ops::__iter_equal_to_iter());
1023 template<
typename _ForwardIterator,
typename _BinaryPredicate>
1024 inline _ForwardIterator
1025 unique(_ForwardIterator __first, _ForwardIterator __last,
1026 _BinaryPredicate __binary_pred)
1029 __glibcxx_function_requires(_Mutable_ForwardIteratorConcept<
1031 __glibcxx_function_requires(_BinaryPredicateConcept<_BinaryPredicate,
1032 typename iterator_traits<_ForwardIterator>::value_type,
1033 typename iterator_traits<_ForwardIterator>::value_type>)
1034 __glibcxx_requires_valid_range(__first, __last);
1036 return std::__unique(__first, __last,
1037 __gnu_cxx::__ops::__iter_comp_iter(__binary_pred));
1046 template<
typename _ForwardIterator,
typename _OutputIterator,
1047 typename _BinaryPredicate>
1050 _OutputIterator __result, _BinaryPredicate __binary_pred,
1054 __glibcxx_function_requires(_BinaryPredicateConcept<_BinaryPredicate,
1055 typename iterator_traits<_ForwardIterator>::value_type,
1056 typename iterator_traits<_ForwardIterator>::value_type>)
1058 _ForwardIterator __next = __first;
1059 *__result = *__first;
1060 while (++__next != __last)
1061 if (!__binary_pred(__first, __next))
1064 *++__result = *__first;
1075 template<
typename _InputIterator,
typename _OutputIterator,
1076 typename _BinaryPredicate>
1079 _OutputIterator __result, _BinaryPredicate __binary_pred,
1083 __glibcxx_function_requires(_BinaryPredicateConcept<_BinaryPredicate,
1084 typename iterator_traits<_InputIterator>::value_type,
1085 typename iterator_traits<_InputIterator>::value_type>)
1087 typename iterator_traits<_InputIterator>::value_type __value = *__first;
1088 __decltype(__gnu_cxx::__ops::__iter_comp_val(__binary_pred))
1090 = __gnu_cxx::__ops::__iter_comp_val(__binary_pred);
1091 *__result = __value;
1092 while (++__first != __last)
1093 if (!__rebound_pred(__first, __value))
1096 *++__result = __value;
1107 template<
typename _InputIterator,
typename _ForwardIterator,
1108 typename _BinaryPredicate>
1111 _ForwardIterator __result, _BinaryPredicate __binary_pred,
1115 __glibcxx_function_requires(_BinaryPredicateConcept<_BinaryPredicate,
1116 typename iterator_traits<_ForwardIterator>::value_type,
1117 typename iterator_traits<_InputIterator>::value_type>)
1118 *__result = *__first;
1119 while (++__first != __last)
1120 if (!__binary_pred(__result, __first))
1121 *++__result = *__first;
1130 template<
typename _B
idirectionalIterator>
1132 __reverse(_BidirectionalIterator __first, _BidirectionalIterator __last,
1136 if (__first == __last || __first == --__last)
1150 template<
typename _RandomAccessIterator>
1152 __reverse(_RandomAccessIterator __first, _RandomAccessIterator __last,
1155 if (__first == __last)
1158 while (__first < __last)
1178 template<
typename _B
idirectionalIterator>
1180 reverse(_BidirectionalIterator __first, _BidirectionalIterator __last)
1183 __glibcxx_function_requires(_Mutable_BidirectionalIteratorConcept<
1184 _BidirectionalIterator>)
1185 __glibcxx_requires_valid_range(__first, __last);
1205 template<
typename _B
idirectionalIterator,
typename _OutputIterator>
1207 reverse_copy(_BidirectionalIterator __first, _BidirectionalIterator __last,
1208 _OutputIterator __result)
1211 __glibcxx_function_requires(_BidirectionalIteratorConcept<
1212 _BidirectionalIterator>)
1213 __glibcxx_function_requires(_OutputIteratorConcept<_OutputIterator,
1214 typename iterator_traits<_BidirectionalIterator>::value_type>)
1215 __glibcxx_requires_valid_range(__first, __last);
1217 while (__first != __last)
1220 *__result = *__last;
1230 template<
typename _Eucl
ideanRingElement>
1231 _EuclideanRingElement
1232 __gcd(_EuclideanRingElement __m, _EuclideanRingElement __n)
1236 _EuclideanRingElement __t = __m % __n;
1243 inline namespace _V2
1247 template<
typename _ForwardIterator>
1250 _ForwardIterator __middle,
1251 _ForwardIterator __last,
1254 if (__first == __middle)
1256 else if (__last == __middle)
1259 _ForwardIterator __first2 = __middle;
1265 if (__first == __middle)
1266 __middle = __first2;
1268 while (__first2 != __last);
1270 _ForwardIterator __ret = __first;
1272 __first2 = __middle;
1274 while (__first2 != __last)
1279 if (__first == __middle)
1280 __middle = __first2;
1281 else if (__first2 == __last)
1282 __first2 = __middle;
1288 template<
typename _B
idirectionalIterator>
1289 _BidirectionalIterator
1291 _BidirectionalIterator __middle,
1292 _BidirectionalIterator __last,
1296 __glibcxx_function_requires(_Mutable_BidirectionalIteratorConcept<
1297 _BidirectionalIterator>)
1299 if (__first == __middle)
1301 else if (__last == __middle)
1307 while (__first != __middle && __middle != __last)
1313 if (__first == __middle)
1326 template<
typename _RandomAccessIterator>
1327 _RandomAccessIterator
1329 _RandomAccessIterator __middle,
1330 _RandomAccessIterator __last,
1334 __glibcxx_function_requires(_Mutable_RandomAccessIteratorConcept<
1335 _RandomAccessIterator>)
1337 if (__first == __middle)
1339 else if (__last == __middle)
1342 typedef typename iterator_traits<_RandomAccessIterator>::difference_type
1344 typedef typename iterator_traits<_RandomAccessIterator>::value_type
1347 _Distance __n = __last - __first;
1348 _Distance __k = __middle - __first;
1350 if (__k == __n - __k)
1356 _RandomAccessIterator __p = __first;
1357 _RandomAccessIterator __ret = __first + (__last - __middle);
1361 if (__k < __n - __k)
1363 if (__is_pod(_ValueType) && __k == 1)
1365 _ValueType __t = _GLIBCXX_MOVE(*__p);
1366 _GLIBCXX_MOVE3(__p + 1, __p + __n, __p);
1367 *(__p + __n - 1) = _GLIBCXX_MOVE(__t);
1370 _RandomAccessIterator __q = __p + __k;
1371 for (_Distance __i = 0; __i < __n - __k; ++ __i)
1380 std::swap(__n, __k);
1386 if (__is_pod(_ValueType) && __k == 1)
1388 _ValueType __t = _GLIBCXX_MOVE(*(__p + __n - 1));
1389 _GLIBCXX_MOVE_BACKWARD3(__p, __p + __n - 1, __p + __n);
1390 *__p = _GLIBCXX_MOVE(__t);
1393 _RandomAccessIterator __q = __p + __n;
1395 for (_Distance __i = 0; __i < __n - __k; ++ __i)
1404 std::swap(__n, __k);
1432 template<
typename _ForwardIterator>
1433 inline _ForwardIterator
1434 rotate(_ForwardIterator __first, _ForwardIterator __middle,
1435 _ForwardIterator __last)
1438 __glibcxx_function_requires(_Mutable_ForwardIteratorConcept<
1440 __glibcxx_requires_valid_range(__first, __middle);
1441 __glibcxx_requires_valid_range(__middle, __last);
1443 return std::__rotate(__first, __middle, __last,
1469 template<
typename _ForwardIterator,
typename _OutputIterator>
1470 inline _OutputIterator
1471 rotate_copy(_ForwardIterator __first, _ForwardIterator __middle,
1472 _ForwardIterator __last, _OutputIterator __result)
1475 __glibcxx_function_requires(_ForwardIteratorConcept<_ForwardIterator>)
1476 __glibcxx_function_requires(_OutputIteratorConcept<_OutputIterator,
1477 typename iterator_traits<_ForwardIterator>::value_type>)
1478 __glibcxx_requires_valid_range(__first, __middle);
1479 __glibcxx_requires_valid_range(__middle, __last);
1481 return std::copy(__first, __middle,
1482 std::copy(__middle, __last, __result));
1486 template<
typename _ForwardIterator,
typename _Predicate>
1491 if (__first == __last)
1494 while (__pred(*__first))
1495 if (++__first == __last)
1498 _ForwardIterator __next = __first;
1500 while (++__next != __last)
1501 if (__pred(*__next))
1511 template<
typename _B
idirectionalIterator,
typename _Predicate>
1512 _BidirectionalIterator
1513 __partition(_BidirectionalIterator __first, _BidirectionalIterator __last,
1519 if (__first == __last)
1521 else if (__pred(*__first))
1527 if (__first == __last)
1529 else if (!
bool(__pred(*__last)))
1546 template<
typename _ForwardIterator,
typename _Pointer,
typename _Predicate,
1550 _ForwardIterator __last,
1551 _Predicate __pred, _Distance __len,
1553 _Distance __buffer_size)
1558 if (__len <= __buffer_size)
1560 _ForwardIterator __result1 = __first;
1561 _Pointer __result2 = __buffer;
1566 *__result2 = _GLIBCXX_MOVE(*__first);
1569 for (; __first != __last; ++__first)
1570 if (__pred(__first))
1572 *__result1 = _GLIBCXX_MOVE(*__first);
1577 *__result2 = _GLIBCXX_MOVE(*__first);
1581 _GLIBCXX_MOVE3(__buffer, __result2, __result1);
1585 _ForwardIterator __middle = __first;
1587 _ForwardIterator __left_split =
1589 __len / 2, __buffer,
1594 _Distance __right_len = __len - __len / 2;
1595 _ForwardIterator __right_split =
1602 __buffer, __buffer_size);
1604 std::rotate(__left_split, __middle, __right_split);
1606 return __left_split;
1609 template<
typename _ForwardIterator,
typename _Predicate>
1611 __stable_partition(_ForwardIterator __first, _ForwardIterator __last,
1616 if (__first == __last)
1619 typedef typename iterator_traits<_ForwardIterator>::value_type
1621 typedef typename iterator_traits<_ForwardIterator>::difference_type
1624 _Temporary_buffer<_ForwardIterator, _ValueType> __buf(__first, __last);
1627 _DistanceType(__buf.requested_size()),
1629 _DistanceType(__buf.size()));
1649 template<
typename _ForwardIterator,
typename _Predicate>
1650 inline _ForwardIterator
1651 stable_partition(_ForwardIterator __first, _ForwardIterator __last,
1655 __glibcxx_function_requires(_Mutable_ForwardIteratorConcept<
1657 __glibcxx_function_requires(_UnaryPredicateConcept<_Predicate,
1658 typename iterator_traits<_ForwardIterator>::value_type>)
1659 __glibcxx_requires_valid_range(__first, __last);
1661 return std::__stable_partition(__first, __last,
1662 __gnu_cxx::__ops::__pred_iter(__pred));
1666 template<
typename _RandomAccessIterator,
typename _Compare>
1669 _RandomAccessIterator __middle,
1670 _RandomAccessIterator __last, _Compare __comp)
1672 std::__make_heap(__first, __middle, __comp);
1673 for (_RandomAccessIterator __i = __middle; __i < __last; ++__i)
1674 if (__comp(__i, __first))
1675 std::__pop_heap(__first, __middle, __i, __comp);
1680 template<
typename _InputIterator,
typename _RandomAccessIterator,
1682 _RandomAccessIterator
1683 __partial_sort_copy(_InputIterator __first, _InputIterator __last,
1684 _RandomAccessIterator __result_first,
1685 _RandomAccessIterator __result_last,
1688 typedef typename iterator_traits<_InputIterator>::value_type
1690 typedef iterator_traits<_RandomAccessIterator> _RItTraits;
1691 typedef typename _RItTraits::difference_type _DistanceType;
1693 if (__result_first == __result_last)
1694 return __result_last;
1695 _RandomAccessIterator __result_real_last = __result_first;
1696 while (__first != __last && __result_real_last != __result_last)
1698 *__result_real_last = *__first;
1699 ++__result_real_last;
1703 std::__make_heap(__result_first, __result_real_last, __comp);
1704 while (__first != __last)
1706 if (__comp(__first, __result_first))
1707 std::__adjust_heap(__result_first, _DistanceType(0),
1708 _DistanceType(__result_real_last
1710 _InputValueType(*__first), __comp);
1713 std::__sort_heap(__result_first, __result_real_last, __comp);
1714 return __result_real_last;
1735 template<
typename _InputIterator,
typename _RandomAccessIterator>
1736 inline _RandomAccessIterator
1737 partial_sort_copy(_InputIterator __first, _InputIterator __last,
1738 _RandomAccessIterator __result_first,
1739 _RandomAccessIterator __result_last)
1741 #ifdef _GLIBCXX_CONCEPT_CHECKS 1742 typedef typename iterator_traits<_InputIterator>::value_type
1744 typedef typename iterator_traits<_RandomAccessIterator>::value_type
1749 __glibcxx_function_requires(_InputIteratorConcept<_InputIterator>)
1750 __glibcxx_function_requires(_ConvertibleConcept<_InputValueType,
1752 __glibcxx_function_requires(_LessThanOpConcept<_InputValueType,
1754 __glibcxx_function_requires(_LessThanComparableConcept<_OutputValueType>)
1755 __glibcxx_requires_valid_range(__first, __last);
1756 __glibcxx_requires_irreflexive(__first, __last);
1757 __glibcxx_requires_valid_range(__result_first, __result_last);
1759 return std::__partial_sort_copy(__first, __last,
1760 __result_first, __result_last,
1761 __gnu_cxx::__ops::__iter_less_iter());
1784 template<
typename _InputIterator,
typename _RandomAccessIterator,
1786 inline _RandomAccessIterator
1787 partial_sort_copy(_InputIterator __first, _InputIterator __last,
1788 _RandomAccessIterator __result_first,
1789 _RandomAccessIterator __result_last,
1792 #ifdef _GLIBCXX_CONCEPT_CHECKS 1793 typedef typename iterator_traits<_InputIterator>::value_type
1795 typedef typename iterator_traits<_RandomAccessIterator>::value_type
1800 __glibcxx_function_requires(_InputIteratorConcept<_InputIterator>)
1801 __glibcxx_function_requires(_Mutable_RandomAccessIteratorConcept<
1802 _RandomAccessIterator>)
1803 __glibcxx_function_requires(_ConvertibleConcept<_InputValueType,
1805 __glibcxx_function_requires(_BinaryPredicateConcept<_Compare,
1806 _InputValueType, _OutputValueType>)
1807 __glibcxx_function_requires(_BinaryPredicateConcept<_Compare,
1808 _OutputValueType, _OutputValueType>)
1809 __glibcxx_requires_valid_range(__first, __last);
1810 __glibcxx_requires_irreflexive_pred(__first, __last, __comp);
1811 __glibcxx_requires_valid_range(__result_first, __result_last);
1813 return std::__partial_sort_copy(__first, __last,
1814 __result_first, __result_last,
1815 __gnu_cxx::__ops::__iter_comp_iter(__comp));
1819 template<
typename _RandomAccessIterator,
typename _Compare>
1824 typename iterator_traits<_RandomAccessIterator>::value_type
1825 __val = _GLIBCXX_MOVE(*__last);
1826 _RandomAccessIterator __next = __last;
1828 while (__comp(__val, __next))
1830 *__last = _GLIBCXX_MOVE(*__next);
1834 *__last = _GLIBCXX_MOVE(__val);
1838 template<
typename _RandomAccessIterator,
typename _Compare>
1841 _RandomAccessIterator __last, _Compare __comp)
1843 if (__first == __last)
return;
1845 for (_RandomAccessIterator __i = __first + 1; __i != __last; ++__i)
1847 if (__comp(__i, __first))
1849 typename iterator_traits<_RandomAccessIterator>::value_type
1850 __val = _GLIBCXX_MOVE(*__i);
1851 _GLIBCXX_MOVE_BACKWARD3(__first, __i, __i + 1);
1852 *__first = _GLIBCXX_MOVE(__val);
1856 __gnu_cxx::__ops::__val_comp_iter(__comp));
1861 template<
typename _RandomAccessIterator,
typename _Compare>
1864 _RandomAccessIterator __last, _Compare __comp)
1866 for (_RandomAccessIterator __i = __first; __i != __last; ++__i)
1868 __gnu_cxx::__ops::__val_comp_iter(__comp));
1875 enum { _S_threshold = 16 };
1878 template<
typename _RandomAccessIterator,
typename _Compare>
1881 _RandomAccessIterator __last, _Compare __comp)
1883 if (__last - __first >
int(_S_threshold))
1894 template<
typename _RandomAccessIterator,
typename _Compare>
1895 _RandomAccessIterator
1897 _RandomAccessIterator __last,
1898 _RandomAccessIterator __pivot, _Compare __comp)
1902 while (__comp(__first, __pivot))
1905 while (__comp(__pivot, __last))
1907 if (!(__first < __last))
1915 template<
typename _RandomAccessIterator,
typename _Compare>
1916 inline _RandomAccessIterator
1918 _RandomAccessIterator __last, _Compare __comp)
1920 _RandomAccessIterator __mid = __first + (__last - __first) / 2;
1926 template<
typename _RandomAccessIterator,
typename _Compare>
1928 __partial_sort(_RandomAccessIterator __first,
1929 _RandomAccessIterator __middle,
1930 _RandomAccessIterator __last,
1934 std::__sort_heap(__first, __middle, __comp);
1938 template<
typename _RandomAccessIterator,
typename _Size,
typename _Compare>
1941 _RandomAccessIterator __last,
1942 _Size __depth_limit, _Compare __comp)
1944 while (__last - __first >
int(_S_threshold))
1946 if (__depth_limit == 0)
1948 std::__partial_sort(__first, __last, __last, __comp);
1952 _RandomAccessIterator __cut =
1961 template<
typename _RandomAccessIterator,
typename _Compare>
1963 __sort(_RandomAccessIterator __first, _RandomAccessIterator __last,
1966 if (__first != __last)
1975 template<
typename _RandomAccessIterator,
typename _Size,
typename _Compare>
1977 __introselect(_RandomAccessIterator __first, _RandomAccessIterator __nth,
1978 _RandomAccessIterator __last, _Size __depth_limit,
1981 while (__last - __first > 3)
1983 if (__depth_limit == 0)
1991 _RandomAccessIterator __cut =
2021 template<
typename _ForwardIterator,
typename _Tp,
typename _Compare>
2022 inline _ForwardIterator
2023 lower_bound(_ForwardIterator __first, _ForwardIterator __last,
2024 const _Tp& __val, _Compare __comp)
2027 __glibcxx_function_requires(_ForwardIteratorConcept<_ForwardIterator>)
2028 __glibcxx_function_requires(_BinaryPredicateConcept<_Compare,
2029 typename iterator_traits<_ForwardIterator>::value_type, _Tp>)
2030 __glibcxx_requires_partitioned_lower_pred(__first, __last,
2033 return std::__lower_bound(__first, __last, __val,
2034 __gnu_cxx::__ops::__iter_comp_val(__comp));
2037 template<
typename _ForwardIterator,
typename _Tp,
typename _Compare>
2039 __upper_bound(_ForwardIterator __first, _ForwardIterator __last,
2040 const _Tp& __val, _Compare __comp)
2042 typedef typename iterator_traits<_ForwardIterator>::difference_type
2049 _DistanceType __half = __len >> 1;
2050 _ForwardIterator __middle = __first;
2052 if (__comp(__val, __middle))
2058 __len = __len - __half - 1;
2075 template<
typename _ForwardIterator,
typename _Tp>
2076 inline _ForwardIterator
2077 upper_bound(_ForwardIterator __first, _ForwardIterator __last,
2081 __glibcxx_function_requires(_ForwardIteratorConcept<_ForwardIterator>)
2082 __glibcxx_function_requires(_LessThanOpConcept<
2083 _Tp,
typename iterator_traits<_ForwardIterator>::value_type>)
2084 __glibcxx_requires_partitioned_upper(__first, __last, __val);
2086 return std::__upper_bound(__first, __last, __val,
2087 __gnu_cxx::__ops::__val_less_iter());
2105 template<
typename _ForwardIterator,
typename _Tp,
typename _Compare>
2106 inline _ForwardIterator
2107 upper_bound(_ForwardIterator __first, _ForwardIterator __last,
2108 const _Tp& __val, _Compare __comp)
2111 __glibcxx_function_requires(_ForwardIteratorConcept<_ForwardIterator>)
2112 __glibcxx_function_requires(_BinaryPredicateConcept<_Compare,
2113 _Tp,
typename iterator_traits<_ForwardIterator>::value_type>)
2114 __glibcxx_requires_partitioned_upper_pred(__first, __last,
2117 return std::__upper_bound(__first, __last, __val,
2118 __gnu_cxx::__ops::__val_comp_iter(__comp));
2121 template<
typename _ForwardIterator,
typename _Tp,
2122 typename _CompareItTp,
typename _CompareTpIt>
2123 pair<_ForwardIterator, _ForwardIterator>
2124 __equal_range(_ForwardIterator __first, _ForwardIterator __last,
2126 _CompareItTp __comp_it_val, _CompareTpIt __comp_val_it)
2128 typedef typename iterator_traits<_ForwardIterator>::difference_type
2135 _DistanceType __half = __len >> 1;
2136 _ForwardIterator __middle = __first;
2138 if (__comp_it_val(__middle, __val))
2142 __len = __len - __half - 1;
2144 else if (__comp_val_it(__val, __middle))
2148 _ForwardIterator __left
2149 = std::__lower_bound(__first, __middle, __val, __comp_it_val);
2151 _ForwardIterator __right
2152 = std::__upper_bound(++__middle, __first, __val, __comp_val_it);
2153 return pair<_ForwardIterator, _ForwardIterator>(__left, __right);
2156 return pair<_ForwardIterator, _ForwardIterator>(__first, __first);
2176 template<
typename _ForwardIterator,
typename _Tp>
2177 inline pair<_ForwardIterator, _ForwardIterator>
2178 equal_range(_ForwardIterator __first, _ForwardIterator __last,
2182 __glibcxx_function_requires(_ForwardIteratorConcept<_ForwardIterator>)
2183 __glibcxx_function_requires(_LessThanOpConcept<
2184 typename iterator_traits<_ForwardIterator>::value_type, _Tp>)
2185 __glibcxx_function_requires(_LessThanOpConcept<
2186 _Tp,
typename iterator_traits<_ForwardIterator>::value_type>)
2187 __glibcxx_requires_partitioned_lower(__first, __last, __val);
2188 __glibcxx_requires_partitioned_upper(__first, __last, __val);
2190 return std::__equal_range(__first, __last, __val,
2191 __gnu_cxx::__ops::__iter_less_val(),
2192 __gnu_cxx::__ops::__val_less_iter());
2212 template<
typename _ForwardIterator,
typename _Tp,
typename _Compare>
2213 inline pair<_ForwardIterator, _ForwardIterator>
2214 equal_range(_ForwardIterator __first, _ForwardIterator __last,
2215 const _Tp& __val, _Compare __comp)
2218 __glibcxx_function_requires(_ForwardIteratorConcept<_ForwardIterator>)
2219 __glibcxx_function_requires(_BinaryPredicateConcept<_Compare,
2220 typename iterator_traits<_ForwardIterator>::value_type, _Tp>)
2221 __glibcxx_function_requires(_BinaryPredicateConcept<_Compare,
2222 _Tp,
typename iterator_traits<_ForwardIterator>::value_type>)
2223 __glibcxx_requires_partitioned_lower_pred(__first, __last,
2225 __glibcxx_requires_partitioned_upper_pred(__first, __last,
2228 return std::__equal_range(__first, __last, __val,
2229 __gnu_cxx::__ops::__iter_comp_val(__comp),
2230 __gnu_cxx::__ops::__val_comp_iter(__comp));
2245 template<
typename _ForwardIterator,
typename _Tp>
2247 binary_search(_ForwardIterator __first, _ForwardIterator __last,
2251 __glibcxx_function_requires(_ForwardIteratorConcept<_ForwardIterator>)
2252 __glibcxx_function_requires(_LessThanOpConcept<
2253 _Tp,
typename iterator_traits<_ForwardIterator>::value_type>)
2254 __glibcxx_requires_partitioned_lower(__first, __last, __val);
2255 __glibcxx_requires_partitioned_upper(__first, __last, __val);
2257 _ForwardIterator __i
2258 = std::__lower_bound(__first, __last, __val,
2259 __gnu_cxx::__ops::__iter_less_val());
2260 return __i != __last && !(__val < *__i);
2278 template<
typename _ForwardIterator,
typename _Tp,
typename _Compare>
2280 binary_search(_ForwardIterator __first, _ForwardIterator __last,
2281 const _Tp& __val, _Compare __comp)
2284 __glibcxx_function_requires(_ForwardIteratorConcept<_ForwardIterator>)
2285 __glibcxx_function_requires(_BinaryPredicateConcept<_Compare,
2286 _Tp,
typename iterator_traits<_ForwardIterator>::value_type>)
2287 __glibcxx_requires_partitioned_lower_pred(__first, __last,
2289 __glibcxx_requires_partitioned_upper_pred(__first, __last,
2292 _ForwardIterator __i
2293 = std::__lower_bound(__first, __last, __val,
2294 __gnu_cxx::__ops::__iter_comp_val(__comp));
2295 return __i != __last && !bool(__comp(__val, *__i));
2301 template<
typename _InputIterator1,
typename _InputIterator2,
2302 typename _OutputIterator,
typename _Compare>
2305 _InputIterator2 __first2, _InputIterator2 __last2,
2306 _OutputIterator __result, _Compare __comp)
2308 while (__first1 != __last1 && __first2 != __last2)
2310 if (__comp(__first2, __first1))
2312 *__result = _GLIBCXX_MOVE(*__first2);
2317 *__result = _GLIBCXX_MOVE(*__first1);
2322 if (__first1 != __last1)
2323 _GLIBCXX_MOVE3(__first1, __last1, __result);
2327 template<
typename _BidirectionalIterator1,
typename _BidirectionalIterator2,
2328 typename _BidirectionalIterator3,
typename _Compare>
2331 _BidirectionalIterator1 __last1,
2332 _BidirectionalIterator2 __first2,
2333 _BidirectionalIterator2 __last2,
2334 _BidirectionalIterator3 __result,
2337 if (__first1 == __last1)
2339 _GLIBCXX_MOVE_BACKWARD3(__first2, __last2, __result);
2342 else if (__first2 == __last2)
2349 if (__comp(__last2, __last1))
2351 *--__result = _GLIBCXX_MOVE(*__last1);
2352 if (__first1 == __last1)
2354 _GLIBCXX_MOVE_BACKWARD3(__first2, ++__last2, __result);
2361 *--__result = _GLIBCXX_MOVE(*__last2);
2362 if (__first2 == __last2)
2370 template<
typename _BidirectionalIterator1,
typename _BidirectionalIterator2,
2372 _BidirectionalIterator1
2374 _BidirectionalIterator1 __middle,
2375 _BidirectionalIterator1 __last,
2376 _Distance __len1, _Distance __len2,
2377 _BidirectionalIterator2 __buffer,
2378 _Distance __buffer_size)
2380 _BidirectionalIterator2 __buffer_end;
2381 if (__len1 > __len2 && __len2 <= __buffer_size)
2385 __buffer_end = _GLIBCXX_MOVE3(__middle, __last, __buffer);
2386 _GLIBCXX_MOVE_BACKWARD3(__first, __middle, __last);
2387 return _GLIBCXX_MOVE3(__buffer, __buffer_end, __first);
2392 else if (__len1 <= __buffer_size)
2396 __buffer_end = _GLIBCXX_MOVE3(__first, __middle, __buffer);
2397 _GLIBCXX_MOVE3(__middle, __last, __first);
2398 return _GLIBCXX_MOVE_BACKWARD3(__buffer, __buffer_end, __last);
2412 template<
typename _BidirectionalIterator,
typename _Distance,
2413 typename _Pointer,
typename _Compare>
2416 _BidirectionalIterator __middle,
2417 _BidirectionalIterator __last,
2418 _Distance __len1, _Distance __len2,
2419 _Pointer __buffer, _Distance __buffer_size,
2422 if (__len1 <= __len2 && __len1 <= __buffer_size)
2424 _Pointer __buffer_end = _GLIBCXX_MOVE3(__first, __middle, __buffer);
2428 else if (__len2 <= __buffer_size)
2430 _Pointer __buffer_end = _GLIBCXX_MOVE3(__middle, __last, __buffer);
2432 __buffer_end, __last, __comp);
2436 _BidirectionalIterator __first_cut = __first;
2437 _BidirectionalIterator __second_cut = __middle;
2438 _Distance __len11 = 0;
2439 _Distance __len22 = 0;
2440 if (__len1 > __len2)
2442 __len11 = __len1 / 2;
2445 = std::__lower_bound(__middle, __last, *__first_cut,
2446 __gnu_cxx::__ops::__iter_comp_val(__comp));
2451 __len22 = __len2 / 2;
2454 = std::__upper_bound(__first, __middle, *__second_cut,
2455 __gnu_cxx::__ops::__val_comp_iter(__comp));
2459 _BidirectionalIterator __new_middle
2461 __len1 - __len11, __len22, __buffer,
2464 __len22, __buffer, __buffer_size, __comp);
2467 __len2 - __len22, __buffer,
2468 __buffer_size, __comp);
2473 template<
typename _BidirectionalIterator,
typename _Distance,
2477 _BidirectionalIterator __middle,
2478 _BidirectionalIterator __last,
2479 _Distance __len1, _Distance __len2,
2482 if (__len1 == 0 || __len2 == 0)
2485 if (__len1 + __len2 == 2)
2487 if (__comp(__middle, __first))
2492 _BidirectionalIterator __first_cut = __first;
2493 _BidirectionalIterator __second_cut = __middle;
2494 _Distance __len11 = 0;
2495 _Distance __len22 = 0;
2496 if (__len1 > __len2)
2498 __len11 = __len1 / 2;
2501 = std::__lower_bound(__middle, __last, *__first_cut,
2502 __gnu_cxx::__ops::__iter_comp_val(__comp));
2507 __len22 = __len2 / 2;
2510 = std::__upper_bound(__first, __middle, *__second_cut,
2511 __gnu_cxx::__ops::__val_comp_iter(__comp));
2516 _BidirectionalIterator __new_middle = __first_cut;
2519 __len11, __len22, __comp);
2521 __len1 - __len11, __len2 - __len22, __comp);
2524 template<
typename _B
idirectionalIterator,
typename _Compare>
2526 __inplace_merge(_BidirectionalIterator __first,
2527 _BidirectionalIterator __middle,
2528 _BidirectionalIterator __last,
2531 typedef typename iterator_traits<_BidirectionalIterator>::value_type
2533 typedef typename iterator_traits<_BidirectionalIterator>::difference_type
2536 if (__first == __middle || __middle == __last)
2539 const _DistanceType __len1 =
std::distance(__first, __middle);
2540 const _DistanceType __len2 =
std::distance(__middle, __last);
2542 typedef _Temporary_buffer<_BidirectionalIterator, _ValueType> _TmpBuf;
2543 _TmpBuf __buf(__first, __last);
2545 if (__buf.begin() == 0)
2547 (__first, __middle, __last, __len1, __len2, __comp);
2550 (__first, __middle, __last, __len1, __len2, __buf.begin(),
2551 _DistanceType(__buf.size()), __comp);
2572 template<
typename _B
idirectionalIterator>
2574 inplace_merge(_BidirectionalIterator __first,
2575 _BidirectionalIterator __middle,
2576 _BidirectionalIterator __last)
2579 __glibcxx_function_requires(_Mutable_BidirectionalIteratorConcept<
2580 _BidirectionalIterator>)
2581 __glibcxx_function_requires(_LessThanComparableConcept<
2582 typename iterator_traits<_BidirectionalIterator>::value_type>)
2583 __glibcxx_requires_sorted(__first, __middle);
2584 __glibcxx_requires_sorted(__middle, __last);
2585 __glibcxx_requires_irreflexive(__first, __last);
2587 std::__inplace_merge(__first, __middle, __last,
2588 __gnu_cxx::__ops::__iter_less_iter());
2613 template<
typename _B
idirectionalIterator,
typename _Compare>
2615 inplace_merge(_BidirectionalIterator __first,
2616 _BidirectionalIterator __middle,
2617 _BidirectionalIterator __last,
2621 __glibcxx_function_requires(_Mutable_BidirectionalIteratorConcept<
2622 _BidirectionalIterator>)
2623 __glibcxx_function_requires(_BinaryPredicateConcept<_Compare,
2624 typename iterator_traits<_BidirectionalIterator>::value_type,
2625 typename iterator_traits<_BidirectionalIterator>::value_type>)
2626 __glibcxx_requires_sorted_pred(__first, __middle, __comp);
2627 __glibcxx_requires_sorted_pred(__middle, __last, __comp);
2628 __glibcxx_requires_irreflexive_pred(__first, __last, __comp);
2630 std::__inplace_merge(__first, __middle, __last,
2631 __gnu_cxx::__ops::__iter_comp_iter(__comp));
2636 template<
typename _InputIterator,
typename _OutputIterator,
2640 _InputIterator __first2, _InputIterator __last2,
2641 _OutputIterator __result, _Compare __comp)
2643 while (__first1 != __last1 && __first2 != __last2)
2645 if (__comp(__first2, __first1))
2647 *__result = _GLIBCXX_MOVE(*__first2);
2652 *__result = _GLIBCXX_MOVE(*__first1);
2657 return _GLIBCXX_MOVE3(__first2, __last2,
2658 _GLIBCXX_MOVE3(__first1, __last1,
2662 template<
typename _RandomAccessIterator1,
typename _RandomAccessIterator2,
2663 typename _Distance,
typename _Compare>
2665 __merge_sort_loop(_RandomAccessIterator1 __first,
2666 _RandomAccessIterator1 __last,
2667 _RandomAccessIterator2 __result, _Distance __step_size,
2670 const _Distance __two_step = 2 * __step_size;
2672 while (__last - __first >= __two_step)
2675 __first + __step_size,
2676 __first + __two_step,
2678 __first += __two_step;
2680 __step_size =
std::min(_Distance(__last - __first), __step_size);
2683 __first + __step_size, __last, __result, __comp);
2686 template<
typename _RandomAccessIterator,
typename _Distance,
2689 __chunk_insertion_sort(_RandomAccessIterator __first,
2690 _RandomAccessIterator __last,
2691 _Distance __chunk_size, _Compare __comp)
2693 while (__last - __first >= __chunk_size)
2696 __first += __chunk_size;
2701 enum { _S_chunk_size = 7 };
2703 template<
typename _RandomAccessIterator,
typename _Po
inter,
typename _Compare>
2705 __merge_sort_with_buffer(_RandomAccessIterator __first,
2706 _RandomAccessIterator __last,
2707 _Pointer __buffer, _Compare __comp)
2709 typedef typename iterator_traits<_RandomAccessIterator>::difference_type
2712 const _Distance __len = __last - __first;
2713 const _Pointer __buffer_last = __buffer + __len;
2715 _Distance __step_size = _S_chunk_size;
2716 std::__chunk_insertion_sort(__first, __last, __step_size, __comp);
2718 while (__step_size < __len)
2720 std::__merge_sort_loop(__first, __last, __buffer,
2721 __step_size, __comp);
2723 std::__merge_sort_loop(__buffer, __buffer_last, __first,
2724 __step_size, __comp);
2729 template<
typename _RandomAccessIterator,
typename _Pointer,
2730 typename _Distance,
typename _Compare>
2732 __stable_sort_adaptive(_RandomAccessIterator __first,
2733 _RandomAccessIterator __last,
2734 _Pointer __buffer, _Distance __buffer_size,
2737 const _Distance __len = (__last - __first + 1) / 2;
2738 const _RandomAccessIterator __middle = __first + __len;
2739 if (__len > __buffer_size)
2741 std::__stable_sort_adaptive(__first, __middle, __buffer,
2742 __buffer_size, __comp);
2743 std::__stable_sort_adaptive(__middle, __last, __buffer,
2744 __buffer_size, __comp);
2748 std::__merge_sort_with_buffer(__first, __middle, __buffer, __comp);
2749 std::__merge_sort_with_buffer(__middle, __last, __buffer, __comp);
2752 _Distance(__middle - __first),
2753 _Distance(__last - __middle),
2754 __buffer, __buffer_size,
2759 template<
typename _RandomAccessIterator,
typename _Compare>
2762 _RandomAccessIterator __last, _Compare __comp)
2764 if (__last - __first < 15)
2769 _RandomAccessIterator __middle = __first + (__last - __first) / 2;
2785 template<
typename _InputIterator1,
typename _InputIterator2,
2788 __includes(_InputIterator1 __first1, _InputIterator1 __last1,
2789 _InputIterator2 __first2, _InputIterator2 __last2,
2792 while (__first1 != __last1 && __first2 != __last2)
2793 if (__comp(__first2, __first1))
2795 else if (__comp(__first1, __first2))
2803 return __first2 == __last2;
2824 template<
typename _InputIterator1,
typename _InputIterator2>
2826 includes(_InputIterator1 __first1, _InputIterator1 __last1,
2827 _InputIterator2 __first2, _InputIterator2 __last2)
2830 __glibcxx_function_requires(_InputIteratorConcept<_InputIterator1>)
2831 __glibcxx_function_requires(_InputIteratorConcept<_InputIterator2>)
2832 __glibcxx_function_requires(_LessThanOpConcept<
2833 typename iterator_traits<_InputIterator1>::value_type,
2834 typename iterator_traits<_InputIterator2>::value_type>)
2835 __glibcxx_function_requires(_LessThanOpConcept<
2836 typename iterator_traits<_InputIterator2>::value_type,
2837 typename iterator_traits<_InputIterator1>::value_type>)
2838 __glibcxx_requires_sorted_set(__first1, __last1, __first2);
2839 __glibcxx_requires_sorted_set(__first2, __last2, __first1);
2840 __glibcxx_requires_irreflexive2(__first1, __last1);
2841 __glibcxx_requires_irreflexive2(__first2, __last2);
2843 return std::__includes(__first1, __last1, __first2, __last2,
2844 __gnu_cxx::__ops::__iter_less_iter());
2868 template<
typename _InputIterator1,
typename _InputIterator2,
2871 includes(_InputIterator1 __first1, _InputIterator1 __last1,
2872 _InputIterator2 __first2, _InputIterator2 __last2,
2876 __glibcxx_function_requires(_InputIteratorConcept<_InputIterator1>)
2877 __glibcxx_function_requires(_InputIteratorConcept<_InputIterator2>)
2878 __glibcxx_function_requires(_BinaryPredicateConcept<_Compare,
2879 typename iterator_traits<_InputIterator1>::value_type,
2880 typename iterator_traits<_InputIterator2>::value_type>)
2881 __glibcxx_function_requires(_BinaryPredicateConcept<_Compare,
2882 typename iterator_traits<_InputIterator2>::value_type,
2883 typename iterator_traits<_InputIterator1>::value_type>)
2884 __glibcxx_requires_sorted_set_pred(__first1, __last1, __first2, __comp);
2885 __glibcxx_requires_sorted_set_pred(__first2, __last2, __first1, __comp);
2886 __glibcxx_requires_irreflexive_pred2(__first1, __last1, __comp);
2887 __glibcxx_requires_irreflexive_pred2(__first2, __last2, __comp);
2889 return std::__includes(__first1, __last1, __first2, __last2,
2890 __gnu_cxx::__ops::__iter_comp_iter(__comp));
2903 template<
typename _B
idirectionalIterator,
typename _Compare>
2905 __next_permutation(_BidirectionalIterator __first,
2906 _BidirectionalIterator __last, _Compare __comp)
2908 if (__first == __last)
2910 _BidirectionalIterator __i = __first;
2919 _BidirectionalIterator __ii = __i;
2921 if (__comp(__i, __ii))
2923 _BidirectionalIterator __j = __last;
2924 while (!__comp(__i, --__j))
2952 template<
typename _B
idirectionalIterator>
2954 next_permutation(_BidirectionalIterator __first,
2955 _BidirectionalIterator __last)
2958 __glibcxx_function_requires(_BidirectionalIteratorConcept<
2959 _BidirectionalIterator>)
2960 __glibcxx_function_requires(_LessThanComparableConcept<
2961 typename iterator_traits<_BidirectionalIterator>::value_type>)
2962 __glibcxx_requires_valid_range(__first, __last);
2963 __glibcxx_requires_irreflexive(__first, __last);
2965 return std::__next_permutation
2966 (__first, __last, __gnu_cxx::__ops::__iter_less_iter());
2984 template<
typename _B
idirectionalIterator,
typename _Compare>
2986 next_permutation(_BidirectionalIterator __first,
2987 _BidirectionalIterator __last, _Compare __comp)
2990 __glibcxx_function_requires(_BidirectionalIteratorConcept<
2991 _BidirectionalIterator>)
2992 __glibcxx_function_requires(_BinaryPredicateConcept<_Compare,
2993 typename iterator_traits<_BidirectionalIterator>::value_type,
2994 typename iterator_traits<_BidirectionalIterator>::value_type>)
2995 __glibcxx_requires_valid_range(__first, __last);
2996 __glibcxx_requires_irreflexive_pred(__first, __last, __comp);
2998 return std::__next_permutation
2999 (__first, __last, __gnu_cxx::__ops::__iter_comp_iter(__comp));
3002 template<
typename _B
idirectionalIterator,
typename _Compare>
3004 __prev_permutation(_BidirectionalIterator __first,
3005 _BidirectionalIterator __last, _Compare __comp)
3007 if (__first == __last)
3009 _BidirectionalIterator __i = __first;
3018 _BidirectionalIterator __ii = __i;
3020 if (__comp(__ii, __i))
3022 _BidirectionalIterator __j = __last;
3023 while (!__comp(--__j, __i))
3052 template<
typename _B
idirectionalIterator>
3054 prev_permutation(_BidirectionalIterator __first,
3055 _BidirectionalIterator __last)
3058 __glibcxx_function_requires(_BidirectionalIteratorConcept<
3059 _BidirectionalIterator>)
3060 __glibcxx_function_requires(_LessThanComparableConcept<
3061 typename iterator_traits<_BidirectionalIterator>::value_type>)
3062 __glibcxx_requires_valid_range(__first, __last);
3063 __glibcxx_requires_irreflexive(__first, __last);
3065 return std::__prev_permutation(__first, __last,
3066 __gnu_cxx::__ops::__iter_less_iter());
3084 template<
typename _B
idirectionalIterator,
typename _Compare>
3086 prev_permutation(_BidirectionalIterator __first,
3087 _BidirectionalIterator __last, _Compare __comp)
3090 __glibcxx_function_requires(_BidirectionalIteratorConcept<
3091 _BidirectionalIterator>)
3092 __glibcxx_function_requires(_BinaryPredicateConcept<_Compare,
3093 typename iterator_traits<_BidirectionalIterator>::value_type,
3094 typename iterator_traits<_BidirectionalIterator>::value_type>)
3095 __glibcxx_requires_valid_range(__first, __last);
3096 __glibcxx_requires_irreflexive_pred(__first, __last, __comp);
3098 return std::__prev_permutation(__first, __last,
3099 __gnu_cxx::__ops::__iter_comp_iter(__comp));
3105 template<
typename _InputIterator,
typename _OutputIterator,
3106 typename _Predicate,
typename _Tp>
3108 __replace_copy_if(_InputIterator __first, _InputIterator __last,
3109 _OutputIterator __result,
3110 _Predicate __pred,
const _Tp& __new_value)
3112 for (; __first != __last; ++__first, (void)++__result)
3113 if (__pred(__first))
3114 *__result = __new_value;
3116 *__result = *__first;
3134 template<
typename _InputIterator,
typename _OutputIterator,
typename _Tp>
3135 inline _OutputIterator
3136 replace_copy(_InputIterator __first, _InputIterator __last,
3137 _OutputIterator __result,
3138 const _Tp& __old_value,
const _Tp& __new_value)
3141 __glibcxx_function_requires(_InputIteratorConcept<_InputIterator>)
3142 __glibcxx_function_requires(_OutputIteratorConcept<_OutputIterator,
3143 typename iterator_traits<_InputIterator>::value_type>)
3144 __glibcxx_function_requires(_EqualOpConcept<
3145 typename iterator_traits<_InputIterator>::value_type, _Tp>)
3146 __glibcxx_requires_valid_range(__first, __last);
3148 return std::__replace_copy_if(__first, __last, __result,
3149 __gnu_cxx::__ops::__iter_equals_val(__old_value),
3168 template<
typename _InputIterator,
typename _OutputIterator,
3169 typename _Predicate,
typename _Tp>
3170 inline _OutputIterator
3171 replace_copy_if(_InputIterator __first, _InputIterator __last,
3172 _OutputIterator __result,
3173 _Predicate __pred,
const _Tp& __new_value)
3176 __glibcxx_function_requires(_InputIteratorConcept<_InputIterator>)
3177 __glibcxx_function_requires(_OutputIteratorConcept<_OutputIterator,
3178 typename iterator_traits<_InputIterator>::value_type>)
3179 __glibcxx_function_requires(_UnaryPredicateConcept<_Predicate,
3180 typename iterator_traits<_InputIterator>::value_type>)
3181 __glibcxx_requires_valid_range(__first, __last);
3183 return std::__replace_copy_if(__first, __last, __result,
3184 __gnu_cxx::__ops::__pred_iter(__pred),
3188 template<
typename _InputIterator,
typename _Predicate>
3189 typename iterator_traits<_InputIterator>::difference_type
3190 __count_if(_InputIterator __first, _InputIterator __last, _Predicate __pred)
3192 typename iterator_traits<_InputIterator>::difference_type __n = 0;
3193 for (; __first != __last; ++__first)
3194 if (__pred(__first))
3199 #if __cplusplus >= 201103L 3207 template<
typename _ForwardIterator>
3209 is_sorted(_ForwardIterator __first, _ForwardIterator __last)
3221 template<
typename _ForwardIterator,
typename _Compare>
3223 is_sorted(_ForwardIterator __first, _ForwardIterator __last,
3227 template<
typename _ForwardIterator,
typename _Compare>
3229 __is_sorted_until(_ForwardIterator __first, _ForwardIterator __last,
3232 if (__first == __last)
3235 _ForwardIterator __next = __first;
3236 for (++__next; __next != __last; __first = __next, (void)++__next)
3237 if (__comp(__next, __first))
3250 template<
typename _ForwardIterator>
3251 inline _ForwardIterator
3252 is_sorted_until(_ForwardIterator __first, _ForwardIterator __last)
3255 __glibcxx_function_requires(_ForwardIteratorConcept<_ForwardIterator>)
3256 __glibcxx_function_requires(_LessThanComparableConcept<
3257 typename iterator_traits<_ForwardIterator>::value_type>)
3258 __glibcxx_requires_valid_range(__first, __last);
3259 __glibcxx_requires_irreflexive(__first, __last);
3261 return std::__is_sorted_until(__first, __last,
3262 __gnu_cxx::__ops::__iter_less_iter());
3274 template<
typename _ForwardIterator,
typename _Compare>
3275 inline _ForwardIterator
3276 is_sorted_until(_ForwardIterator __first, _ForwardIterator __last,
3280 __glibcxx_function_requires(_ForwardIteratorConcept<_ForwardIterator>)
3281 __glibcxx_function_requires(_BinaryPredicateConcept<_Compare,
3282 typename iterator_traits<_ForwardIterator>::value_type,
3283 typename iterator_traits<_ForwardIterator>::value_type>)
3284 __glibcxx_requires_valid_range(__first, __last);
3285 __glibcxx_requires_irreflexive_pred(__first, __last, __comp);
3287 return std::__is_sorted_until(__first, __last,
3288 __gnu_cxx::__ops::__iter_comp_iter(__comp));
3299 template<
typename _Tp>
3300 _GLIBCXX14_CONSTEXPR
3301 inline pair<const _Tp&, const _Tp&>
3305 __glibcxx_function_requires(_LessThanComparableConcept<_Tp>)
3307 return __b < __a ? pair<const _Tp&, const _Tp&>(__b, __a)
3320 template<
typename _Tp,
typename _Compare>
3321 _GLIBCXX14_CONSTEXPR
3322 inline pair<const _Tp&, const _Tp&>
3323 minmax(
const _Tp& __a,
const _Tp& __b, _Compare __comp)
3329 template<
typename _ForwardIterator,
typename _Compare>
3330 _GLIBCXX14_CONSTEXPR
3331 pair<_ForwardIterator, _ForwardIterator>
3332 __minmax_element(_ForwardIterator __first, _ForwardIterator __last,
3335 _ForwardIterator __next = __first;
3336 if (__first == __last
3337 || ++__next == __last)
3340 _ForwardIterator __min{}, __max{};
3341 if (__comp(__next, __first))
3355 while (__first != __last)
3358 if (++__next == __last)
3360 if (__comp(__first, __min))
3362 else if (!__comp(__first, __max))
3367 if (__comp(__next, __first))
3369 if (__comp(__next, __min))
3371 if (!__comp(__first, __max))
3376 if (__comp(__first, __min))
3378 if (!__comp(__next, __max))
3400 template<
typename _ForwardIterator>
3401 _GLIBCXX14_CONSTEXPR
3402 inline pair<_ForwardIterator, _ForwardIterator>
3403 minmax_element(_ForwardIterator __first, _ForwardIterator __last)
3406 __glibcxx_function_requires(_ForwardIteratorConcept<_ForwardIterator>)
3407 __glibcxx_function_requires(_LessThanComparableConcept<
3408 typename iterator_traits<_ForwardIterator>::value_type>)
3409 __glibcxx_requires_valid_range(__first, __last);
3410 __glibcxx_requires_irreflexive(__first, __last);
3412 return std::__minmax_element(__first, __last,
3413 __gnu_cxx::__ops::__iter_less_iter());
3428 template<
typename _ForwardIterator,
typename _Compare>
3429 _GLIBCXX14_CONSTEXPR
3430 inline pair<_ForwardIterator, _ForwardIterator>
3431 minmax_element(_ForwardIterator __first, _ForwardIterator __last,
3435 __glibcxx_function_requires(_ForwardIteratorConcept<_ForwardIterator>)
3436 __glibcxx_function_requires(_BinaryPredicateConcept<_Compare,
3437 typename iterator_traits<_ForwardIterator>::value_type,
3438 typename iterator_traits<_ForwardIterator>::value_type>)
3439 __glibcxx_requires_valid_range(__first, __last);
3440 __glibcxx_requires_irreflexive_pred(__first, __last, __comp);
3442 return std::__minmax_element(__first, __last,
3443 __gnu_cxx::__ops::__iter_comp_iter(__comp));
3447 template<
typename _Tp>
3448 _GLIBCXX14_CONSTEXPR
3450 min(initializer_list<_Tp> __l)
3451 {
return *std::min_element(__l.begin(), __l.end()); }
3453 template<
typename _Tp,
typename _Compare>
3454 _GLIBCXX14_CONSTEXPR
3456 min(initializer_list<_Tp> __l, _Compare __comp)
3459 template<
typename _Tp>
3460 _GLIBCXX14_CONSTEXPR
3462 max(initializer_list<_Tp> __l)
3465 template<
typename _Tp,
typename _Compare>
3466 _GLIBCXX14_CONSTEXPR
3468 max(initializer_list<_Tp> __l, _Compare __comp)
3471 template<
typename _Tp>
3472 _GLIBCXX14_CONSTEXPR
3473 inline pair<_Tp, _Tp>
3474 minmax(initializer_list<_Tp> __l)
3476 pair<const _Tp*, const _Tp*> __p =
3481 template<
typename _Tp,
typename _Compare>
3482 _GLIBCXX14_CONSTEXPR
3483 inline pair<_Tp, _Tp>
3484 minmax(initializer_list<_Tp> __l, _Compare __comp)
3486 pair<const _Tp*, const _Tp*> __p =
3491 template<
typename _ForwardIterator1,
typename _ForwardIterator2,
3492 typename _BinaryPredicate>
3494 __is_permutation(_ForwardIterator1 __first1, _ForwardIterator1 __last1,
3495 _ForwardIterator2 __first2, _BinaryPredicate __pred)
3499 for (; __first1 != __last1; ++__first1, (void)++__first2)
3500 if (!__pred(__first1, __first2))
3503 if (__first1 == __last1)
3508 _ForwardIterator2 __last2 = __first2;
3510 for (_ForwardIterator1 __scan = __first1; __scan != __last1; ++__scan)
3513 __gnu_cxx::__ops::__iter_comp_iter(__pred, __scan)))
3517 = std::__count_if(__first2, __last2,
3518 __gnu_cxx::__ops::__iter_comp_iter(__pred, __scan));
3519 if (0 == __matches ||
3520 std::__count_if(__scan, __last1,
3521 __gnu_cxx::__ops::__iter_comp_iter(__pred, __scan))
3540 template<
typename _ForwardIterator1,
typename _ForwardIterator2>
3542 is_permutation(_ForwardIterator1 __first1, _ForwardIterator1 __last1,
3543 _ForwardIterator2 __first2)
3546 __glibcxx_function_requires(_ForwardIteratorConcept<_ForwardIterator1>)
3547 __glibcxx_function_requires(_ForwardIteratorConcept<_ForwardIterator2>)
3548 __glibcxx_function_requires(_EqualOpConcept<
3549 typename iterator_traits<_ForwardIterator1>::value_type,
3550 typename iterator_traits<_ForwardIterator2>::value_type>)
3551 __glibcxx_requires_valid_range(__first1, __last1);
3553 return std::__is_permutation(__first1, __last1, __first2,
3554 __gnu_cxx::__ops::__iter_equal_to_iter());
3571 template<
typename _ForwardIterator1,
typename _ForwardIterator2,
3572 typename _BinaryPredicate>
3574 is_permutation(_ForwardIterator1 __first1, _ForwardIterator1 __last1,
3575 _ForwardIterator2 __first2, _BinaryPredicate __pred)
3578 __glibcxx_function_requires(_ForwardIteratorConcept<_ForwardIterator1>)
3579 __glibcxx_function_requires(_ForwardIteratorConcept<_ForwardIterator2>)
3580 __glibcxx_function_requires(_BinaryPredicateConcept<_BinaryPredicate,
3581 typename iterator_traits<_ForwardIterator1>::value_type,
3582 typename iterator_traits<_ForwardIterator2>::value_type>)
3583 __glibcxx_requires_valid_range(__first1, __last1);
3585 return std::__is_permutation(__first1, __last1, __first2,
3586 __gnu_cxx::__ops::__iter_comp_iter(__pred));
3589 #if __cplusplus > 201103L 3590 template<
typename _ForwardIterator1,
typename _ForwardIterator2,
3591 typename _BinaryPredicate>
3593 __is_permutation(_ForwardIterator1 __first1, _ForwardIterator1 __last1,
3594 _ForwardIterator2 __first2, _ForwardIterator2 __last2,
3595 _BinaryPredicate __pred)
3598 =
typename iterator_traits<_ForwardIterator1>::iterator_category;
3600 =
typename iterator_traits<_ForwardIterator2>::iterator_category;
3601 using _It1_is_RA = is_same<_Cat1, random_access_iterator_tag>;
3602 using _It2_is_RA = is_same<_Cat2, random_access_iterator_tag>;
3603 constexpr
bool __ra_iters = _It1_is_RA() && _It2_is_RA();
3614 for (; __first1 != __last1 && __first2 != __last2;
3615 ++__first1, (void)++__first2)
3616 if (!__pred(__first1, __first2))
3621 if (__first1 == __last1)
3628 if (__d1 == 0 && __d2 == 0)
3634 for (_ForwardIterator1 __scan = __first1; __scan != __last1; ++__scan)
3637 __gnu_cxx::__ops::__iter_comp_iter(__pred, __scan)))
3640 auto __matches = std::__count_if(__first2, __last2,
3641 __gnu_cxx::__ops::__iter_comp_iter(__pred, __scan));
3643 || std::__count_if(__scan, __last1,
3644 __gnu_cxx::__ops::__iter_comp_iter(__pred, __scan))
3664 template<
typename _ForwardIterator1,
typename _ForwardIterator2>
3666 is_permutation(_ForwardIterator1 __first1, _ForwardIterator1 __last1,
3667 _ForwardIterator2 __first2, _ForwardIterator2 __last2)
3669 __glibcxx_requires_valid_range(__first1, __last1);
3670 __glibcxx_requires_valid_range(__first2, __last2);
3673 std::__is_permutation(__first1, __last1, __first2, __last2,
3674 __gnu_cxx::__ops::__iter_equal_to_iter());
3691 template<
typename _ForwardIterator1,
typename _ForwardIterator2,
3692 typename _BinaryPredicate>
3694 is_permutation(_ForwardIterator1 __first1, _ForwardIterator1 __last1,
3695 _ForwardIterator2 __first2, _ForwardIterator2 __last2,
3696 _BinaryPredicate __pred)
3698 __glibcxx_requires_valid_range(__first1, __last1);
3699 __glibcxx_requires_valid_range(__first2, __last2);
3701 return std::__is_permutation(__first1, __last1, __first2, __last2,
3702 __gnu_cxx::__ops::__iter_comp_iter(__pred));
3705 #if __cplusplus > 201402L 3707 #define __cpp_lib_clamp 201603 3717 template<
typename _Tp>
3718 constexpr
const _Tp&
3719 clamp(
const _Tp& __val,
const _Tp& __lo,
const _Tp& __hi)
3721 __glibcxx_assert(!(__hi < __lo));
3722 return (__val < __lo) ? __lo : (__hi < __val) ? __hi : __val;
3735 template<
typename _Tp,
typename _Compare>
3736 constexpr
const _Tp&
3737 clamp(
const _Tp& __val,
const _Tp& __lo,
const _Tp& __hi, _Compare __comp)
3739 __glibcxx_assert(!__comp(__hi, __lo));
3740 return __comp(__val, __lo) ? __lo : __comp(__hi, __val) ? __hi : __val;
3745 #ifdef _GLIBCXX_USE_C99_STDINT_TR1 3767 template<
typename _IntType,
typename _UniformRandomBitGenerator>
3768 pair<_IntType, _IntType>
3770 _UniformRandomBitGenerator&& __g)
3789 template<
typename _RandomAccessIterator,
3790 typename _UniformRandomNumberGenerator>
3792 shuffle(_RandomAccessIterator __first, _RandomAccessIterator __last,
3793 _UniformRandomNumberGenerator&& __g)
3796 __glibcxx_function_requires(_Mutable_RandomAccessIteratorConcept<
3797 _RandomAccessIterator>)
3798 __glibcxx_requires_valid_range(__first, __last);
3800 if (__first == __last)
3803 typedef typename iterator_traits<_RandomAccessIterator>::difference_type
3806 typedef typename std::make_unsigned<_DistanceType>::type __ud_type;
3808 typedef typename __distr_type::param_type __p_type;
3810 typedef typename remove_reference<_UniformRandomNumberGenerator>::type
3815 const __uc_type __urngrange = __g.max() - __g.min();
3816 const __uc_type __urange = __uc_type(__last - __first);
3818 if (__urngrange / __urange >= __urange)
3821 _RandomAccessIterator __i = __first + 1;
3827 if ((__urange % 2) == 0)
3829 __distr_type __d{0, 1};
3837 while (__i != __last)
3839 const __uc_type __swap_range = __uc_type(__i - __first) + 1;
3853 for (_RandomAccessIterator __i = __first + 1; __i != __last; ++__i)
3854 std::iter_swap(__i, __first + __d(__g, __p_type(0, __i - __first)));
3860 _GLIBCXX_BEGIN_NAMESPACE_ALGO
3874 template<
typename _InputIterator,
typename _Function>
3876 for_each(_InputIterator __first, _InputIterator __last, _Function __f)
3879 __glibcxx_function_requires(_InputIteratorConcept<_InputIterator>)
3880 __glibcxx_requires_valid_range(__first, __last);
3881 for (; __first != __last; ++__first)
3895 template<
typename _InputIterator,
typename _Tp>
3896 inline _InputIterator
3897 find(_InputIterator __first, _InputIterator __last,
3901 __glibcxx_function_requires(_InputIteratorConcept<_InputIterator>)
3902 __glibcxx_function_requires(_EqualOpConcept<
3903 typename iterator_traits<_InputIterator>::value_type, _Tp>)
3904 __glibcxx_requires_valid_range(__first, __last);
3906 __gnu_cxx::__ops::__iter_equals_val(__val));
3919 template<
typename _InputIterator,
typename _Predicate>
3920 inline _InputIterator
3921 find_if(_InputIterator __first, _InputIterator __last,
3925 __glibcxx_function_requires(_InputIteratorConcept<_InputIterator>)
3926 __glibcxx_function_requires(_UnaryPredicateConcept<_Predicate,
3927 typename iterator_traits<_InputIterator>::value_type>)
3928 __glibcxx_requires_valid_range(__first, __last);
3931 __gnu_cxx::__ops::__pred_iter(__pred));
3950 template<
typename _InputIterator,
typename _ForwardIterator>
3952 find_first_of(_InputIterator __first1, _InputIterator __last1,
3953 _ForwardIterator __first2, _ForwardIterator __last2)
3956 __glibcxx_function_requires(_InputIteratorConcept<_InputIterator>)
3957 __glibcxx_function_requires(_ForwardIteratorConcept<_ForwardIterator>)
3958 __glibcxx_function_requires(_EqualOpConcept<
3959 typename iterator_traits<_InputIterator>::value_type,
3960 typename iterator_traits<_ForwardIterator>::value_type>)
3961 __glibcxx_requires_valid_range(__first1, __last1);
3962 __glibcxx_requires_valid_range(__first2, __last2);
3964 for (; __first1 != __last1; ++__first1)
3965 for (_ForwardIterator __iter = __first2; __iter != __last2; ++__iter)
3966 if (*__first1 == *__iter)
3990 template<
typename _InputIterator,
typename _ForwardIterator,
3991 typename _BinaryPredicate>
3993 find_first_of(_InputIterator __first1, _InputIterator __last1,
3994 _ForwardIterator __first2, _ForwardIterator __last2,
3995 _BinaryPredicate __comp)
3998 __glibcxx_function_requires(_InputIteratorConcept<_InputIterator>)
3999 __glibcxx_function_requires(_ForwardIteratorConcept<_ForwardIterator>)
4000 __glibcxx_function_requires(_BinaryPredicateConcept<_BinaryPredicate,
4001 typename iterator_traits<_InputIterator>::value_type,
4002 typename iterator_traits<_ForwardIterator>::value_type>)
4003 __glibcxx_requires_valid_range(__first1, __last1);
4004 __glibcxx_requires_valid_range(__first2, __last2);
4006 for (; __first1 != __last1; ++__first1)
4007 for (_ForwardIterator __iter = __first2; __iter != __last2; ++__iter)
4008 if (__comp(*__first1, *__iter))
4022 template<
typename _ForwardIterator>
4023 inline _ForwardIterator
4024 adjacent_find(_ForwardIterator __first, _ForwardIterator __last)
4027 __glibcxx_function_requires(_ForwardIteratorConcept<_ForwardIterator>)
4028 __glibcxx_function_requires(_EqualityComparableConcept<
4029 typename iterator_traits<_ForwardIterator>::value_type>)
4030 __glibcxx_requires_valid_range(__first, __last);
4032 return std::__adjacent_find(__first, __last,
4033 __gnu_cxx::__ops::__iter_equal_to_iter());
4047 template<
typename _ForwardIterator,
typename _BinaryPredicate>
4048 inline _ForwardIterator
4049 adjacent_find(_ForwardIterator __first, _ForwardIterator __last,
4050 _BinaryPredicate __binary_pred)
4053 __glibcxx_function_requires(_ForwardIteratorConcept<_ForwardIterator>)
4054 __glibcxx_function_requires(_BinaryPredicateConcept<_BinaryPredicate,
4055 typename iterator_traits<_ForwardIterator>::value_type,
4056 typename iterator_traits<_ForwardIterator>::value_type>)
4057 __glibcxx_requires_valid_range(__first, __last);
4059 return std::__adjacent_find(__first, __last,
4060 __gnu_cxx::__ops::__iter_comp_iter(__binary_pred));
4072 template<
typename _InputIterator,
typename _Tp>
4073 inline typename iterator_traits<_InputIterator>::difference_type
4074 count(_InputIterator __first, _InputIterator __last,
const _Tp& __value)
4077 __glibcxx_function_requires(_InputIteratorConcept<_InputIterator>)
4078 __glibcxx_function_requires(_EqualOpConcept<
4079 typename iterator_traits<_InputIterator>::value_type, _Tp>)
4080 __glibcxx_requires_valid_range(__first, __last);
4082 return std::__count_if(__first, __last,
4083 __gnu_cxx::__ops::__iter_equals_val(__value));
4095 template<
typename _InputIterator,
typename _Predicate>
4096 inline typename iterator_traits<_InputIterator>::difference_type
4097 count_if(_InputIterator __first, _InputIterator __last, _Predicate __pred)
4100 __glibcxx_function_requires(_InputIteratorConcept<_InputIterator>)
4101 __glibcxx_function_requires(_UnaryPredicateConcept<_Predicate,
4102 typename iterator_traits<_InputIterator>::value_type>)
4103 __glibcxx_requires_valid_range(__first, __last);
4105 return std::__count_if(__first, __last,
4106 __gnu_cxx::__ops::__pred_iter(__pred));
4135 template<
typename _ForwardIterator1,
typename _ForwardIterator2>
4136 inline _ForwardIterator1
4137 search(_ForwardIterator1 __first1, _ForwardIterator1 __last1,
4138 _ForwardIterator2 __first2, _ForwardIterator2 __last2)
4141 __glibcxx_function_requires(_ForwardIteratorConcept<_ForwardIterator1>)
4142 __glibcxx_function_requires(_ForwardIteratorConcept<_ForwardIterator2>)
4143 __glibcxx_function_requires(_EqualOpConcept<
4144 typename iterator_traits<_ForwardIterator1>::value_type,
4145 typename iterator_traits<_ForwardIterator2>::value_type>)
4146 __glibcxx_requires_valid_range(__first1, __last1);
4147 __glibcxx_requires_valid_range(__first2, __last2);
4149 return std::__search(__first1, __last1, __first2, __last2,
4150 __gnu_cxx::__ops::__iter_equal_to_iter());
4174 template<
typename _ForwardIterator1,
typename _ForwardIterator2,
4175 typename _BinaryPredicate>
4176 inline _ForwardIterator1
4177 search(_ForwardIterator1 __first1, _ForwardIterator1 __last1,
4178 _ForwardIterator2 __first2, _ForwardIterator2 __last2,
4179 _BinaryPredicate __predicate)
4182 __glibcxx_function_requires(_ForwardIteratorConcept<_ForwardIterator1>)
4183 __glibcxx_function_requires(_ForwardIteratorConcept<_ForwardIterator2>)
4184 __glibcxx_function_requires(_BinaryPredicateConcept<_BinaryPredicate,
4185 typename iterator_traits<_ForwardIterator1>::value_type,
4186 typename iterator_traits<_ForwardIterator2>::value_type>)
4187 __glibcxx_requires_valid_range(__first1, __last1);
4188 __glibcxx_requires_valid_range(__first2, __last2);
4190 return std::__search(__first1, __last1, __first2, __last2,
4191 __gnu_cxx::__ops::__iter_comp_iter(__predicate));
4209 template<
typename _ForwardIterator,
typename _Integer,
typename _Tp>
4210 inline _ForwardIterator
4211 search_n(_ForwardIterator __first, _ForwardIterator __last,
4212 _Integer __count,
const _Tp& __val)
4215 __glibcxx_function_requires(_ForwardIteratorConcept<_ForwardIterator>)
4216 __glibcxx_function_requires(_EqualOpConcept<
4217 typename iterator_traits<_ForwardIterator>::value_type, _Tp>)
4218 __glibcxx_requires_valid_range(__first, __last);
4220 return std::__search_n(__first, __last, __count,
4221 __gnu_cxx::__ops::__iter_equals_val(__val));
4242 template<
typename _ForwardIterator,
typename _Integer,
typename _Tp,
4243 typename _BinaryPredicate>
4244 inline _ForwardIterator
4245 search_n(_ForwardIterator __first, _ForwardIterator __last,
4246 _Integer __count,
const _Tp& __val,
4247 _BinaryPredicate __binary_pred)
4250 __glibcxx_function_requires(_ForwardIteratorConcept<_ForwardIterator>)
4251 __glibcxx_function_requires(_BinaryPredicateConcept<_BinaryPredicate,
4252 typename iterator_traits<_ForwardIterator>::value_type, _Tp>)
4253 __glibcxx_requires_valid_range(__first, __last);
4255 return std::__search_n(__first, __last, __count,
4256 __gnu_cxx::__ops::__iter_comp_val(__binary_pred, __val));
4259 #if __cplusplus > 201402L 4267 template<
typename _ForwardIterator,
typename _Searcher>
4268 inline _ForwardIterator
4269 search(_ForwardIterator __first, _ForwardIterator __last,
4270 const _Searcher& __searcher)
4271 {
return __searcher(__first, __last).first; }
4290 template<
typename _InputIterator,
typename _OutputIterator,
4291 typename _UnaryOperation>
4293 transform(_InputIterator __first, _InputIterator __last,
4294 _OutputIterator __result, _UnaryOperation __unary_op)
4297 __glibcxx_function_requires(_InputIteratorConcept<_InputIterator>)
4298 __glibcxx_function_requires(_OutputIteratorConcept<_OutputIterator,
4300 __typeof__(__unary_op(*__first))>)
4301 __glibcxx_requires_valid_range(__first, __last);
4303 for (; __first != __last; ++__first, (void)++__result)
4304 *__result = __unary_op(*__first);
4327 template<
typename _InputIterator1,
typename _InputIterator2,
4328 typename _OutputIterator,
typename _BinaryOperation>
4330 transform(_InputIterator1 __first1, _InputIterator1 __last1,
4331 _InputIterator2 __first2, _OutputIterator __result,
4332 _BinaryOperation __binary_op)
4335 __glibcxx_function_requires(_InputIteratorConcept<_InputIterator1>)
4336 __glibcxx_function_requires(_InputIteratorConcept<_InputIterator2>)
4337 __glibcxx_function_requires(_OutputIteratorConcept<_OutputIterator,
4339 __typeof__(__binary_op(*__first1,*__first2))>)
4340 __glibcxx_requires_valid_range(__first1, __last1);
4342 for (; __first1 != __last1; ++__first1, (void)++__first2, ++__result)
4343 *__result = __binary_op(*__first1, *__first2);
4360 template<
typename _ForwardIterator,
typename _Tp>
4362 replace(_ForwardIterator __first, _ForwardIterator __last,
4363 const _Tp& __old_value,
const _Tp& __new_value)
4366 __glibcxx_function_requires(_Mutable_ForwardIteratorConcept<
4368 __glibcxx_function_requires(_EqualOpConcept<
4369 typename iterator_traits<_ForwardIterator>::value_type, _Tp>)
4370 __glibcxx_function_requires(_ConvertibleConcept<_Tp,
4371 typename iterator_traits<_ForwardIterator>::value_type>)
4372 __glibcxx_requires_valid_range(__first, __last);
4374 for (; __first != __last; ++__first)
4375 if (*__first == __old_value)
4376 *__first = __new_value;
4392 template<
typename _ForwardIterator,
typename _Predicate,
typename _Tp>
4394 replace_if(_ForwardIterator __first, _ForwardIterator __last,
4395 _Predicate __pred,
const _Tp& __new_value)
4398 __glibcxx_function_requires(_Mutable_ForwardIteratorConcept<
4400 __glibcxx_function_requires(_ConvertibleConcept<_Tp,
4401 typename iterator_traits<_ForwardIterator>::value_type>)
4402 __glibcxx_function_requires(_UnaryPredicateConcept<_Predicate,
4403 typename iterator_traits<_ForwardIterator>::value_type>)
4404 __glibcxx_requires_valid_range(__first, __last);
4406 for (; __first != __last; ++__first)
4407 if (__pred(*__first))
4408 *__first = __new_value;
4424 template<
typename _ForwardIterator,
typename _Generator>
4426 generate(_ForwardIterator __first, _ForwardIterator __last,
4430 __glibcxx_function_requires(_ForwardIteratorConcept<_ForwardIterator>)
4431 __glibcxx_function_requires(_GeneratorConcept<_Generator,
4432 typename iterator_traits<_ForwardIterator>::value_type>)
4433 __glibcxx_requires_valid_range(__first, __last);
4435 for (; __first != __last; ++__first)
4455 template<
typename _OutputIterator,
typename _Size,
typename _Generator>
4457 generate_n(_OutputIterator __first, _Size __n, _Generator __gen)
4460 __glibcxx_function_requires(_OutputIteratorConcept<_OutputIterator,
4462 __typeof__(__gen())>)
4464 for (__decltype(__n + 0) __niter = __n;
4465 __niter > 0; --__niter, (void) ++__first)
4491 template<
typename _InputIterator,
typename _OutputIterator>
4492 inline _OutputIterator
4493 unique_copy(_InputIterator __first, _InputIterator __last,
4494 _OutputIterator __result)
4497 __glibcxx_function_requires(_InputIteratorConcept<_InputIterator>)
4498 __glibcxx_function_requires(_OutputIteratorConcept<_OutputIterator,
4499 typename iterator_traits<_InputIterator>::value_type>)
4500 __glibcxx_function_requires(_EqualityComparableConcept<
4501 typename iterator_traits<_InputIterator>::value_type>)
4502 __glibcxx_requires_valid_range(__first, __last);
4504 if (__first == __last)
4507 __gnu_cxx::__ops::__iter_equal_to_iter(),
4531 template<
typename _InputIterator,
typename _OutputIterator,
4532 typename _BinaryPredicate>
4533 inline _OutputIterator
4534 unique_copy(_InputIterator __first, _InputIterator __last,
4535 _OutputIterator __result,
4536 _BinaryPredicate __binary_pred)
4539 __glibcxx_function_requires(_InputIteratorConcept<_InputIterator>)
4540 __glibcxx_function_requires(_OutputIteratorConcept<_OutputIterator,
4541 typename iterator_traits<_InputIterator>::value_type>)
4542 __glibcxx_requires_valid_range(__first, __last);
4544 if (__first == __last)
4547 __gnu_cxx::__ops::__iter_comp_iter(__binary_pred),
4564 template<
typename _RandomAccessIterator>
4566 random_shuffle(_RandomAccessIterator __first, _RandomAccessIterator __last)
4569 __glibcxx_function_requires(_Mutable_RandomAccessIteratorConcept<
4570 _RandomAccessIterator>)
4571 __glibcxx_requires_valid_range(__first, __last);
4573 if (__first != __last)
4574 for (_RandomAccessIterator __i = __first + 1; __i != __last; ++__i)
4577 _RandomAccessIterator __j = __first
4578 + std::rand() % ((__i - __first) + 1);
4580 std::iter_swap(__i, __j);
4599 template<
typename _RandomAccessIterator,
typename _RandomNumberGenerator>
4601 random_shuffle(_RandomAccessIterator __first, _RandomAccessIterator __last,
4602 #
if __cplusplus >= 201103L
4603 _RandomNumberGenerator&& __rand)
4605 _RandomNumberGenerator& __rand)
4609 __glibcxx_function_requires(_Mutable_RandomAccessIteratorConcept<
4610 _RandomAccessIterator>)
4611 __glibcxx_requires_valid_range(__first, __last);
4613 if (__first == __last)
4615 for (_RandomAccessIterator __i = __first + 1; __i != __last; ++__i)
4617 _RandomAccessIterator __j = __first + __rand((__i - __first) + 1);
4639 template<
typename _ForwardIterator,
typename _Predicate>
4640 inline _ForwardIterator
4641 partition(_ForwardIterator __first, _ForwardIterator __last,
4645 __glibcxx_function_requires(_Mutable_ForwardIteratorConcept<
4647 __glibcxx_function_requires(_UnaryPredicateConcept<_Predicate,
4648 typename iterator_traits<_ForwardIterator>::value_type>)
4649 __glibcxx_requires_valid_range(__first, __last);
4672 template<
typename _RandomAccessIterator>
4674 partial_sort(_RandomAccessIterator __first,
4675 _RandomAccessIterator __middle,
4676 _RandomAccessIterator __last)
4679 __glibcxx_function_requires(_Mutable_RandomAccessIteratorConcept<
4680 _RandomAccessIterator>)
4681 __glibcxx_function_requires(_LessThanComparableConcept<
4682 typename iterator_traits<_RandomAccessIterator>::value_type>)
4683 __glibcxx_requires_valid_range(__first, __middle);
4684 __glibcxx_requires_valid_range(__middle, __last);
4685 __glibcxx_requires_irreflexive(__first, __last);
4687 std::__partial_sort(__first, __middle, __last,
4688 __gnu_cxx::__ops::__iter_less_iter());
4710 template<
typename _RandomAccessIterator,
typename _Compare>
4712 partial_sort(_RandomAccessIterator __first,
4713 _RandomAccessIterator __middle,
4714 _RandomAccessIterator __last,
4718 __glibcxx_function_requires(_Mutable_RandomAccessIteratorConcept<
4719 _RandomAccessIterator>)
4720 __glibcxx_function_requires(_BinaryPredicateConcept<_Compare,
4721 typename iterator_traits<_RandomAccessIterator>::value_type,
4722 typename iterator_traits<_RandomAccessIterator>::value_type>)
4723 __glibcxx_requires_valid_range(__first, __middle);
4724 __glibcxx_requires_valid_range(__middle, __last);
4725 __glibcxx_requires_irreflexive_pred(__first, __last, __comp);
4727 std::__partial_sort(__first, __middle, __last,
4728 __gnu_cxx::__ops::__iter_comp_iter(__comp));
4746 template<
typename _RandomAccessIterator>
4748 nth_element(_RandomAccessIterator __first, _RandomAccessIterator __nth,
4749 _RandomAccessIterator __last)
4752 __glibcxx_function_requires(_Mutable_RandomAccessIteratorConcept<
4753 _RandomAccessIterator>)
4754 __glibcxx_function_requires(_LessThanComparableConcept<
4755 typename iterator_traits<_RandomAccessIterator>::value_type>)
4756 __glibcxx_requires_valid_range(__first, __nth);
4757 __glibcxx_requires_valid_range(__nth, __last);
4758 __glibcxx_requires_irreflexive(__first, __last);
4760 if (__first == __last || __nth == __last)
4763 std::__introselect(__first, __nth, __last,
4765 __gnu_cxx::__ops::__iter_less_iter());
4785 template<
typename _RandomAccessIterator,
typename _Compare>
4787 nth_element(_RandomAccessIterator __first, _RandomAccessIterator __nth,
4788 _RandomAccessIterator __last, _Compare __comp)
4791 __glibcxx_function_requires(_Mutable_RandomAccessIteratorConcept<
4792 _RandomAccessIterator>)
4793 __glibcxx_function_requires(_BinaryPredicateConcept<_Compare,
4794 typename iterator_traits<_RandomAccessIterator>::value_type,
4795 typename iterator_traits<_RandomAccessIterator>::value_type>)
4796 __glibcxx_requires_valid_range(__first, __nth);
4797 __glibcxx_requires_valid_range(__nth, __last);
4798 __glibcxx_requires_irreflexive_pred(__first, __last, __comp);
4800 if (__first == __last || __nth == __last)
4803 std::__introselect(__first, __nth, __last,
4805 __gnu_cxx::__ops::__iter_comp_iter(__comp));
4822 template<
typename _RandomAccessIterator>
4824 sort(_RandomAccessIterator __first, _RandomAccessIterator __last)
4827 __glibcxx_function_requires(_Mutable_RandomAccessIteratorConcept<
4828 _RandomAccessIterator>)
4829 __glibcxx_function_requires(_LessThanComparableConcept<
4830 typename iterator_traits<_RandomAccessIterator>::value_type>)
4831 __glibcxx_requires_valid_range(__first, __last);
4832 __glibcxx_requires_irreflexive(__first, __last);
4834 std::__sort(__first, __last, __gnu_cxx::__ops::__iter_less_iter());
4852 template<
typename _RandomAccessIterator,
typename _Compare>
4854 sort(_RandomAccessIterator __first, _RandomAccessIterator __last,
4858 __glibcxx_function_requires(_Mutable_RandomAccessIteratorConcept<
4859 _RandomAccessIterator>)
4860 __glibcxx_function_requires(_BinaryPredicateConcept<_Compare,
4861 typename iterator_traits<_RandomAccessIterator>::value_type,
4862 typename iterator_traits<_RandomAccessIterator>::value_type>)
4863 __glibcxx_requires_valid_range(__first, __last);
4864 __glibcxx_requires_irreflexive_pred(__first, __last, __comp);
4866 std::__sort(__first, __last, __gnu_cxx::__ops::__iter_comp_iter(__comp));
4869 template<
typename _InputIterator1,
typename _InputIterator2,
4870 typename _OutputIterator,
typename _Compare>
4872 __merge(_InputIterator1 __first1, _InputIterator1 __last1,
4873 _InputIterator2 __first2, _InputIterator2 __last2,
4874 _OutputIterator __result, _Compare __comp)
4876 while (__first1 != __last1 && __first2 != __last2)
4878 if (__comp(__first2, __first1))
4880 *__result = *__first2;
4885 *__result = *__first1;
4890 return std::copy(__first2, __last2,
4891 std::copy(__first1, __last1, __result));
4913 template<
typename _InputIterator1,
typename _InputIterator2,
4914 typename _OutputIterator>
4915 inline _OutputIterator
4916 merge(_InputIterator1 __first1, _InputIterator1 __last1,
4917 _InputIterator2 __first2, _InputIterator2 __last2,
4918 _OutputIterator __result)
4921 __glibcxx_function_requires(_InputIteratorConcept<_InputIterator1>)
4922 __glibcxx_function_requires(_InputIteratorConcept<_InputIterator2>)
4923 __glibcxx_function_requires(_OutputIteratorConcept<_OutputIterator,
4924 typename iterator_traits<_InputIterator1>::value_type>)
4925 __glibcxx_function_requires(_OutputIteratorConcept<_OutputIterator,
4926 typename iterator_traits<_InputIterator2>::value_type>)
4927 __glibcxx_function_requires(_LessThanOpConcept<
4928 typename iterator_traits<_InputIterator2>::value_type,
4929 typename iterator_traits<_InputIterator1>::value_type>)
4930 __glibcxx_requires_sorted_set(__first1, __last1, __first2);
4931 __glibcxx_requires_sorted_set(__first2, __last2, __first1);
4932 __glibcxx_requires_irreflexive2(__first1, __last1);
4933 __glibcxx_requires_irreflexive2(__first2, __last2);
4935 return _GLIBCXX_STD_A::__merge(__first1, __last1,
4936 __first2, __last2, __result,
4937 __gnu_cxx::__ops::__iter_less_iter());
4963 template<
typename _InputIterator1,
typename _InputIterator2,
4964 typename _OutputIterator,
typename _Compare>
4965 inline _OutputIterator
4966 merge(_InputIterator1 __first1, _InputIterator1 __last1,
4967 _InputIterator2 __first2, _InputIterator2 __last2,
4968 _OutputIterator __result, _Compare __comp)
4971 __glibcxx_function_requires(_InputIteratorConcept<_InputIterator1>)
4972 __glibcxx_function_requires(_InputIteratorConcept<_InputIterator2>)
4973 __glibcxx_function_requires(_OutputIteratorConcept<_OutputIterator,
4974 typename iterator_traits<_InputIterator1>::value_type>)
4975 __glibcxx_function_requires(_OutputIteratorConcept<_OutputIterator,
4976 typename iterator_traits<_InputIterator2>::value_type>)
4977 __glibcxx_function_requires(_BinaryPredicateConcept<_Compare,
4978 typename iterator_traits<_InputIterator2>::value_type,
4979 typename iterator_traits<_InputIterator1>::value_type>)
4980 __glibcxx_requires_sorted_set_pred(__first1, __last1, __first2, __comp);
4981 __glibcxx_requires_sorted_set_pred(__first2, __last2, __first1, __comp);
4982 __glibcxx_requires_irreflexive_pred2(__first1, __last1, __comp);
4983 __glibcxx_requires_irreflexive_pred2(__first2, __last2, __comp);
4985 return _GLIBCXX_STD_A::__merge(__first1, __last1,
4986 __first2, __last2, __result,
4987 __gnu_cxx::__ops::__iter_comp_iter(__comp));
4990 template<
typename _RandomAccessIterator,
typename _Compare>
4992 __stable_sort(_RandomAccessIterator __first, _RandomAccessIterator __last,
4995 typedef typename iterator_traits<_RandomAccessIterator>::value_type
4997 typedef typename iterator_traits<_RandomAccessIterator>::difference_type
5000 typedef _Temporary_buffer<_RandomAccessIterator, _ValueType> _TmpBuf;
5001 _TmpBuf __buf(__first, __last);
5003 if (__buf.begin() == 0)
5006 std::__stable_sort_adaptive(__first, __last, __buf.begin(),
5007 _DistanceType(__buf.size()), __comp);
5027 template<
typename _RandomAccessIterator>
5029 stable_sort(_RandomAccessIterator __first, _RandomAccessIterator __last)
5032 __glibcxx_function_requires(_Mutable_RandomAccessIteratorConcept<
5033 _RandomAccessIterator>)
5034 __glibcxx_function_requires(_LessThanComparableConcept<
5035 typename iterator_traits<_RandomAccessIterator>::value_type>)
5036 __glibcxx_requires_valid_range(__first, __last);
5037 __glibcxx_requires_irreflexive(__first, __last);
5039 _GLIBCXX_STD_A::__stable_sort(__first, __last,
5040 __gnu_cxx::__ops::__iter_less_iter());
5061 template<
typename _RandomAccessIterator,
typename _Compare>
5063 stable_sort(_RandomAccessIterator __first, _RandomAccessIterator __last,
5067 __glibcxx_function_requires(_Mutable_RandomAccessIteratorConcept<
5068 _RandomAccessIterator>)
5069 __glibcxx_function_requires(_BinaryPredicateConcept<_Compare,
5070 typename iterator_traits<_RandomAccessIterator>::value_type,
5071 typename iterator_traits<_RandomAccessIterator>::value_type>)
5072 __glibcxx_requires_valid_range(__first, __last);
5073 __glibcxx_requires_irreflexive_pred(__first, __last, __comp);
5075 _GLIBCXX_STD_A::__stable_sort(__first, __last,
5076 __gnu_cxx::__ops::__iter_comp_iter(__comp));
5079 template<
typename _InputIterator1,
typename _InputIterator2,
5080 typename _OutputIterator,
5083 __set_union(_InputIterator1 __first1, _InputIterator1 __last1,
5084 _InputIterator2 __first2, _InputIterator2 __last2,
5085 _OutputIterator __result, _Compare __comp)
5087 while (__first1 != __last1 && __first2 != __last2)
5089 if (__comp(__first1, __first2))
5091 *__result = *__first1;
5094 else if (__comp(__first2, __first1))
5096 *__result = *__first2;
5101 *__result = *__first1;
5107 return std::copy(__first2, __last2,
5108 std::copy(__first1, __last1, __result));
5130 template<
typename _InputIterator1,
typename _InputIterator2,
5131 typename _OutputIterator>
5132 inline _OutputIterator
5133 set_union(_InputIterator1 __first1, _InputIterator1 __last1,
5134 _InputIterator2 __first2, _InputIterator2 __last2,
5135 _OutputIterator __result)
5138 __glibcxx_function_requires(_InputIteratorConcept<_InputIterator1>)
5139 __glibcxx_function_requires(_InputIteratorConcept<_InputIterator2>)
5140 __glibcxx_function_requires(_OutputIteratorConcept<_OutputIterator,
5141 typename iterator_traits<_InputIterator1>::value_type>)
5142 __glibcxx_function_requires(_OutputIteratorConcept<_OutputIterator,
5143 typename iterator_traits<_InputIterator2>::value_type>)
5144 __glibcxx_function_requires(_LessThanOpConcept<
5145 typename iterator_traits<_InputIterator1>::value_type,
5146 typename iterator_traits<_InputIterator2>::value_type>)
5147 __glibcxx_function_requires(_LessThanOpConcept<
5148 typename iterator_traits<_InputIterator2>::value_type,
5149 typename iterator_traits<_InputIterator1>::value_type>)
5150 __glibcxx_requires_sorted_set(__first1, __last1, __first2);
5151 __glibcxx_requires_sorted_set(__first2, __last2, __first1);
5152 __glibcxx_requires_irreflexive2(__first1, __last1);
5153 __glibcxx_requires_irreflexive2(__first2, __last2);
5155 return _GLIBCXX_STD_A::__set_union(__first1, __last1,
5156 __first2, __last2, __result,
5157 __gnu_cxx::__ops::__iter_less_iter());
5180 template<
typename _InputIterator1,
typename _InputIterator2,
5181 typename _OutputIterator,
typename _Compare>
5182 inline _OutputIterator
5183 set_union(_InputIterator1 __first1, _InputIterator1 __last1,
5184 _InputIterator2 __first2, _InputIterator2 __last2,
5185 _OutputIterator __result, _Compare __comp)
5188 __glibcxx_function_requires(_InputIteratorConcept<_InputIterator1>)
5189 __glibcxx_function_requires(_InputIteratorConcept<_InputIterator2>)
5190 __glibcxx_function_requires(_OutputIteratorConcept<_OutputIterator,
5191 typename iterator_traits<_InputIterator1>::value_type>)
5192 __glibcxx_function_requires(_OutputIteratorConcept<_OutputIterator,
5193 typename iterator_traits<_InputIterator2>::value_type>)
5194 __glibcxx_function_requires(_BinaryPredicateConcept<_Compare,
5195 typename iterator_traits<_InputIterator1>::value_type,
5196 typename iterator_traits<_InputIterator2>::value_type>)
5197 __glibcxx_function_requires(_BinaryPredicateConcept<_Compare,
5198 typename iterator_traits<_InputIterator2>::value_type,
5199 typename iterator_traits<_InputIterator1>::value_type>)
5200 __glibcxx_requires_sorted_set_pred(__first1, __last1, __first2, __comp);
5201 __glibcxx_requires_sorted_set_pred(__first2, __last2, __first1, __comp);
5202 __glibcxx_requires_irreflexive_pred2(__first1, __last1, __comp);
5203 __glibcxx_requires_irreflexive_pred2(__first2, __last2, __comp);
5205 return _GLIBCXX_STD_A::__set_union(__first1, __last1,
5206 __first2, __last2, __result,
5207 __gnu_cxx::__ops::__iter_comp_iter(__comp));
5210 template<
typename _InputIterator1,
typename _InputIterator2,
5211 typename _OutputIterator,
5214 __set_intersection(_InputIterator1 __first1, _InputIterator1 __last1,
5215 _InputIterator2 __first2, _InputIterator2 __last2,
5216 _OutputIterator __result, _Compare __comp)
5218 while (__first1 != __last1 && __first2 != __last2)
5219 if (__comp(__first1, __first2))
5221 else if (__comp(__first2, __first1))
5225 *__result = *__first1;
5251 template<
typename _InputIterator1,
typename _InputIterator2,
5252 typename _OutputIterator>
5253 inline _OutputIterator
5254 set_intersection(_InputIterator1 __first1, _InputIterator1 __last1,
5255 _InputIterator2 __first2, _InputIterator2 __last2,
5256 _OutputIterator __result)
5259 __glibcxx_function_requires(_InputIteratorConcept<_InputIterator1>)
5260 __glibcxx_function_requires(_InputIteratorConcept<_InputIterator2>)
5261 __glibcxx_function_requires(_OutputIteratorConcept<_OutputIterator,
5262 typename iterator_traits<_InputIterator1>::value_type>)
5263 __glibcxx_function_requires(_LessThanOpConcept<
5264 typename iterator_traits<_InputIterator1>::value_type,
5265 typename iterator_traits<_InputIterator2>::value_type>)
5266 __glibcxx_function_requires(_LessThanOpConcept<
5267 typename iterator_traits<_InputIterator2>::value_type,
5268 typename iterator_traits<_InputIterator1>::value_type>)
5269 __glibcxx_requires_sorted_set(__first1, __last1, __first2);
5270 __glibcxx_requires_sorted_set(__first2, __last2, __first1);
5271 __glibcxx_requires_irreflexive2(__first1, __last1);
5272 __glibcxx_requires_irreflexive2(__first2, __last2);
5274 return _GLIBCXX_STD_A::__set_intersection(__first1, __last1,
5275 __first2, __last2, __result,
5276 __gnu_cxx::__ops::__iter_less_iter());
5300 template<
typename _InputIterator1,
typename _InputIterator2,
5301 typename _OutputIterator,
typename _Compare>
5302 inline _OutputIterator
5303 set_intersection(_InputIterator1 __first1, _InputIterator1 __last1,
5304 _InputIterator2 __first2, _InputIterator2 __last2,
5305 _OutputIterator __result, _Compare __comp)
5308 __glibcxx_function_requires(_InputIteratorConcept<_InputIterator1>)
5309 __glibcxx_function_requires(_InputIteratorConcept<_InputIterator2>)
5310 __glibcxx_function_requires(_OutputIteratorConcept<_OutputIterator,
5311 typename iterator_traits<_InputIterator1>::value_type>)
5312 __glibcxx_function_requires(_BinaryPredicateConcept<_Compare,
5313 typename iterator_traits<_InputIterator1>::value_type,
5314 typename iterator_traits<_InputIterator2>::value_type>)
5315 __glibcxx_function_requires(_BinaryPredicateConcept<_Compare,
5316 typename iterator_traits<_InputIterator2>::value_type,
5317 typename iterator_traits<_InputIterator1>::value_type>)
5318 __glibcxx_requires_sorted_set_pred(__first1, __last1, __first2, __comp);
5319 __glibcxx_requires_sorted_set_pred(__first2, __last2, __first1, __comp);
5320 __glibcxx_requires_irreflexive_pred2(__first1, __last1, __comp);
5321 __glibcxx_requires_irreflexive_pred2(__first2, __last2, __comp);
5323 return _GLIBCXX_STD_A::__set_intersection(__first1, __last1,
5324 __first2, __last2, __result,
5325 __gnu_cxx::__ops::__iter_comp_iter(__comp));
5328 template<
typename _InputIterator1,
typename _InputIterator2,
5329 typename _OutputIterator,
5332 __set_difference(_InputIterator1 __first1, _InputIterator1 __last1,
5333 _InputIterator2 __first2, _InputIterator2 __last2,
5334 _OutputIterator __result, _Compare __comp)
5336 while (__first1 != __last1 && __first2 != __last2)
5337 if (__comp(__first1, __first2))
5339 *__result = *__first1;
5343 else if (__comp(__first2, __first1))
5350 return std::copy(__first1, __last1, __result);
5373 template<
typename _InputIterator1,
typename _InputIterator2,
5374 typename _OutputIterator>
5375 inline _OutputIterator
5376 set_difference(_InputIterator1 __first1, _InputIterator1 __last1,
5377 _InputIterator2 __first2, _InputIterator2 __last2,
5378 _OutputIterator __result)
5381 __glibcxx_function_requires(_InputIteratorConcept<_InputIterator1>)
5382 __glibcxx_function_requires(_InputIteratorConcept<_InputIterator2>)
5383 __glibcxx_function_requires(_OutputIteratorConcept<_OutputIterator,
5384 typename iterator_traits<_InputIterator1>::value_type>)
5385 __glibcxx_function_requires(_LessThanOpConcept<
5386 typename iterator_traits<_InputIterator1>::value_type,
5387 typename iterator_traits<_InputIterator2>::value_type>)
5388 __glibcxx_function_requires(_LessThanOpConcept<
5389 typename iterator_traits<_InputIterator2>::value_type,
5390 typename iterator_traits<_InputIterator1>::value_type>)
5391 __glibcxx_requires_sorted_set(__first1, __last1, __first2);
5392 __glibcxx_requires_sorted_set(__first2, __last2, __first1);
5393 __glibcxx_requires_irreflexive2(__first1, __last1);
5394 __glibcxx_requires_irreflexive2(__first2, __last2);
5396 return _GLIBCXX_STD_A::__set_difference(__first1, __last1,
5397 __first2, __last2, __result,
5398 __gnu_cxx::__ops::__iter_less_iter());
5424 template<
typename _InputIterator1,
typename _InputIterator2,
5425 typename _OutputIterator,
typename _Compare>
5426 inline _OutputIterator
5427 set_difference(_InputIterator1 __first1, _InputIterator1 __last1,
5428 _InputIterator2 __first2, _InputIterator2 __last2,
5429 _OutputIterator __result, _Compare __comp)
5432 __glibcxx_function_requires(_InputIteratorConcept<_InputIterator1>)
5433 __glibcxx_function_requires(_InputIteratorConcept<_InputIterator2>)
5434 __glibcxx_function_requires(_OutputIteratorConcept<_OutputIterator,
5435 typename iterator_traits<_InputIterator1>::value_type>)
5436 __glibcxx_function_requires(_BinaryPredicateConcept<_Compare,
5437 typename iterator_traits<_InputIterator1>::value_type,
5438 typename iterator_traits<_InputIterator2>::value_type>)
5439 __glibcxx_function_requires(_BinaryPredicateConcept<_Compare,
5440 typename iterator_traits<_InputIterator2>::value_type,
5441 typename iterator_traits<_InputIterator1>::value_type>)
5442 __glibcxx_requires_sorted_set_pred(__first1, __last1, __first2, __comp);
5443 __glibcxx_requires_sorted_set_pred(__first2, __last2, __first1, __comp);
5444 __glibcxx_requires_irreflexive_pred2(__first1, __last1, __comp);
5445 __glibcxx_requires_irreflexive_pred2(__first2, __last2, __comp);
5447 return _GLIBCXX_STD_A::__set_difference(__first1, __last1,
5448 __first2, __last2, __result,
5449 __gnu_cxx::__ops::__iter_comp_iter(__comp));
5452 template<
typename _InputIterator1,
typename _InputIterator2,
5453 typename _OutputIterator,
5456 __set_symmetric_difference(_InputIterator1 __first1,
5457 _InputIterator1 __last1,
5458 _InputIterator2 __first2,
5459 _InputIterator2 __last2,
5460 _OutputIterator __result,
5463 while (__first1 != __last1 && __first2 != __last2)
5464 if (__comp(__first1, __first2))
5466 *__result = *__first1;
5470 else if (__comp(__first2, __first1))
5472 *__result = *__first2;
5481 return std::copy(__first2, __last2,
5482 std::copy(__first1, __last1, __result));
5503 template<
typename _InputIterator1,
typename _InputIterator2,
5504 typename _OutputIterator>
5505 inline _OutputIterator
5506 set_symmetric_difference(_InputIterator1 __first1, _InputIterator1 __last1,
5507 _InputIterator2 __first2, _InputIterator2 __last2,
5508 _OutputIterator __result)
5511 __glibcxx_function_requires(_InputIteratorConcept<_InputIterator1>)
5512 __glibcxx_function_requires(_InputIteratorConcept<_InputIterator2>)
5513 __glibcxx_function_requires(_OutputIteratorConcept<_OutputIterator,
5514 typename iterator_traits<_InputIterator1>::value_type>)
5515 __glibcxx_function_requires(_OutputIteratorConcept<_OutputIterator,
5516 typename iterator_traits<_InputIterator2>::value_type>)
5517 __glibcxx_function_requires(_LessThanOpConcept<
5518 typename iterator_traits<_InputIterator1>::value_type,
5519 typename iterator_traits<_InputIterator2>::value_type>)
5520 __glibcxx_function_requires(_LessThanOpConcept<
5521 typename iterator_traits<_InputIterator2>::value_type,
5522 typename iterator_traits<_InputIterator1>::value_type>)
5523 __glibcxx_requires_sorted_set(__first1, __last1, __first2);
5524 __glibcxx_requires_sorted_set(__first2, __last2, __first1);
5525 __glibcxx_requires_irreflexive2(__first1, __last1);
5526 __glibcxx_requires_irreflexive2(__first2, __last2);
5528 return _GLIBCXX_STD_A::__set_symmetric_difference(__first1, __last1,
5529 __first2, __last2, __result,
5530 __gnu_cxx::__ops::__iter_less_iter());
5554 template<
typename _InputIterator1,
typename _InputIterator2,
5555 typename _OutputIterator,
typename _Compare>
5556 inline _OutputIterator
5557 set_symmetric_difference(_InputIterator1 __first1, _InputIterator1 __last1,
5558 _InputIterator2 __first2, _InputIterator2 __last2,
5559 _OutputIterator __result,
5563 __glibcxx_function_requires(_InputIteratorConcept<_InputIterator1>)
5564 __glibcxx_function_requires(_InputIteratorConcept<_InputIterator2>)
5565 __glibcxx_function_requires(_OutputIteratorConcept<_OutputIterator,
5566 typename iterator_traits<_InputIterator1>::value_type>)
5567 __glibcxx_function_requires(_OutputIteratorConcept<_OutputIterator,
5568 typename iterator_traits<_InputIterator2>::value_type>)
5569 __glibcxx_function_requires(_BinaryPredicateConcept<_Compare,
5570 typename iterator_traits<_InputIterator1>::value_type,
5571 typename iterator_traits<_InputIterator2>::value_type>)
5572 __glibcxx_function_requires(_BinaryPredicateConcept<_Compare,
5573 typename iterator_traits<_InputIterator2>::value_type,
5574 typename iterator_traits<_InputIterator1>::value_type>)
5575 __glibcxx_requires_sorted_set_pred(__first1, __last1, __first2, __comp);
5576 __glibcxx_requires_sorted_set_pred(__first2, __last2, __first1, __comp);
5577 __glibcxx_requires_irreflexive_pred2(__first1, __last1, __comp);
5578 __glibcxx_requires_irreflexive_pred2(__first2, __last2, __comp);
5580 return _GLIBCXX_STD_A::__set_symmetric_difference(__first1, __last1,
5581 __first2, __last2, __result,
5582 __gnu_cxx::__ops::__iter_comp_iter(__comp));
5585 template<
typename _ForwardIterator,
typename _Compare>
5586 _GLIBCXX14_CONSTEXPR
5588 __min_element(_ForwardIterator __first, _ForwardIterator __last,
5591 if (__first == __last)
5593 _ForwardIterator __result = __first;
5594 while (++__first != __last)
5595 if (__comp(__first, __result))
5607 template<
typename _ForwardIterator>
5608 _GLIBCXX14_CONSTEXPR
5610 inline min_element(_ForwardIterator __first, _ForwardIterator __last)
5613 __glibcxx_function_requires(_ForwardIteratorConcept<_ForwardIterator>)
5614 __glibcxx_function_requires(_LessThanComparableConcept<
5615 typename iterator_traits<_ForwardIterator>::value_type>)
5616 __glibcxx_requires_valid_range(__first, __last);
5617 __glibcxx_requires_irreflexive(__first, __last);
5619 return _GLIBCXX_STD_A::__min_element(__first, __last,
5620 __gnu_cxx::__ops::__iter_less_iter());
5632 template<
typename _ForwardIterator,
typename _Compare>
5633 _GLIBCXX14_CONSTEXPR
5634 inline _ForwardIterator
5635 min_element(_ForwardIterator __first, _ForwardIterator __last,
5639 __glibcxx_function_requires(_ForwardIteratorConcept<_ForwardIterator>)
5640 __glibcxx_function_requires(_BinaryPredicateConcept<_Compare,
5641 typename iterator_traits<_ForwardIterator>::value_type,
5642 typename iterator_traits<_ForwardIterator>::value_type>)
5643 __glibcxx_requires_valid_range(__first, __last);
5644 __glibcxx_requires_irreflexive_pred(__first, __last, __comp);
5646 return _GLIBCXX_STD_A::__min_element(__first, __last,
5647 __gnu_cxx::__ops::__iter_comp_iter(__comp));
5650 template<
typename _ForwardIterator,
typename _Compare>
5651 _GLIBCXX14_CONSTEXPR
5653 __max_element(_ForwardIterator __first, _ForwardIterator __last,
5656 if (__first == __last)
return __first;
5657 _ForwardIterator __result = __first;
5658 while (++__first != __last)
5659 if (__comp(__result, __first))
5671 template<
typename _ForwardIterator>
5672 _GLIBCXX14_CONSTEXPR
5673 inline _ForwardIterator
5674 max_element(_ForwardIterator __first, _ForwardIterator __last)
5677 __glibcxx_function_requires(_ForwardIteratorConcept<_ForwardIterator>)
5678 __glibcxx_function_requires(_LessThanComparableConcept<
5679 typename iterator_traits<_ForwardIterator>::value_type>)
5680 __glibcxx_requires_valid_range(__first, __last);
5681 __glibcxx_requires_irreflexive(__first, __last);
5683 return _GLIBCXX_STD_A::__max_element(__first, __last,
5684 __gnu_cxx::__ops::__iter_less_iter());
5696 template<
typename _ForwardIterator,
typename _Compare>
5697 _GLIBCXX14_CONSTEXPR
5698 inline _ForwardIterator
5699 max_element(_ForwardIterator __first, _ForwardIterator __last,
5703 __glibcxx_function_requires(_ForwardIteratorConcept<_ForwardIterator>)
5704 __glibcxx_function_requires(_BinaryPredicateConcept<_Compare,
5705 typename iterator_traits<_ForwardIterator>::value_type,
5706 typename iterator_traits<_ForwardIterator>::value_type>)
5707 __glibcxx_requires_valid_range(__first, __last);
5708 __glibcxx_requires_irreflexive_pred(__first, __last, __comp);
5710 return _GLIBCXX_STD_A::__max_element(__first, __last,
5711 __gnu_cxx::__ops::__iter_comp_iter(__comp));
5714 #if __cplusplus >= 201402L 5716 template<
typename _InputIterator,
typename _RandomAccessIterator,
5717 typename _Size,
typename _UniformRandomBitGenerator>
5718 _RandomAccessIterator
5721 _Size __n, _UniformRandomBitGenerator&& __g)
5724 using __param_type =
typename __distrib_type::param_type;
5725 __distrib_type __d{};
5726 _Size __sample_sz = 0;
5727 while (__first != __last && __sample_sz != __n)
5729 __out[__sample_sz++] = *__first;
5732 for (
auto __pop_sz = __sample_sz; __first != __last;
5733 ++__first, (void) ++__pop_sz)
5735 const auto __k = __d(__g, __param_type{0, __pop_sz});
5737 __out[__k] = *__first;
5739 return __out + __sample_sz;
5743 template<
typename _ForwardIterator,
typename _OutputIterator,
typename _Cat,
5744 typename _Size,
typename _UniformRandomBitGenerator>
5746 __sample(_ForwardIterator __first, _ForwardIterator __last,
5748 _OutputIterator __out, _Cat,
5749 _Size __n, _UniformRandomBitGenerator&& __g)
5752 using __param_type =
typename __distrib_type::param_type;
5757 __distrib_type __d{};
5759 __n =
std::min(__n, __unsampled_sz);
5764 const __uc_type __urngrange = __g.max() - __g.min();
5765 if (__urngrange / __uc_type(__unsampled_sz) >= __uc_type(__unsampled_sz))
5769 while (__n != 0 && __unsampled_sz >= 2)
5775 if (__p.
first < __n)
5777 *__out++ = *__first;
5783 if (__n == 0)
break;
5788 *__out++ = *__first;
5798 for (; __n != 0; ++__first)
5799 if (__d(__g, __param_type{0, --__unsampled_sz}) < __n)
5801 *__out++ = *__first;
5807 #if __cplusplus > 201402L 5808 #define __cpp_lib_sample 201603 5810 template<
typename _PopulationIterator,
typename _SampleIterator,
5811 typename _Distance,
typename _UniformRandomBitGenerator>
5813 sample(_PopulationIterator __first, _PopulationIterator __last,
5814 _SampleIterator __out, _Distance __n,
5815 _UniformRandomBitGenerator&& __g)
5817 using __pop_cat =
typename 5818 std::iterator_traits<_PopulationIterator>::iterator_category;
5819 using __samp_cat =
typename 5820 std::iterator_traits<_SampleIterator>::iterator_category;
5823 __or_<is_convertible<__pop_cat, forward_iterator_tag>,
5824 is_convertible<__samp_cat, random_access_iterator_tag>>::value,
5825 "output range must use a RandomAccessIterator when input range" 5826 " does not meet the ForwardIterator requirements");
5828 static_assert(is_integral<_Distance>::value,
5829 "sample size must be an integer type");
5831 typename iterator_traits<_PopulationIterator>::difference_type __d = __n;
5833 __sample(__first, __last, __pop_cat{}, __out, __samp_cat{}, __d,
5834 std::forward<_UniformRandomBitGenerator>(__g));
5839 _GLIBCXX_END_NAMESPACE_ALGO
5840 _GLIBCXX_END_NAMESPACE_VERSION
Struct holding two objects of arbitrary type.
Bidirectional iterators support a superset of forward iterator operations.
_InputIterator find_if_not(_InputIterator __first, _InputIterator __last, _Predicate __pred)
Find the first element in a sequence for which a predicate is false.
_RandomAccessIterator __unguarded_partition_pivot(_RandomAccessIterator __first, _RandomAccessIterator __last, _Compare __comp)
This is a helper function...
_GLIBCXX17_CONSTEXPR iterator_traits< _InputIterator >::difference_type distance(_InputIterator __first, _InputIterator __last)
A generalization of pointer arithmetic.
void __unguarded_linear_insert(_RandomAccessIterator __last, _Compare __comp)
This is a helper function for the sort routine.
void __move_merge_adaptive(_InputIterator1 __first1, _InputIterator1 __last1, _InputIterator2 __first2, _InputIterator2 __last2, _OutputIterator __result, _Compare __comp)
This is a helper function for the __merge_adaptive routines.
_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...
typename make_unsigned< _Tp >::type make_unsigned_t
Alias template for make_unsigned.
bool none_of(_InputIterator __first, _InputIterator __last, _Predicate __pred)
Checks that a predicate is false for all the elements of a sequence.
_ForwardIterator __rotate(_ForwardIterator __first, _ForwardIterator __middle, _ForwardIterator __last, forward_iterator_tag)
This is a helper function for the rotate algorithm.
_ForwardIterator2 swap_ranges(_ForwardIterator1 __first1, _ForwardIterator1 __last1, _ForwardIterator2 __first2)
Swap the elements of two sequences.
Forward iterators support a superset of input iterator operations.
void __move_median_to_first(_Iterator __result, _Iterator __a, _Iterator __b, _Iterator __c, _Compare __comp)
Swaps the median value of *__a, *__b and *__c under __comp to *__result.
_OutputIterator __sample(_ForwardIterator __first, _ForwardIterator __last, forward_iterator_tag, _OutputIterator __out, _Cat, _Size __n, _UniformRandomBitGenerator &&__g)
Selection sampling algorithm.
void __reverse(_BidirectionalIterator __first, _BidirectionalIterator __last, bidirectional_iterator_tag)
_GLIBCXX17_CONSTEXPR void advance(_InputIterator &__i, _Distance __n)
A generalization of pointer arithmetic.
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.
_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.
_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(__...
_RandomAccessIterator __unguarded_partition(_RandomAccessIterator __first, _RandomAccessIterator __last, _RandomAccessIterator __pivot, _Compare __comp)
This is a helper function...
_ForwardIterator is_sorted_until(_ForwardIterator __first, _ForwardIterator __last, _Compare __comp)
Determines the end of a sorted sequence using comparison functor.
_InputIterator __find_if_not(_InputIterator __first, _InputIterator __last, _Predicate __pred)
Provided for stable_partition to use.
void __inplace_stable_sort(_RandomAccessIterator __first, _RandomAccessIterator __last, _Compare __comp)
This is a helper function for the stable sorting routines.
ISO C++ entities toplevel namespace is std.
_GLIBCXX14_CONSTEXPR _ForwardIterator min_element(_ForwardIterator __first, _ForwardIterator __last, _Compare __comp)
Return the minimum element in a range using comparison functor.
_GLIBCXX14_CONSTEXPR const _Tp & min(const _Tp &, const _Tp &)
This does what you think it does.
pair< _IntType, _IntType > __gen_two_uniform_ints(_IntType __b0, _IntType __b1, _UniformRandomBitGenerator &&__g)
Generate two uniformly distributed integers using a single distribution invocation.
_ForwardIterator rotate(_ForwardIterator __first, _ForwardIterator __middle, _ForwardIterator __last)
Rotate the elements of a sequence.
void __introsort_loop(_RandomAccessIterator __first, _RandomAccessIterator __last, _Size __depth_limit, _Compare __comp)
This is a helper function for the sort routine.
_InputIterator find_if(_InputIterator __first, _InputIterator __last, _Predicate __pred)
Find the first element in a sequence for which a predicate is true.
constexpr iterator_traits< _Iter >::iterator_category __iterator_category(const _Iter &)
_GLIBCXX14_CONSTEXPR pair< const _Tp &, const _Tp & > minmax(const _Tp &, const _Tp &)
Determines min and max at once as an ordered pair.
void __merge_adaptive(_BidirectionalIterator __first, _BidirectionalIterator __middle, _BidirectionalIterator __last, _Distance __len1, _Distance __len2, _Pointer __buffer, _Distance __buffer_size, _Compare __comp)
This is a helper function for the merge routines.
void iter_swap(_ForwardIterator1 __a, _ForwardIterator2 __b)
Swaps the contents of two iterators.
_OutputIterator __move_merge(_InputIterator __first1, _InputIterator __last1, _InputIterator __first2, _InputIterator __last2, _OutputIterator __result, _Compare __comp)
This is a helper function for the __merge_sort_loop routines.
void __heap_select(_RandomAccessIterator __first, _RandomAccessIterator __middle, _RandomAccessIterator __last, _Compare __comp)
This is a helper function for the sort routines.
constexpr int __lg(int __n)
This is a helper function for the sort routines and for random.tcc.
_InputIterator __find_if(_InputIterator __first, _InputIterator __last, _Predicate __pred, input_iterator_tag)
This is an overload used by find algos for the Input Iterator case.
Random-access iterators support a superset of bidirectional iterator operations.
_ForwardIterator __partition(_ForwardIterator __first, _ForwardIterator __last, _Predicate __pred, forward_iterator_tag)
This is a helper function...
_T1 first
second_type is the second bound type
_OutputIterator __unique_copy(_ForwardIterator __first, _ForwardIterator __last, _OutputIterator __result, _BinaryPredicate __binary_pred, forward_iterator_tag, output_iterator_tag)
_RandomAccessIterator __sample(_InputIterator __first, _InputIterator __last, input_iterator_tag, _RandomAccessIterator __out, random_access_iterator_tag, _Size __n, _UniformRandomBitGenerator &&__g)
Reservoir sampling algorithm.
Uniform discrete distribution for random numbers. A discrete random distribution on the range with e...
_GLIBCXX14_CONSTEXPR _ForwardIterator max_element(_ForwardIterator __first, _ForwardIterator __last, _Compare __comp)
Return the maximum element in a range using comparison functor.
_T2 second
first is a copy of the first object
typename remove_reference< _Tp >::type remove_reference_t
Alias template for remove_reference.
void __move_merge_adaptive_backward(_BidirectionalIterator1 __first1, _BidirectionalIterator1 __last1, _BidirectionalIterator2 __first2, _BidirectionalIterator2 __last2, _BidirectionalIterator3 __result, _Compare __comp)
This is a helper function for the __merge_adaptive routines.
void __insertion_sort(_RandomAccessIterator __first, _RandomAccessIterator __last, _Compare __comp)
This is a helper function for the sort routine.
_GLIBCXX14_CONSTEXPR 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.
Marking output iterators.
_EuclideanRingElement __gcd(_EuclideanRingElement __m, _EuclideanRingElement __n)
void __final_insertion_sort(_RandomAccessIterator __first, _RandomAccessIterator __last, _Compare __comp)
This is a helper function for the sort routine.
void __unguarded_insertion_sort(_RandomAccessIterator __first, _RandomAccessIterator __last, _Compare __comp)
This is a helper function for the sort routine.
typename common_type< _Tp... >::type common_type_t
Alias template for common_type.
_GLIBCXX14_CONSTEXPR const _Tp & max(const _Tp &, const _Tp &)
This does what you think it does.
_ForwardIterator __search_n_aux(_ForwardIterator __first, _ForwardIterator __last, _Integer __count, _UnaryPredicate __unary_pred, std::forward_iterator_tag)
void __merge_without_buffer(_BidirectionalIterator __first, _BidirectionalIterator __middle, _BidirectionalIterator __last, _Distance __len1, _Distance __len2, _Compare __comp)
This is a helper function for the merge routines.