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, ++__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,
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,
370 _BinaryPredicate __comp)
373 __glibcxx_function_requires(_BidirectionalIteratorConcept<
374 _BidirectionalIterator1>)
375 __glibcxx_function_requires(_BidirectionalIteratorConcept<
376 _BidirectionalIterator2>)
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,
598 template<
typename _ForwardIterator,
typename _Predicate>
600 partition_point(_ForwardIterator __first, _ForwardIterator __last,
604 __glibcxx_function_requires(_ForwardIteratorConcept<_ForwardIterator>)
605 __glibcxx_function_requires(_UnaryPredicateConcept<_Predicate,
606 typename iterator_traits<_ForwardIterator>::value_type>)
609 __glibcxx_requires_valid_range(__first, __last);
611 typedef typename iterator_traits<_ForwardIterator>::difference_type
615 _DistanceType __half;
616 _ForwardIterator __middle;
623 if (__pred(*__middle))
627 __len = __len - __half - 1;
636 template<
typename _InputIterator,
typename _OutputIterator,
639 __remove_copy_if(_InputIterator __first, _InputIterator __last,
640 _OutputIterator __result, _Predicate __pred)
642 for (; __first != __last; ++__first)
643 if (!__pred(__first))
645 *__result = *__first;
665 template<
typename _InputIterator,
typename _OutputIterator,
typename _Tp>
666 inline _OutputIterator
667 remove_copy(_InputIterator __first, _InputIterator __last,
668 _OutputIterator __result,
const _Tp& __value)
671 __glibcxx_function_requires(_InputIteratorConcept<_InputIterator>)
672 __glibcxx_function_requires(_OutputIteratorConcept<_OutputIterator,
673 typename iterator_traits<_InputIterator>::value_type>)
674 __glibcxx_function_requires(_EqualOpConcept<
675 typename iterator_traits<_InputIterator>::value_type, _Tp>)
676 __glibcxx_requires_valid_range(__first, __last);
678 return std::__remove_copy_if(__first, __last, __result,
679 __gnu_cxx::__ops::__iter_equals_val(__value));
697 template<
typename _InputIterator,
typename _OutputIterator,
699 inline _OutputIterator
700 remove_copy_if(_InputIterator __first, _InputIterator __last,
701 _OutputIterator __result, _Predicate __pred)
704 __glibcxx_function_requires(_InputIteratorConcept<_InputIterator>)
705 __glibcxx_function_requires(_OutputIteratorConcept<_OutputIterator,
706 typename iterator_traits<_InputIterator>::value_type>)
707 __glibcxx_function_requires(_UnaryPredicateConcept<_Predicate,
708 typename iterator_traits<_InputIterator>::value_type>)
709 __glibcxx_requires_valid_range(__first, __last);
711 return std::__remove_copy_if(__first, __last, __result,
712 __gnu_cxx::__ops::__pred_iter(__pred));
715 #if __cplusplus >= 201103L 731 template<
typename _InputIterator,
typename _OutputIterator,
734 copy_if(_InputIterator __first, _InputIterator __last,
735 _OutputIterator __result, _Predicate __pred)
738 __glibcxx_function_requires(_InputIteratorConcept<_InputIterator>)
739 __glibcxx_function_requires(_OutputIteratorConcept<_OutputIterator,
740 typename iterator_traits<_InputIterator>::value_type>)
741 __glibcxx_function_requires(_UnaryPredicateConcept<_Predicate,
742 typename iterator_traits<_InputIterator>::value_type>)
743 __glibcxx_requires_valid_range(__first, __last);
745 for (; __first != __last; ++__first)
746 if (__pred(*__first))
748 *__result = *__first;
754 template<
typename _InputIterator,
typename _Size,
typename _OutputIterator>
756 __copy_n(_InputIterator __first, _Size __n,
763 *__result = *__first;
774 template<
typename _RandomAccessIterator,
typename _Size,
775 typename _OutputIterator>
776 inline _OutputIterator
777 __copy_n(_RandomAccessIterator __first, _Size __n,
779 {
return std::copy(__first, __first + __n, __result); }
794 template<
typename _InputIterator,
typename _Size,
typename _OutputIterator>
795 inline _OutputIterator
796 copy_n(_InputIterator __first, _Size __n, _OutputIterator __result)
799 __glibcxx_function_requires(_InputIteratorConcept<_InputIterator>)
800 __glibcxx_function_requires(_OutputIteratorConcept<_OutputIterator,
801 typename iterator_traits<_InputIterator>::value_type>)
803 return std::__copy_n(__first, __n, __result,
822 template<
typename _InputIterator,
typename _OutputIterator1,
823 typename _OutputIterator2,
typename _Predicate>
825 partition_copy(_InputIterator __first, _InputIterator __last,
826 _OutputIterator1 __out_true, _OutputIterator2 __out_false,
830 __glibcxx_function_requires(_InputIteratorConcept<_InputIterator>)
831 __glibcxx_function_requires(_OutputIteratorConcept<_OutputIterator1,
832 typename iterator_traits<_InputIterator>::value_type>)
833 __glibcxx_function_requires(_OutputIteratorConcept<_OutputIterator2,
834 typename iterator_traits<_InputIterator>::value_type>)
835 __glibcxx_function_requires(_UnaryPredicateConcept<_Predicate,
836 typename iterator_traits<_InputIterator>::value_type>)
837 __glibcxx_requires_valid_range(__first, __last);
839 for (; __first != __last; ++__first)
840 if (__pred(*__first))
842 *__out_true = *__first;
847 *__out_false = *__first;
855 template<
typename _ForwardIterator,
typename _Predicate>
857 __remove_if(_ForwardIterator __first, _ForwardIterator __last,
861 if (__first == __last)
863 _ForwardIterator __result = __first;
865 for (; __first != __last; ++__first)
866 if (!__pred(__first))
868 *__result = _GLIBCXX_MOVE(*__first);
891 template<
typename _ForwardIterator,
typename _Tp>
892 inline _ForwardIterator
893 remove(_ForwardIterator __first, _ForwardIterator __last,
897 __glibcxx_function_requires(_Mutable_ForwardIteratorConcept<
899 __glibcxx_function_requires(_EqualOpConcept<
900 typename iterator_traits<_ForwardIterator>::value_type, _Tp>)
901 __glibcxx_requires_valid_range(__first, __last);
903 return std::__remove_if(__first, __last,
904 __gnu_cxx::__ops::__iter_equals_val(__value));
924 template<
typename _ForwardIterator,
typename _Predicate>
925 inline _ForwardIterator
926 remove_if(_ForwardIterator __first, _ForwardIterator __last,
930 __glibcxx_function_requires(_Mutable_ForwardIteratorConcept<
932 __glibcxx_function_requires(_UnaryPredicateConcept<_Predicate,
933 typename iterator_traits<_ForwardIterator>::value_type>)
934 __glibcxx_requires_valid_range(__first, __last);
936 return std::__remove_if(__first, __last,
937 __gnu_cxx::__ops::__pred_iter(__pred));
940 template<
typename _ForwardIterator,
typename _BinaryPredicate>
942 __adjacent_find(_ForwardIterator __first, _ForwardIterator __last,
943 _BinaryPredicate __binary_pred)
945 if (__first == __last)
947 _ForwardIterator __next = __first;
948 while (++__next != __last)
950 if (__binary_pred(__first, __next))
957 template<
typename _ForwardIterator,
typename _BinaryPredicate>
959 __unique(_ForwardIterator __first, _ForwardIterator __last,
960 _BinaryPredicate __binary_pred)
963 __first = std::__adjacent_find(__first, __last, __binary_pred);
964 if (__first == __last)
968 _ForwardIterator __dest = __first;
970 while (++__first != __last)
971 if (!__binary_pred(__dest, __first))
972 *++__dest = _GLIBCXX_MOVE(*__first);
990 template<
typename _ForwardIterator>
991 inline _ForwardIterator
992 unique(_ForwardIterator __first, _ForwardIterator __last)
995 __glibcxx_function_requires(_Mutable_ForwardIteratorConcept<
997 __glibcxx_function_requires(_EqualityComparableConcept<
998 typename iterator_traits<_ForwardIterator>::value_type>)
999 __glibcxx_requires_valid_range(__first, __last);
1001 return std::__unique(__first, __last,
1002 __gnu_cxx::__ops::__iter_equal_to_iter());
1020 template<
typename _ForwardIterator,
typename _BinaryPredicate>
1021 inline _ForwardIterator
1022 unique(_ForwardIterator __first, _ForwardIterator __last,
1023 _BinaryPredicate __binary_pred)
1026 __glibcxx_function_requires(_Mutable_ForwardIteratorConcept<
1028 __glibcxx_function_requires(_BinaryPredicateConcept<_BinaryPredicate,
1029 typename iterator_traits<_ForwardIterator>::value_type,
1030 typename iterator_traits<_ForwardIterator>::value_type>)
1031 __glibcxx_requires_valid_range(__first, __last);
1033 return std::__unique(__first, __last,
1034 __gnu_cxx::__ops::__iter_comp_iter(__binary_pred));
1043 template<
typename _ForwardIterator,
typename _OutputIterator,
1044 typename _BinaryPredicate>
1047 _OutputIterator __result, _BinaryPredicate __binary_pred,
1051 __glibcxx_function_requires(_BinaryPredicateConcept<_BinaryPredicate,
1052 typename iterator_traits<_ForwardIterator>::value_type,
1053 typename iterator_traits<_ForwardIterator>::value_type>)
1055 _ForwardIterator __next = __first;
1056 *__result = *__first;
1057 while (++__next != __last)
1058 if (!__binary_pred(__first, __next))
1061 *++__result = *__first;
1072 template<
typename _InputIterator,
typename _OutputIterator,
1073 typename _BinaryPredicate>
1076 _OutputIterator __result, _BinaryPredicate __binary_pred,
1080 __glibcxx_function_requires(_BinaryPredicateConcept<_BinaryPredicate,
1081 typename iterator_traits<_InputIterator>::value_type,
1082 typename iterator_traits<_InputIterator>::value_type>)
1084 typename iterator_traits<_InputIterator>::value_type __value = *__first;
1085 __decltype(__gnu_cxx::__ops::__iter_comp_val(__binary_pred))
1087 = __gnu_cxx::__ops::__iter_comp_val(__binary_pred);
1088 *__result = __value;
1089 while (++__first != __last)
1090 if (!__rebound_pred(__first, __value))
1093 *++__result = __value;
1104 template<
typename _InputIterator,
typename _ForwardIterator,
1105 typename _BinaryPredicate>
1108 _ForwardIterator __result, _BinaryPredicate __binary_pred,
1112 __glibcxx_function_requires(_BinaryPredicateConcept<_BinaryPredicate,
1113 typename iterator_traits<_ForwardIterator>::value_type,
1114 typename iterator_traits<_InputIterator>::value_type>)
1115 *__result = *__first;
1116 while (++__first != __last)
1117 if (!__binary_pred(__result, __first))
1118 *++__result = *__first;
1127 template<
typename _B
idirectionalIterator>
1129 __reverse(_BidirectionalIterator __first, _BidirectionalIterator __last,
1133 if (__first == __last || __first == --__last)
1147 template<
typename _RandomAccessIterator>
1149 __reverse(_RandomAccessIterator __first, _RandomAccessIterator __last,
1152 if (__first == __last)
1155 while (__first < __last)
1175 template<
typename _B
idirectionalIterator>
1177 reverse(_BidirectionalIterator __first, _BidirectionalIterator __last)
1180 __glibcxx_function_requires(_Mutable_BidirectionalIteratorConcept<
1181 _BidirectionalIterator>)
1182 __glibcxx_requires_valid_range(__first, __last);
1202 template<
typename _B
idirectionalIterator,
typename _OutputIterator>
1204 reverse_copy(_BidirectionalIterator __first, _BidirectionalIterator __last,
1205 _OutputIterator __result)
1208 __glibcxx_function_requires(_BidirectionalIteratorConcept<
1209 _BidirectionalIterator>)
1210 __glibcxx_function_requires(_OutputIteratorConcept<_OutputIterator,
1211 typename iterator_traits<_BidirectionalIterator>::value_type>)
1212 __glibcxx_requires_valid_range(__first, __last);
1214 while (__first != __last)
1217 *__result = *__last;
1227 template<
typename _Eucl
ideanRingElement>
1228 _EuclideanRingElement
1229 __gcd(_EuclideanRingElement __m, _EuclideanRingElement __n)
1233 _EuclideanRingElement __t = __m % __n;
1240 inline namespace _V2
1244 template<
typename _ForwardIterator>
1247 _ForwardIterator __middle,
1248 _ForwardIterator __last,
1251 if (__first == __middle)
1253 else if (__last == __middle)
1256 _ForwardIterator __first2 = __middle;
1262 if (__first == __middle)
1263 __middle = __first2;
1265 while (__first2 != __last);
1267 _ForwardIterator __ret = __first;
1269 __first2 = __middle;
1271 while (__first2 != __last)
1276 if (__first == __middle)
1277 __middle = __first2;
1278 else if (__first2 == __last)
1279 __first2 = __middle;
1285 template<
typename _B
idirectionalIterator>
1286 _BidirectionalIterator
1288 _BidirectionalIterator __middle,
1289 _BidirectionalIterator __last,
1293 __glibcxx_function_requires(_Mutable_BidirectionalIteratorConcept<
1294 _BidirectionalIterator>)
1296 if (__first == __middle)
1298 else if (__last == __middle)
1304 while (__first != __middle && __middle != __last)
1310 if (__first == __middle)
1323 template<
typename _RandomAccessIterator>
1324 _RandomAccessIterator
1326 _RandomAccessIterator __middle,
1327 _RandomAccessIterator __last,
1331 __glibcxx_function_requires(_Mutable_RandomAccessIteratorConcept<
1332 _RandomAccessIterator>)
1334 if (__first == __middle)
1336 else if (__last == __middle)
1339 typedef typename iterator_traits<_RandomAccessIterator>::difference_type
1341 typedef typename iterator_traits<_RandomAccessIterator>::value_type
1344 _Distance __n = __last - __first;
1345 _Distance __k = __middle - __first;
1347 if (__k == __n - __k)
1353 _RandomAccessIterator __p = __first;
1354 _RandomAccessIterator __ret = __first + (__last - __middle);
1358 if (__k < __n - __k)
1360 if (__is_pod(_ValueType) && __k == 1)
1362 _ValueType __t = _GLIBCXX_MOVE(*__p);
1363 _GLIBCXX_MOVE3(__p + 1, __p + __n, __p);
1364 *(__p + __n - 1) = _GLIBCXX_MOVE(__t);
1367 _RandomAccessIterator __q = __p + __k;
1368 for (_Distance __i = 0; __i < __n - __k; ++ __i)
1377 std::swap(__n, __k);
1383 if (__is_pod(_ValueType) && __k == 1)
1385 _ValueType __t = _GLIBCXX_MOVE(*(__p + __n - 1));
1386 _GLIBCXX_MOVE_BACKWARD3(__p, __p + __n - 1, __p + __n);
1387 *__p = _GLIBCXX_MOVE(__t);
1390 _RandomAccessIterator __q = __p + __n;
1392 for (_Distance __i = 0; __i < __n - __k; ++ __i)
1401 std::swap(__n, __k);
1429 template<
typename _ForwardIterator>
1430 inline _ForwardIterator
1431 rotate(_ForwardIterator __first, _ForwardIterator __middle,
1432 _ForwardIterator __last)
1435 __glibcxx_function_requires(_Mutable_ForwardIteratorConcept<
1437 __glibcxx_requires_valid_range(__first, __middle);
1438 __glibcxx_requires_valid_range(__middle, __last);
1440 return std::__rotate(__first, __middle, __last,
1466 template<
typename _ForwardIterator,
typename _OutputIterator>
1467 inline _OutputIterator
1468 rotate_copy(_ForwardIterator __first, _ForwardIterator __middle,
1469 _ForwardIterator __last, _OutputIterator __result)
1472 __glibcxx_function_requires(_ForwardIteratorConcept<_ForwardIterator>)
1473 __glibcxx_function_requires(_OutputIteratorConcept<_OutputIterator,
1474 typename iterator_traits<_ForwardIterator>::value_type>)
1475 __glibcxx_requires_valid_range(__first, __middle);
1476 __glibcxx_requires_valid_range(__middle, __last);
1478 return std::copy(__first, __middle,
1479 std::copy(__middle, __last, __result));
1483 template<
typename _ForwardIterator,
typename _Predicate>
1488 if (__first == __last)
1491 while (__pred(*__first))
1492 if (++__first == __last)
1495 _ForwardIterator __next = __first;
1497 while (++__next != __last)
1498 if (__pred(*__next))
1508 template<
typename _B
idirectionalIterator,
typename _Predicate>
1509 _BidirectionalIterator
1510 __partition(_BidirectionalIterator __first, _BidirectionalIterator __last,
1516 if (__first == __last)
1518 else if (__pred(*__first))
1524 if (__first == __last)
1526 else if (!
bool(__pred(*__last)))
1543 template<
typename _ForwardIterator,
typename _Pointer,
typename _Predicate,
1547 _ForwardIterator __last,
1548 _Predicate __pred, _Distance __len,
1550 _Distance __buffer_size)
1555 if (__len <= __buffer_size)
1557 _ForwardIterator __result1 = __first;
1558 _Pointer __result2 = __buffer;
1563 *__result2 = _GLIBCXX_MOVE(*__first);
1566 for (; __first != __last; ++__first)
1567 if (__pred(__first))
1569 *__result1 = _GLIBCXX_MOVE(*__first);
1574 *__result2 = _GLIBCXX_MOVE(*__first);
1578 _GLIBCXX_MOVE3(__buffer, __result2, __result1);
1582 _ForwardIterator __middle = __first;
1584 _ForwardIterator __left_split =
1586 __len / 2, __buffer,
1591 _Distance __right_len = __len - __len / 2;
1592 _ForwardIterator __right_split =
1599 __buffer, __buffer_size);
1601 std::rotate(__left_split, __middle, __right_split);
1603 return __left_split;
1606 template<
typename _ForwardIterator,
typename _Predicate>
1608 __stable_partition(_ForwardIterator __first, _ForwardIterator __last,
1613 if (__first == __last)
1616 typedef typename iterator_traits<_ForwardIterator>::value_type
1618 typedef typename iterator_traits<_ForwardIterator>::difference_type
1626 _DistanceType(__buf.
size()));
1646 template<
typename _ForwardIterator,
typename _Predicate>
1647 inline _ForwardIterator
1648 stable_partition(_ForwardIterator __first, _ForwardIterator __last,
1652 __glibcxx_function_requires(_Mutable_ForwardIteratorConcept<
1654 __glibcxx_function_requires(_UnaryPredicateConcept<_Predicate,
1655 typename iterator_traits<_ForwardIterator>::value_type>)
1656 __glibcxx_requires_valid_range(__first, __last);
1658 return std::__stable_partition(__first, __last,
1659 __gnu_cxx::__ops::__pred_iter(__pred));
1663 template<
typename _RandomAccessIterator,
typename _Compare>
1666 _RandomAccessIterator __middle,
1667 _RandomAccessIterator __last, _Compare __comp)
1669 std::__make_heap(__first, __middle, __comp);
1670 for (_RandomAccessIterator __i = __middle; __i < __last; ++__i)
1671 if (__comp(__i, __first))
1672 std::__pop_heap(__first, __middle, __i, __comp);
1677 template<
typename _InputIterator,
typename _RandomAccessIterator,
1679 _RandomAccessIterator
1680 __partial_sort_copy(_InputIterator __first, _InputIterator __last,
1681 _RandomAccessIterator __result_first,
1682 _RandomAccessIterator __result_last,
1685 typedef typename iterator_traits<_InputIterator>::value_type
1687 typedef iterator_traits<_RandomAccessIterator> _RItTraits;
1688 typedef typename _RItTraits::difference_type _DistanceType;
1690 if (__result_first == __result_last)
1691 return __result_last;
1692 _RandomAccessIterator __result_real_last = __result_first;
1693 while (__first != __last && __result_real_last != __result_last)
1695 *__result_real_last = *__first;
1696 ++__result_real_last;
1700 std::__make_heap(__result_first, __result_real_last, __comp);
1701 while (__first != __last)
1703 if (__comp(__first, __result_first))
1704 std::__adjust_heap(__result_first, _DistanceType(0),
1705 _DistanceType(__result_real_last
1707 _InputValueType(*__first), __comp);
1710 std::__sort_heap(__result_first, __result_real_last, __comp);
1711 return __result_real_last;
1732 template<
typename _InputIterator,
typename _RandomAccessIterator>
1733 inline _RandomAccessIterator
1734 partial_sort_copy(_InputIterator __first, _InputIterator __last,
1735 _RandomAccessIterator __result_first,
1736 _RandomAccessIterator __result_last)
1738 typedef typename iterator_traits<_InputIterator>::value_type
1740 typedef typename iterator_traits<_RandomAccessIterator>::value_type
1742 typedef typename iterator_traits<_RandomAccessIterator>::difference_type
1746 __glibcxx_function_requires(_InputIteratorConcept<_InputIterator>)
1747 __glibcxx_function_requires(_ConvertibleConcept<_InputValueType,
1749 __glibcxx_function_requires(_LessThanOpConcept<_InputValueType,
1751 __glibcxx_function_requires(_LessThanComparableConcept<_OutputValueType>)
1752 __glibcxx_requires_valid_range(__first, __last);
1753 __glibcxx_requires_valid_range(__result_first, __result_last);
1755 return std::__partial_sort_copy(__first, __last,
1756 __result_first, __result_last,
1757 __gnu_cxx::__ops::__iter_less_iter());
1780 template<
typename _InputIterator,
typename _RandomAccessIterator,
1782 inline _RandomAccessIterator
1783 partial_sort_copy(_InputIterator __first, _InputIterator __last,
1784 _RandomAccessIterator __result_first,
1785 _RandomAccessIterator __result_last,
1788 typedef typename iterator_traits<_InputIterator>::value_type
1790 typedef typename iterator_traits<_RandomAccessIterator>::value_type
1792 typedef typename iterator_traits<_RandomAccessIterator>::difference_type
1796 __glibcxx_function_requires(_InputIteratorConcept<_InputIterator>)
1797 __glibcxx_function_requires(_Mutable_RandomAccessIteratorConcept<
1798 _RandomAccessIterator>)
1799 __glibcxx_function_requires(_ConvertibleConcept<_InputValueType,
1801 __glibcxx_function_requires(_BinaryPredicateConcept<_Compare,
1802 _InputValueType, _OutputValueType>)
1803 __glibcxx_function_requires(_BinaryPredicateConcept<_Compare,
1804 _OutputValueType, _OutputValueType>)
1805 __glibcxx_requires_valid_range(__first, __last);
1806 __glibcxx_requires_valid_range(__result_first, __result_last);
1808 return std::__partial_sort_copy(__first, __last,
1809 __result_first, __result_last,
1810 __gnu_cxx::__ops::__iter_comp_iter(__comp));
1814 template<
typename _RandomAccessIterator,
typename _Compare>
1819 typename iterator_traits<_RandomAccessIterator>::value_type
1820 __val = _GLIBCXX_MOVE(*__last);
1821 _RandomAccessIterator __next = __last;
1823 while (__comp(__val, __next))
1825 *__last = _GLIBCXX_MOVE(*__next);
1829 *__last = _GLIBCXX_MOVE(__val);
1833 template<
typename _RandomAccessIterator,
typename _Compare>
1836 _RandomAccessIterator __last, _Compare __comp)
1838 if (__first == __last)
return;
1840 for (_RandomAccessIterator __i = __first + 1; __i != __last; ++__i)
1842 if (__comp(__i, __first))
1844 typename iterator_traits<_RandomAccessIterator>::value_type
1845 __val = _GLIBCXX_MOVE(*__i);
1846 _GLIBCXX_MOVE_BACKWARD3(__first, __i, __i + 1);
1847 *__first = _GLIBCXX_MOVE(__val);
1851 __gnu_cxx::__ops::__val_comp_iter(__comp));
1856 template<
typename _RandomAccessIterator,
typename _Compare>
1859 _RandomAccessIterator __last, _Compare __comp)
1861 for (_RandomAccessIterator __i = __first; __i != __last; ++__i)
1863 __gnu_cxx::__ops::__val_comp_iter(__comp));
1870 enum { _S_threshold = 16 };
1873 template<
typename _RandomAccessIterator,
typename _Compare>
1876 _RandomAccessIterator __last, _Compare __comp)
1878 if (__last - __first >
int(_S_threshold))
1889 template<
typename _RandomAccessIterator,
typename _Compare>
1890 _RandomAccessIterator
1892 _RandomAccessIterator __last,
1893 _RandomAccessIterator __pivot, _Compare __comp)
1897 while (__comp(__first, __pivot))
1900 while (__comp(__pivot, __last))
1902 if (!(__first < __last))
1910 template<
typename _RandomAccessIterator,
typename _Compare>
1911 inline _RandomAccessIterator
1913 _RandomAccessIterator __last, _Compare __comp)
1915 _RandomAccessIterator __mid = __first + (__last - __first) / 2;
1921 template<
typename _RandomAccessIterator,
typename _Compare>
1923 __partial_sort(_RandomAccessIterator __first,
1924 _RandomAccessIterator __middle,
1925 _RandomAccessIterator __last,
1929 std::__sort_heap(__first, __middle, __comp);
1933 template<
typename _RandomAccessIterator,
typename _Size,
typename _Compare>
1936 _RandomAccessIterator __last,
1937 _Size __depth_limit, _Compare __comp)
1939 while (__last - __first >
int(_S_threshold))
1941 if (__depth_limit == 0)
1943 std::__partial_sort(__first, __last, __last, __comp);
1947 _RandomAccessIterator __cut =
1956 template<
typename _RandomAccessIterator,
typename _Compare>
1958 __sort(_RandomAccessIterator __first, _RandomAccessIterator __last,
1961 if (__first != __last)
1970 template<
typename _RandomAccessIterator,
typename _Size,
typename _Compare>
1972 __introselect(_RandomAccessIterator __first, _RandomAccessIterator __nth,
1973 _RandomAccessIterator __last, _Size __depth_limit,
1976 while (__last - __first > 3)
1978 if (__depth_limit == 0)
1986 _RandomAccessIterator __cut =
2016 template<
typename _ForwardIterator,
typename _Tp,
typename _Compare>
2017 inline _ForwardIterator
2018 lower_bound(_ForwardIterator __first, _ForwardIterator __last,
2019 const _Tp& __val, _Compare __comp)
2021 typedef typename iterator_traits<_ForwardIterator>::value_type
2025 __glibcxx_function_requires(_ForwardIteratorConcept<_ForwardIterator>)
2026 __glibcxx_function_requires(_BinaryPredicateConcept<_Compare,
2028 __glibcxx_requires_partitioned_lower_pred(__first, __last,
2031 return std::__lower_bound(__first, __last, __val,
2032 __gnu_cxx::__ops::__iter_comp_val(__comp));
2035 template<
typename _ForwardIterator,
typename _Tp,
typename _Compare>
2037 __upper_bound(_ForwardIterator __first, _ForwardIterator __last,
2038 const _Tp& __val, _Compare __comp)
2040 typedef typename iterator_traits<_ForwardIterator>::difference_type
2047 _DistanceType __half = __len >> 1;
2048 _ForwardIterator __middle = __first;
2050 if (__comp(__val, __middle))
2056 __len = __len - __half - 1;
2073 template<
typename _ForwardIterator,
typename _Tp>
2074 inline _ForwardIterator
2075 upper_bound(_ForwardIterator __first, _ForwardIterator __last,
2078 typedef typename iterator_traits<_ForwardIterator>::value_type
2082 __glibcxx_function_requires(_ForwardIteratorConcept<_ForwardIterator>)
2083 __glibcxx_function_requires(_LessThanOpConcept<_Tp, _ValueType>)
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)
2110 typedef typename iterator_traits<_ForwardIterator>::value_type
2114 __glibcxx_function_requires(_ForwardIteratorConcept<_ForwardIterator>)
2115 __glibcxx_function_requires(_BinaryPredicateConcept<_Compare,
2117 __glibcxx_requires_partitioned_upper_pred(__first, __last,
2120 return std::__upper_bound(__first, __last, __val,
2121 __gnu_cxx::__ops::__val_comp_iter(__comp));
2124 template<
typename _ForwardIterator,
typename _Tp,
2125 typename _CompareItTp,
typename _CompareTpIt>
2127 __equal_range(_ForwardIterator __first, _ForwardIterator __last,
2129 _CompareItTp __comp_it_val, _CompareTpIt __comp_val_it)
2131 typedef typename iterator_traits<_ForwardIterator>::difference_type
2138 _DistanceType __half = __len >> 1;
2139 _ForwardIterator __middle = __first;
2141 if (__comp_it_val(__middle, __val))
2145 __len = __len - __half - 1;
2147 else if (__comp_val_it(__val, __middle))
2151 _ForwardIterator __left
2152 = std::__lower_bound(__first, __middle, __val, __comp_it_val);
2154 _ForwardIterator __right
2155 = std::__upper_bound(++__middle, __first, __val, __comp_val_it);
2179 template<
typename _ForwardIterator,
typename _Tp>
2181 equal_range(_ForwardIterator __first, _ForwardIterator __last,
2184 typedef typename iterator_traits<_ForwardIterator>::value_type
2188 __glibcxx_function_requires(_ForwardIteratorConcept<_ForwardIterator>)
2189 __glibcxx_function_requires(_LessThanOpConcept<_ValueType, _Tp>)
2190 __glibcxx_function_requires(_LessThanOpConcept<_Tp, _ValueType>)
2191 __glibcxx_requires_partitioned_lower(__first, __last, __val);
2192 __glibcxx_requires_partitioned_upper(__first, __last, __val);
2194 return std::__equal_range(__first, __last, __val,
2195 __gnu_cxx::__ops::__iter_less_val(),
2196 __gnu_cxx::__ops::__val_less_iter());
2216 template<
typename _ForwardIterator,
typename _Tp,
typename _Compare>
2218 equal_range(_ForwardIterator __first, _ForwardIterator __last,
2219 const _Tp& __val, _Compare __comp)
2221 typedef typename iterator_traits<_ForwardIterator>::value_type
2225 __glibcxx_function_requires(_ForwardIteratorConcept<_ForwardIterator>)
2226 __glibcxx_function_requires(_BinaryPredicateConcept<_Compare,
2228 __glibcxx_function_requires(_BinaryPredicateConcept<_Compare,
2230 __glibcxx_requires_partitioned_lower_pred(__first, __last,
2232 __glibcxx_requires_partitioned_upper_pred(__first, __last,
2235 return std::__equal_range(__first, __last, __val,
2236 __gnu_cxx::__ops::__iter_comp_val(__comp),
2237 __gnu_cxx::__ops::__val_comp_iter(__comp));
2252 template<
typename _ForwardIterator,
typename _Tp>
2254 binary_search(_ForwardIterator __first, _ForwardIterator __last,
2257 typedef typename iterator_traits<_ForwardIterator>::value_type
2261 __glibcxx_function_requires(_ForwardIteratorConcept<_ForwardIterator>)
2262 __glibcxx_function_requires(_LessThanOpConcept<_Tp, _ValueType>)
2263 __glibcxx_requires_partitioned_lower(__first, __last, __val);
2264 __glibcxx_requires_partitioned_upper(__first, __last, __val);
2266 _ForwardIterator __i
2267 = std::__lower_bound(__first, __last, __val,
2268 __gnu_cxx::__ops::__iter_less_val());
2269 return __i != __last && !(__val < *__i);
2287 template<
typename _ForwardIterator,
typename _Tp,
typename _Compare>
2289 binary_search(_ForwardIterator __first, _ForwardIterator __last,
2290 const _Tp& __val, _Compare __comp)
2292 typedef typename iterator_traits<_ForwardIterator>::value_type
2296 __glibcxx_function_requires(_ForwardIteratorConcept<_ForwardIterator>)
2297 __glibcxx_function_requires(_BinaryPredicateConcept<_Compare,
2299 __glibcxx_requires_partitioned_lower_pred(__first, __last,
2301 __glibcxx_requires_partitioned_upper_pred(__first, __last,
2304 _ForwardIterator __i
2305 = std::__lower_bound(__first, __last, __val,
2306 __gnu_cxx::__ops::__iter_comp_val(__comp));
2307 return __i != __last && !bool(__comp(__val, *__i));
2313 template<
typename _InputIterator1,
typename _InputIterator2,
2314 typename _OutputIterator,
typename _Compare>
2317 _InputIterator2 __first2, _InputIterator2 __last2,
2318 _OutputIterator __result, _Compare __comp)
2320 while (__first1 != __last1 && __first2 != __last2)
2322 if (__comp(__first2, __first1))
2324 *__result = _GLIBCXX_MOVE(*__first2);
2329 *__result = _GLIBCXX_MOVE(*__first1);
2334 if (__first1 != __last1)
2335 _GLIBCXX_MOVE3(__first1, __last1, __result);
2339 template<
typename _BidirectionalIterator1,
typename _BidirectionalIterator2,
2340 typename _BidirectionalIterator3,
typename _Compare>
2343 _BidirectionalIterator1 __last1,
2344 _BidirectionalIterator2 __first2,
2345 _BidirectionalIterator2 __last2,
2346 _BidirectionalIterator3 __result,
2349 if (__first1 == __last1)
2351 _GLIBCXX_MOVE_BACKWARD3(__first2, __last2, __result);
2354 else if (__first2 == __last2)
2361 if (__comp(__last2, __last1))
2363 *--__result = _GLIBCXX_MOVE(*__last1);
2364 if (__first1 == __last1)
2366 _GLIBCXX_MOVE_BACKWARD3(__first2, ++__last2, __result);
2373 *--__result = _GLIBCXX_MOVE(*__last2);
2374 if (__first2 == __last2)
2382 template<
typename _BidirectionalIterator1,
typename _BidirectionalIterator2,
2384 _BidirectionalIterator1
2386 _BidirectionalIterator1 __middle,
2387 _BidirectionalIterator1 __last,
2388 _Distance __len1, _Distance __len2,
2389 _BidirectionalIterator2 __buffer,
2390 _Distance __buffer_size)
2392 _BidirectionalIterator2 __buffer_end;
2393 if (__len1 > __len2 && __len2 <= __buffer_size)
2397 __buffer_end = _GLIBCXX_MOVE3(__middle, __last, __buffer);
2398 _GLIBCXX_MOVE_BACKWARD3(__first, __middle, __last);
2399 return _GLIBCXX_MOVE3(__buffer, __buffer_end, __first);
2404 else if (__len1 <= __buffer_size)
2408 __buffer_end = _GLIBCXX_MOVE3(__first, __middle, __buffer);
2409 _GLIBCXX_MOVE3(__middle, __last, __first);
2410 return _GLIBCXX_MOVE_BACKWARD3(__buffer, __buffer_end, __last);
2424 template<
typename _BidirectionalIterator,
typename _Distance,
2425 typename _Pointer,
typename _Compare>
2428 _BidirectionalIterator __middle,
2429 _BidirectionalIterator __last,
2430 _Distance __len1, _Distance __len2,
2431 _Pointer __buffer, _Distance __buffer_size,
2434 if (__len1 <= __len2 && __len1 <= __buffer_size)
2436 _Pointer __buffer_end = _GLIBCXX_MOVE3(__first, __middle, __buffer);
2440 else if (__len2 <= __buffer_size)
2442 _Pointer __buffer_end = _GLIBCXX_MOVE3(__middle, __last, __buffer);
2444 __buffer_end, __last, __comp);
2448 _BidirectionalIterator __first_cut = __first;
2449 _BidirectionalIterator __second_cut = __middle;
2450 _Distance __len11 = 0;
2451 _Distance __len22 = 0;
2452 if (__len1 > __len2)
2454 __len11 = __len1 / 2;
2457 = std::__lower_bound(__middle, __last, *__first_cut,
2458 __gnu_cxx::__ops::__iter_comp_val(__comp));
2463 __len22 = __len2 / 2;
2466 = std::__upper_bound(__first, __middle, *__second_cut,
2467 __gnu_cxx::__ops::__val_comp_iter(__comp));
2471 _BidirectionalIterator __new_middle
2473 __len1 - __len11, __len22, __buffer,
2476 __len22, __buffer, __buffer_size, __comp);
2479 __len2 - __len22, __buffer,
2480 __buffer_size, __comp);
2485 template<
typename _BidirectionalIterator,
typename _Distance,
2489 _BidirectionalIterator __middle,
2490 _BidirectionalIterator __last,
2491 _Distance __len1, _Distance __len2,
2494 if (__len1 == 0 || __len2 == 0)
2497 if (__len1 + __len2 == 2)
2499 if (__comp(__middle, __first))
2504 _BidirectionalIterator __first_cut = __first;
2505 _BidirectionalIterator __second_cut = __middle;
2506 _Distance __len11 = 0;
2507 _Distance __len22 = 0;
2508 if (__len1 > __len2)
2510 __len11 = __len1 / 2;
2513 = std::__lower_bound(__middle, __last, *__first_cut,
2514 __gnu_cxx::__ops::__iter_comp_val(__comp));
2519 __len22 = __len2 / 2;
2522 = std::__upper_bound(__first, __middle, *__second_cut,
2523 __gnu_cxx::__ops::__val_comp_iter(__comp));
2528 _BidirectionalIterator __new_middle = __first_cut;
2531 __len11, __len22, __comp);
2533 __len1 - __len11, __len2 - __len22, __comp);
2536 template<
typename _B
idirectionalIterator,
typename _Compare>
2538 __inplace_merge(_BidirectionalIterator __first,
2539 _BidirectionalIterator __middle,
2540 _BidirectionalIterator __last,
2543 typedef typename iterator_traits<_BidirectionalIterator>::value_type
2545 typedef typename iterator_traits<_BidirectionalIterator>::difference_type
2548 if (__first == __middle || __middle == __last)
2551 const _DistanceType __len1 =
std::distance(__first, __middle);
2552 const _DistanceType __len2 =
std::distance(__middle, __last);
2555 _TmpBuf __buf(__first, __last);
2557 if (__buf.begin() == 0)
2559 (__first, __middle, __last, __len1, __len2, __comp);
2562 (__first, __middle, __last, __len1, __len2, __buf.begin(),
2563 _DistanceType(__buf.size()), __comp);
2584 template<
typename _B
idirectionalIterator>
2586 inplace_merge(_BidirectionalIterator __first,
2587 _BidirectionalIterator __middle,
2588 _BidirectionalIterator __last)
2591 __glibcxx_function_requires(_Mutable_BidirectionalIteratorConcept<
2592 _BidirectionalIterator>)
2593 __glibcxx_function_requires(_LessThanComparableConcept<
2594 typename iterator_traits<_BidirectionalIterator>::value_type>)
2595 __glibcxx_requires_sorted(__first, __middle);
2596 __glibcxx_requires_sorted(__middle, __last);
2598 std::__inplace_merge(__first, __middle, __last,
2599 __gnu_cxx::__ops::__iter_less_iter());
2624 template<
typename _B
idirectionalIterator,
typename _Compare>
2626 inplace_merge(_BidirectionalIterator __first,
2627 _BidirectionalIterator __middle,
2628 _BidirectionalIterator __last,
2632 __glibcxx_function_requires(_Mutable_BidirectionalIteratorConcept<
2633 _BidirectionalIterator>)
2634 __glibcxx_function_requires(_BinaryPredicateConcept<_Compare,
2635 typename iterator_traits<_BidirectionalIterator>::value_type,
2636 typename iterator_traits<_BidirectionalIterator>::value_type>)
2637 __glibcxx_requires_sorted_pred(__first, __middle, __comp);
2638 __glibcxx_requires_sorted_pred(__middle, __last, __comp);
2640 std::__inplace_merge(__first, __middle, __last,
2641 __gnu_cxx::__ops::__iter_comp_iter(__comp));
2646 template<
typename _InputIterator,
typename _OutputIterator,
2650 _InputIterator __first2, _InputIterator __last2,
2651 _OutputIterator __result, _Compare __comp)
2653 while (__first1 != __last1 && __first2 != __last2)
2655 if (__comp(__first2, __first1))
2657 *__result = _GLIBCXX_MOVE(*__first2);
2662 *__result = _GLIBCXX_MOVE(*__first1);
2667 return _GLIBCXX_MOVE3(__first2, __last2,
2668 _GLIBCXX_MOVE3(__first1, __last1,
2672 template<
typename _RandomAccessIterator1,
typename _RandomAccessIterator2,
2673 typename _Distance,
typename _Compare>
2675 __merge_sort_loop(_RandomAccessIterator1 __first,
2676 _RandomAccessIterator1 __last,
2677 _RandomAccessIterator2 __result, _Distance __step_size,
2680 const _Distance __two_step = 2 * __step_size;
2682 while (__last - __first >= __two_step)
2685 __first + __step_size,
2686 __first + __two_step,
2688 __first += __two_step;
2690 __step_size =
std::min(_Distance(__last - __first), __step_size);
2693 __first + __step_size, __last, __result, __comp);
2696 template<
typename _RandomAccessIterator,
typename _Distance,
2699 __chunk_insertion_sort(_RandomAccessIterator __first,
2700 _RandomAccessIterator __last,
2701 _Distance __chunk_size, _Compare __comp)
2703 while (__last - __first >= __chunk_size)
2706 __first += __chunk_size;
2711 enum { _S_chunk_size = 7 };
2713 template<
typename _RandomAccessIterator,
typename _Po
inter,
typename _Compare>
2715 __merge_sort_with_buffer(_RandomAccessIterator __first,
2716 _RandomAccessIterator __last,
2717 _Pointer __buffer, _Compare __comp)
2719 typedef typename iterator_traits<_RandomAccessIterator>::difference_type
2722 const _Distance __len = __last - __first;
2723 const _Pointer __buffer_last = __buffer + __len;
2725 _Distance __step_size = _S_chunk_size;
2726 std::__chunk_insertion_sort(__first, __last, __step_size, __comp);
2728 while (__step_size < __len)
2730 std::__merge_sort_loop(__first, __last, __buffer,
2731 __step_size, __comp);
2733 std::__merge_sort_loop(__buffer, __buffer_last, __first,
2734 __step_size, __comp);
2739 template<
typename _RandomAccessIterator,
typename _Pointer,
2740 typename _Distance,
typename _Compare>
2742 __stable_sort_adaptive(_RandomAccessIterator __first,
2743 _RandomAccessIterator __last,
2744 _Pointer __buffer, _Distance __buffer_size,
2747 const _Distance __len = (__last - __first + 1) / 2;
2748 const _RandomAccessIterator __middle = __first + __len;
2749 if (__len > __buffer_size)
2751 std::__stable_sort_adaptive(__first, __middle, __buffer,
2752 __buffer_size, __comp);
2753 std::__stable_sort_adaptive(__middle, __last, __buffer,
2754 __buffer_size, __comp);
2758 std::__merge_sort_with_buffer(__first, __middle, __buffer, __comp);
2759 std::__merge_sort_with_buffer(__middle, __last, __buffer, __comp);
2762 _Distance(__middle - __first),
2763 _Distance(__last - __middle),
2764 __buffer, __buffer_size,
2769 template<
typename _RandomAccessIterator,
typename _Compare>
2772 _RandomAccessIterator __last, _Compare __comp)
2774 if (__last - __first < 15)
2779 _RandomAccessIterator __middle = __first + (__last - __first) / 2;
2795 template<
typename _InputIterator1,
typename _InputIterator2,
2798 __includes(_InputIterator1 __first1, _InputIterator1 __last1,
2799 _InputIterator2 __first2, _InputIterator2 __last2,
2802 while (__first1 != __last1 && __first2 != __last2)
2803 if (__comp(__first2, __first1))
2805 else if (__comp(__first1, __first2))
2808 ++__first1, ++__first2;
2810 return __first2 == __last2;
2831 template<
typename _InputIterator1,
typename _InputIterator2>
2833 includes(_InputIterator1 __first1, _InputIterator1 __last1,
2834 _InputIterator2 __first2, _InputIterator2 __last2)
2837 __glibcxx_function_requires(_InputIteratorConcept<_InputIterator1>)
2838 __glibcxx_function_requires(_InputIteratorConcept<_InputIterator2>)
2839 __glibcxx_function_requires(_LessThanOpConcept<
2840 typename iterator_traits<_InputIterator1>::value_type,
2841 typename iterator_traits<_InputIterator2>::value_type>)
2842 __glibcxx_function_requires(_LessThanOpConcept<
2843 typename iterator_traits<_InputIterator2>::value_type,
2844 typename iterator_traits<_InputIterator1>::value_type>)
2845 __glibcxx_requires_sorted_set(__first1, __last1, __first2);
2846 __glibcxx_requires_sorted_set(__first2, __last2, __first1);
2848 return std::__includes(__first1, __last1, __first2, __last2,
2849 __gnu_cxx::__ops::__iter_less_iter());
2873 template<
typename _InputIterator1,
typename _InputIterator2,
2876 includes(_InputIterator1 __first1, _InputIterator1 __last1,
2877 _InputIterator2 __first2, _InputIterator2 __last2,
2881 __glibcxx_function_requires(_InputIteratorConcept<_InputIterator1>)
2882 __glibcxx_function_requires(_InputIteratorConcept<_InputIterator2>)
2883 __glibcxx_function_requires(_BinaryPredicateConcept<_Compare,
2884 typename iterator_traits<_InputIterator1>::value_type,
2885 typename iterator_traits<_InputIterator2>::value_type>)
2886 __glibcxx_function_requires(_BinaryPredicateConcept<_Compare,
2887 typename iterator_traits<_InputIterator2>::value_type,
2888 typename iterator_traits<_InputIterator1>::value_type>)
2889 __glibcxx_requires_sorted_set_pred(__first1, __last1, __first2, __comp);
2890 __glibcxx_requires_sorted_set_pred(__first2, __last2, __first1, __comp);
2892 return std::__includes(__first1, __last1, __first2, __last2,
2893 __gnu_cxx::__ops::__iter_comp_iter(__comp));
2906 template<
typename _B
idirectionalIterator,
typename _Compare>
2908 __next_permutation(_BidirectionalIterator __first,
2909 _BidirectionalIterator __last, _Compare __comp)
2911 if (__first == __last)
2913 _BidirectionalIterator __i = __first;
2922 _BidirectionalIterator __ii = __i;
2924 if (__comp(__i, __ii))
2926 _BidirectionalIterator __j = __last;
2927 while (!__comp(__i, --__j))
2955 template<
typename _B
idirectionalIterator>
2957 next_permutation(_BidirectionalIterator __first,
2958 _BidirectionalIterator __last)
2961 __glibcxx_function_requires(_BidirectionalIteratorConcept<
2962 _BidirectionalIterator>)
2963 __glibcxx_function_requires(_LessThanComparableConcept<
2964 typename iterator_traits<_BidirectionalIterator>::value_type>)
2965 __glibcxx_requires_valid_range(__first, __last);
2967 return std::__next_permutation
2968 (__first, __last, __gnu_cxx::__ops::__iter_less_iter());
2986 template<
typename _B
idirectionalIterator,
typename _Compare>
2988 next_permutation(_BidirectionalIterator __first,
2989 _BidirectionalIterator __last, _Compare __comp)
2992 __glibcxx_function_requires(_BidirectionalIteratorConcept<
2993 _BidirectionalIterator>)
2994 __glibcxx_function_requires(_BinaryPredicateConcept<_Compare,
2995 typename iterator_traits<_BidirectionalIterator>::value_type,
2996 typename iterator_traits<_BidirectionalIterator>::value_type>)
2997 __glibcxx_requires_valid_range(__first, __last);
2999 return std::__next_permutation
3000 (__first, __last, __gnu_cxx::__ops::__iter_comp_iter(__comp));
3003 template<
typename _B
idirectionalIterator,
typename _Compare>
3005 __prev_permutation(_BidirectionalIterator __first,
3006 _BidirectionalIterator __last, _Compare __comp)
3008 if (__first == __last)
3010 _BidirectionalIterator __i = __first;
3019 _BidirectionalIterator __ii = __i;
3021 if (__comp(__ii, __i))
3023 _BidirectionalIterator __j = __last;
3024 while (!__comp(--__j, __i))
3053 template<
typename _B
idirectionalIterator>
3055 prev_permutation(_BidirectionalIterator __first,
3056 _BidirectionalIterator __last)
3059 __glibcxx_function_requires(_BidirectionalIteratorConcept<
3060 _BidirectionalIterator>)
3061 __glibcxx_function_requires(_LessThanComparableConcept<
3062 typename iterator_traits<_BidirectionalIterator>::value_type>)
3063 __glibcxx_requires_valid_range(__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);
3097 return std::__prev_permutation(__first, __last,
3098 __gnu_cxx::__ops::__iter_comp_iter(__comp));
3104 template<
typename _InputIterator,
typename _OutputIterator,
3105 typename _Predicate,
typename _Tp>
3107 __replace_copy_if(_InputIterator __first, _InputIterator __last,
3108 _OutputIterator __result,
3109 _Predicate __pred,
const _Tp& __new_value)
3111 for (; __first != __last; ++__first, ++__result)
3112 if (__pred(__first))
3113 *__result = __new_value;
3115 *__result = *__first;
3133 template<
typename _InputIterator,
typename _OutputIterator,
typename _Tp>
3134 inline _OutputIterator
3135 replace_copy(_InputIterator __first, _InputIterator __last,
3136 _OutputIterator __result,
3137 const _Tp& __old_value,
const _Tp& __new_value)
3140 __glibcxx_function_requires(_InputIteratorConcept<_InputIterator>)
3141 __glibcxx_function_requires(_OutputIteratorConcept<_OutputIterator,
3142 typename iterator_traits<_InputIterator>::value_type>)
3143 __glibcxx_function_requires(_EqualOpConcept<
3144 typename iterator_traits<_InputIterator>::value_type, _Tp>)
3145 __glibcxx_requires_valid_range(__first, __last);
3147 return std::__replace_copy_if(__first, __last, __result,
3148 __gnu_cxx::__ops::__iter_equals_val(__old_value),
3167 template<
typename _InputIterator,
typename _OutputIterator,
3168 typename _Predicate,
typename _Tp>
3169 inline _OutputIterator
3170 replace_copy_if(_InputIterator __first, _InputIterator __last,
3171 _OutputIterator __result,
3172 _Predicate __pred,
const _Tp& __new_value)
3175 __glibcxx_function_requires(_InputIteratorConcept<_InputIterator>)
3176 __glibcxx_function_requires(_OutputIteratorConcept<_OutputIterator,
3177 typename iterator_traits<_InputIterator>::value_type>)
3178 __glibcxx_function_requires(_UnaryPredicateConcept<_Predicate,
3179 typename iterator_traits<_InputIterator>::value_type>)
3180 __glibcxx_requires_valid_range(__first, __last);
3182 return std::__replace_copy_if(__first, __last, __result,
3183 __gnu_cxx::__ops::__pred_iter(__pred),
3187 template<
typename _InputIterator,
typename _Predicate>
3188 typename iterator_traits<_InputIterator>::difference_type
3189 __count_if(_InputIterator __first, _InputIterator __last, _Predicate __pred)
3191 typename iterator_traits<_InputIterator>::difference_type __n = 0;
3192 for (; __first != __last; ++__first)
3193 if (__pred(__first))
3198 #if __cplusplus >= 201103L 3206 template<
typename _ForwardIterator>
3208 is_sorted(_ForwardIterator __first, _ForwardIterator __last)
3220 template<
typename _ForwardIterator,
typename _Compare>
3222 is_sorted(_ForwardIterator __first, _ForwardIterator __last,
3226 template<
typename _ForwardIterator,
typename _Compare>
3228 __is_sorted_until(_ForwardIterator __first, _ForwardIterator __last,
3231 if (__first == __last)
3234 _ForwardIterator __next = __first;
3235 for (++__next; __next != __last; __first = __next, ++__next)
3236 if (__comp(__next, __first))
3249 template<
typename _ForwardIterator>
3250 inline _ForwardIterator
3251 is_sorted_until(_ForwardIterator __first, _ForwardIterator __last)
3254 __glibcxx_function_requires(_ForwardIteratorConcept<_ForwardIterator>)
3255 __glibcxx_function_requires(_LessThanComparableConcept<
3256 typename iterator_traits<_ForwardIterator>::value_type>)
3257 __glibcxx_requires_valid_range(__first, __last);
3259 return std::__is_sorted_until(__first, __last,
3260 __gnu_cxx::__ops::__iter_less_iter());
3272 template<
typename _ForwardIterator,
typename _Compare>
3273 inline _ForwardIterator
3274 is_sorted_until(_ForwardIterator __first, _ForwardIterator __last,
3278 __glibcxx_function_requires(_ForwardIteratorConcept<_ForwardIterator>)
3279 __glibcxx_function_requires(_BinaryPredicateConcept<_Compare,
3280 typename iterator_traits<_ForwardIterator>::value_type,
3281 typename iterator_traits<_ForwardIterator>::value_type>)
3282 __glibcxx_requires_valid_range(__first, __last);
3284 return std::__is_sorted_until(__first, __last,
3285 __gnu_cxx::__ops::__iter_comp_iter(__comp));
3296 template<
typename _Tp>
3297 _GLIBCXX14_CONSTEXPR
3302 __glibcxx_function_requires(_LessThanComparableConcept<_Tp>)
3304 return __b < __a ? pair<const _Tp&, const _Tp&>(__b, __a)
3317 template<
typename _Tp,
typename _Compare>
3318 _GLIBCXX14_CONSTEXPR
3320 minmax(
const _Tp& __a,
const _Tp& __b, _Compare __comp)
3326 template<
typename _ForwardIterator,
typename _Compare>
3327 _GLIBCXX14_CONSTEXPR
3329 __minmax_element(_ForwardIterator __first, _ForwardIterator __last,
3332 _ForwardIterator __next = __first;
3333 if (__first == __last
3334 || ++__next == __last)
3337 _ForwardIterator __min{}, __max{};
3338 if (__comp(__next, __first))
3352 while (__first != __last)
3355 if (++__next == __last)
3357 if (__comp(__first, __min))
3359 else if (!__comp(__first, __max))
3364 if (__comp(__next, __first))
3366 if (__comp(__next, __min))
3368 if (!__comp(__first, __max))
3373 if (__comp(__first, __min))
3375 if (!__comp(__next, __max))
3397 template<
typename _ForwardIterator>
3398 _GLIBCXX14_CONSTEXPR
3400 minmax_element(_ForwardIterator __first, _ForwardIterator __last)
3403 __glibcxx_function_requires(_ForwardIteratorConcept<_ForwardIterator>)
3404 __glibcxx_function_requires(_LessThanComparableConcept<
3405 typename iterator_traits<_ForwardIterator>::value_type>)
3406 __glibcxx_requires_valid_range(__first, __last);
3408 return std::__minmax_element(__first, __last,
3409 __gnu_cxx::__ops::__iter_less_iter());
3424 template<
typename _ForwardIterator,
typename _Compare>
3425 _GLIBCXX14_CONSTEXPR
3427 minmax_element(_ForwardIterator __first, _ForwardIterator __last,
3431 __glibcxx_function_requires(_ForwardIteratorConcept<_ForwardIterator>)
3432 __glibcxx_function_requires(_BinaryPredicateConcept<_Compare,
3433 typename iterator_traits<_ForwardIterator>::value_type,
3434 typename iterator_traits<_ForwardIterator>::value_type>)
3435 __glibcxx_requires_valid_range(__first, __last);
3437 return std::__minmax_element(__first, __last,
3438 __gnu_cxx::__ops::__iter_comp_iter(__comp));
3442 template<
typename _Tp>
3443 _GLIBCXX14_CONSTEXPR
3448 template<
typename _Tp,
typename _Compare>
3449 _GLIBCXX14_CONSTEXPR
3454 template<
typename _Tp>
3455 _GLIBCXX14_CONSTEXPR
3460 template<
typename _Tp,
typename _Compare>
3461 _GLIBCXX14_CONSTEXPR
3466 template<
typename _Tp>
3467 _GLIBCXX14_CONSTEXPR
3476 template<
typename _Tp,
typename _Compare>
3477 _GLIBCXX14_CONSTEXPR
3486 template<
typename _ForwardIterator1,
typename _ForwardIterator2,
3487 typename _BinaryPredicate>
3489 __is_permutation(_ForwardIterator1 __first1, _ForwardIterator1 __last1,
3490 _ForwardIterator2 __first2, _BinaryPredicate __pred)
3494 for (; __first1 != __last1; ++__first1, ++__first2)
3495 if (!__pred(__first1, __first2))
3498 if (__first1 == __last1)
3503 _ForwardIterator2 __last2 = __first2;
3505 for (_ForwardIterator1 __scan = __first1; __scan != __last1; ++__scan)
3508 __gnu_cxx::__ops::__iter_comp_iter(__pred, __scan)))
3512 = std::__count_if(__first2, __last2,
3513 __gnu_cxx::__ops::__iter_comp_iter(__pred, __scan));
3514 if (0 == __matches ||
3515 std::__count_if(__scan, __last1,
3516 __gnu_cxx::__ops::__iter_comp_iter(__pred, __scan))
3535 template<
typename _ForwardIterator1,
typename _ForwardIterator2>
3537 is_permutation(_ForwardIterator1 __first1, _ForwardIterator1 __last1,
3538 _ForwardIterator2 __first2)
3541 __glibcxx_function_requires(_ForwardIteratorConcept<_ForwardIterator1>)
3542 __glibcxx_function_requires(_ForwardIteratorConcept<_ForwardIterator2>)
3543 __glibcxx_function_requires(_EqualOpConcept<
3544 typename iterator_traits<_ForwardIterator1>::value_type,
3545 typename iterator_traits<_ForwardIterator2>::value_type>)
3546 __glibcxx_requires_valid_range(__first1, __last1);
3548 return std::__is_permutation(__first1, __last1, __first2,
3549 __gnu_cxx::__ops::__iter_equal_to_iter());
3566 template<
typename _ForwardIterator1,
typename _ForwardIterator2,
3567 typename _BinaryPredicate>
3569 is_permutation(_ForwardIterator1 __first1, _ForwardIterator1 __last1,
3570 _ForwardIterator2 __first2, _BinaryPredicate __pred)
3573 __glibcxx_function_requires(_ForwardIteratorConcept<_ForwardIterator1>)
3574 __glibcxx_function_requires(_ForwardIteratorConcept<_ForwardIterator2>)
3575 __glibcxx_function_requires(_BinaryPredicateConcept<_BinaryPredicate,
3576 typename iterator_traits<_ForwardIterator1>::value_type,
3577 typename iterator_traits<_ForwardIterator2>::value_type>)
3578 __glibcxx_requires_valid_range(__first1, __last1);
3580 return std::__is_permutation(__first1, __last1, __first2,
3581 __gnu_cxx::__ops::__iter_comp_iter(__pred));
3584 #if __cplusplus > 201103L 3585 template<
typename _ForwardIterator1,
typename _ForwardIterator2,
3586 typename _BinaryPredicate>
3588 __is_permutation(_ForwardIterator1 __first1, _ForwardIterator1 __last1,
3589 _ForwardIterator2 __first2, _ForwardIterator2 __last2,
3590 _BinaryPredicate __pred)
3593 =
typename iterator_traits<_ForwardIterator1>::iterator_category;
3595 =
typename iterator_traits<_ForwardIterator2>::iterator_category;
3596 using _It1_is_RA = is_same<_Cat1, random_access_iterator_tag>;
3597 using _It2_is_RA = is_same<_Cat2, random_access_iterator_tag>;
3598 constexpr
bool __ra_iters = _It1_is_RA() && _It2_is_RA();
3609 for (; __first1 != __last1 && __first2 != __last2;
3610 ++__first1, ++__first2)
3611 if (!__pred(__first1, __first2))
3616 if (__first1 == __last1)
3623 if (__d1 == 0 && __d2 == 0)
3629 for (_ForwardIterator1 __scan = __first1; __scan != __last1; ++__scan)
3632 __gnu_cxx::__ops::__iter_comp_iter(__pred, __scan)))
3635 auto __matches = std::__count_if(__first2, __last2,
3636 __gnu_cxx::__ops::__iter_comp_iter(__pred, __scan));
3638 || std::__count_if(__scan, __last1,
3639 __gnu_cxx::__ops::__iter_comp_iter(__pred, __scan))
3659 template<
typename _ForwardIterator1,
typename _ForwardIterator2>
3661 is_permutation(_ForwardIterator1 __first1, _ForwardIterator1 __last1,
3662 _ForwardIterator2 __first2, _ForwardIterator2 __last2)
3664 __glibcxx_requires_valid_range(__first1, __last1);
3665 __glibcxx_requires_valid_range(__first2, __last2);
3668 std::__is_permutation(__first1, __last1, __first2, __last2,
3669 __gnu_cxx::__ops::__iter_equal_to_iter());
3686 template<
typename _ForwardIterator1,
typename _ForwardIterator2,
3687 typename _BinaryPredicate>
3689 is_permutation(_ForwardIterator1 __first1, _ForwardIterator1 __last1,
3690 _ForwardIterator2 __first2, _ForwardIterator2 __last2,
3691 _BinaryPredicate __pred)
3693 __glibcxx_requires_valid_range(__first1, __last1);
3694 __glibcxx_requires_valid_range(__first2, __last2);
3696 return std::__is_permutation(__first1, __last1, __first2, __last2,
3697 __gnu_cxx::__ops::__iter_comp_iter(__pred));
3701 #ifdef _GLIBCXX_USE_C99_STDINT_TR1 3714 template<
typename _RandomAccessIterator,
3715 typename _UniformRandomNumberGenerator>
3717 shuffle(_RandomAccessIterator __first, _RandomAccessIterator __last,
3718 _UniformRandomNumberGenerator&& __g)
3721 __glibcxx_function_requires(_Mutable_RandomAccessIteratorConcept<
3722 _RandomAccessIterator>)
3723 __glibcxx_requires_valid_range(__first, __last);
3725 if (__first == __last)
3728 typedef typename iterator_traits<_RandomAccessIterator>::difference_type
3731 typedef typename std::make_unsigned<_DistanceType>::type __ud_type;
3733 typedef typename __distr_type::param_type __p_type;
3736 for (_RandomAccessIterator __i = __first + 1; __i != __last; ++__i)
3737 std::iter_swap(__i, __first + __d(__g, __p_type(0, __i - __first)));
3743 _GLIBCXX_END_NAMESPACE_VERSION
3745 _GLIBCXX_BEGIN_NAMESPACE_ALGO
3759 template<
typename _InputIterator,
typename _Function>
3761 for_each(_InputIterator __first, _InputIterator __last, _Function __f)
3764 __glibcxx_function_requires(_InputIteratorConcept<_InputIterator>)
3765 __glibcxx_requires_valid_range(__first, __last);
3766 for (; __first != __last; ++__first)
3768 return _GLIBCXX_MOVE(__f);
3780 template<
typename _InputIterator,
typename _Tp>
3781 inline _InputIterator
3782 find(_InputIterator __first, _InputIterator __last,
3786 __glibcxx_function_requires(_InputIteratorConcept<_InputIterator>)
3787 __glibcxx_function_requires(_EqualOpConcept<
3788 typename iterator_traits<_InputIterator>::value_type, _Tp>)
3789 __glibcxx_requires_valid_range(__first, __last);
3791 __gnu_cxx::__ops::__iter_equals_val(__val));
3804 template<
typename _InputIterator,
typename _Predicate>
3805 inline _InputIterator
3806 find_if(_InputIterator __first, _InputIterator __last,
3810 __glibcxx_function_requires(_InputIteratorConcept<_InputIterator>)
3811 __glibcxx_function_requires(_UnaryPredicateConcept<_Predicate,
3812 typename iterator_traits<_InputIterator>::value_type>)
3813 __glibcxx_requires_valid_range(__first, __last);
3816 __gnu_cxx::__ops::__pred_iter(__pred));
3835 template<
typename _InputIterator,
typename _ForwardIterator>
3837 find_first_of(_InputIterator __first1, _InputIterator __last1,
3838 _ForwardIterator __first2, _ForwardIterator __last2)
3841 __glibcxx_function_requires(_InputIteratorConcept<_InputIterator>)
3842 __glibcxx_function_requires(_ForwardIteratorConcept<_ForwardIterator>)
3843 __glibcxx_function_requires(_EqualOpConcept<
3844 typename iterator_traits<_InputIterator>::value_type,
3845 typename iterator_traits<_ForwardIterator>::value_type>)
3846 __glibcxx_requires_valid_range(__first1, __last1);
3847 __glibcxx_requires_valid_range(__first2, __last2);
3849 for (; __first1 != __last1; ++__first1)
3850 for (_ForwardIterator __iter = __first2; __iter != __last2; ++__iter)
3851 if (*__first1 == *__iter)
3875 template<
typename _InputIterator,
typename _ForwardIterator,
3876 typename _BinaryPredicate>
3878 find_first_of(_InputIterator __first1, _InputIterator __last1,
3879 _ForwardIterator __first2, _ForwardIterator __last2,
3880 _BinaryPredicate __comp)
3883 __glibcxx_function_requires(_InputIteratorConcept<_InputIterator>)
3884 __glibcxx_function_requires(_ForwardIteratorConcept<_ForwardIterator>)
3885 __glibcxx_function_requires(_BinaryPredicateConcept<_BinaryPredicate,
3886 typename iterator_traits<_InputIterator>::value_type,
3887 typename iterator_traits<_ForwardIterator>::value_type>)
3888 __glibcxx_requires_valid_range(__first1, __last1);
3889 __glibcxx_requires_valid_range(__first2, __last2);
3891 for (; __first1 != __last1; ++__first1)
3892 for (_ForwardIterator __iter = __first2; __iter != __last2; ++__iter)
3893 if (__comp(*__first1, *__iter))
3907 template<
typename _ForwardIterator>
3908 inline _ForwardIterator
3909 adjacent_find(_ForwardIterator __first, _ForwardIterator __last)
3912 __glibcxx_function_requires(_ForwardIteratorConcept<_ForwardIterator>)
3913 __glibcxx_function_requires(_EqualityComparableConcept<
3914 typename iterator_traits<_ForwardIterator>::value_type>)
3915 __glibcxx_requires_valid_range(__first, __last);
3917 return std::__adjacent_find(__first, __last,
3918 __gnu_cxx::__ops::__iter_equal_to_iter());
3932 template<
typename _ForwardIterator,
typename _BinaryPredicate>
3933 inline _ForwardIterator
3934 adjacent_find(_ForwardIterator __first, _ForwardIterator __last,
3935 _BinaryPredicate __binary_pred)
3938 __glibcxx_function_requires(_ForwardIteratorConcept<_ForwardIterator>)
3939 __glibcxx_function_requires(_BinaryPredicateConcept<_BinaryPredicate,
3940 typename iterator_traits<_ForwardIterator>::value_type,
3941 typename iterator_traits<_ForwardIterator>::value_type>)
3942 __glibcxx_requires_valid_range(__first, __last);
3944 return std::__adjacent_find(__first, __last,
3945 __gnu_cxx::__ops::__iter_comp_iter(__binary_pred));
3957 template<
typename _InputIterator,
typename _Tp>
3958 inline typename iterator_traits<_InputIterator>::difference_type
3959 count(_InputIterator __first, _InputIterator __last,
const _Tp& __value)
3962 __glibcxx_function_requires(_InputIteratorConcept<_InputIterator>)
3963 __glibcxx_function_requires(_EqualOpConcept<
3964 typename iterator_traits<_InputIterator>::value_type, _Tp>)
3965 __glibcxx_requires_valid_range(__first, __last);
3967 return std::__count_if(__first, __last,
3968 __gnu_cxx::__ops::__iter_equals_val(__value));
3980 template<
typename _InputIterator,
typename _Predicate>
3981 inline typename iterator_traits<_InputIterator>::difference_type
3982 count_if(_InputIterator __first, _InputIterator __last, _Predicate __pred)
3985 __glibcxx_function_requires(_InputIteratorConcept<_InputIterator>)
3986 __glibcxx_function_requires(_UnaryPredicateConcept<_Predicate,
3987 typename iterator_traits<_InputIterator>::value_type>)
3988 __glibcxx_requires_valid_range(__first, __last);
3990 return std::__count_if(__first, __last,
3991 __gnu_cxx::__ops::__pred_iter(__pred));
4020 template<
typename _ForwardIterator1,
typename _ForwardIterator2>
4021 inline _ForwardIterator1
4022 search(_ForwardIterator1 __first1, _ForwardIterator1 __last1,
4023 _ForwardIterator2 __first2, _ForwardIterator2 __last2)
4026 __glibcxx_function_requires(_ForwardIteratorConcept<_ForwardIterator1>)
4027 __glibcxx_function_requires(_ForwardIteratorConcept<_ForwardIterator2>)
4028 __glibcxx_function_requires(_EqualOpConcept<
4029 typename iterator_traits<_ForwardIterator1>::value_type,
4030 typename iterator_traits<_ForwardIterator2>::value_type>)
4031 __glibcxx_requires_valid_range(__first1, __last1);
4032 __glibcxx_requires_valid_range(__first2, __last2);
4034 return std::__search(__first1, __last1, __first2, __last2,
4035 __gnu_cxx::__ops::__iter_equal_to_iter());
4059 template<
typename _ForwardIterator1,
typename _ForwardIterator2,
4060 typename _BinaryPredicate>
4061 inline _ForwardIterator1
4062 search(_ForwardIterator1 __first1, _ForwardIterator1 __last1,
4063 _ForwardIterator2 __first2, _ForwardIterator2 __last2,
4064 _BinaryPredicate __predicate)
4067 __glibcxx_function_requires(_ForwardIteratorConcept<_ForwardIterator1>)
4068 __glibcxx_function_requires(_ForwardIteratorConcept<_ForwardIterator2>)
4069 __glibcxx_function_requires(_BinaryPredicateConcept<_BinaryPredicate,
4070 typename iterator_traits<_ForwardIterator1>::value_type,
4071 typename iterator_traits<_ForwardIterator2>::value_type>)
4072 __glibcxx_requires_valid_range(__first1, __last1);
4073 __glibcxx_requires_valid_range(__first2, __last2);
4075 return std::__search(__first1, __last1, __first2, __last2,
4076 __gnu_cxx::__ops::__iter_comp_iter(__predicate));
4094 template<
typename _ForwardIterator,
typename _Integer,
typename _Tp>
4095 inline _ForwardIterator
4096 search_n(_ForwardIterator __first, _ForwardIterator __last,
4097 _Integer __count,
const _Tp& __val)
4100 __glibcxx_function_requires(_ForwardIteratorConcept<_ForwardIterator>)
4101 __glibcxx_function_requires(_EqualOpConcept<
4102 typename iterator_traits<_ForwardIterator>::value_type, _Tp>)
4103 __glibcxx_requires_valid_range(__first, __last);
4105 return std::__search_n(__first, __last, __count,
4106 __gnu_cxx::__ops::__iter_equals_val(__val));
4127 template<
typename _ForwardIterator,
typename _Integer,
typename _Tp,
4128 typename _BinaryPredicate>
4129 inline _ForwardIterator
4130 search_n(_ForwardIterator __first, _ForwardIterator __last,
4131 _Integer __count,
const _Tp& __val,
4132 _BinaryPredicate __binary_pred)
4135 __glibcxx_function_requires(_ForwardIteratorConcept<_ForwardIterator>)
4136 __glibcxx_function_requires(_BinaryPredicateConcept<_BinaryPredicate,
4137 typename iterator_traits<_ForwardIterator>::value_type, _Tp>)
4138 __glibcxx_requires_valid_range(__first, __last);
4140 return std::__search_n(__first, __last, __count,
4141 __gnu_cxx::__ops::__iter_comp_val(__binary_pred, __val));
4161 template<
typename _InputIterator,
typename _OutputIterator,
4162 typename _UnaryOperation>
4164 transform(_InputIterator __first, _InputIterator __last,
4165 _OutputIterator __result, _UnaryOperation __unary_op)
4168 __glibcxx_function_requires(_InputIteratorConcept<_InputIterator>)
4169 __glibcxx_function_requires(_OutputIteratorConcept<_OutputIterator,
4171 __typeof__(__unary_op(*__first))>)
4172 __glibcxx_requires_valid_range(__first, __last);
4174 for (; __first != __last; ++__first, ++__result)
4175 *__result = __unary_op(*__first);
4198 template<
typename _InputIterator1,
typename _InputIterator2,
4199 typename _OutputIterator,
typename _BinaryOperation>
4201 transform(_InputIterator1 __first1, _InputIterator1 __last1,
4202 _InputIterator2 __first2, _OutputIterator __result,
4203 _BinaryOperation __binary_op)
4206 __glibcxx_function_requires(_InputIteratorConcept<_InputIterator1>)
4207 __glibcxx_function_requires(_InputIteratorConcept<_InputIterator2>)
4208 __glibcxx_function_requires(_OutputIteratorConcept<_OutputIterator,
4210 __typeof__(__binary_op(*__first1,*__first2))>)
4211 __glibcxx_requires_valid_range(__first1, __last1);
4213 for (; __first1 != __last1; ++__first1, ++__first2, ++__result)
4214 *__result = __binary_op(*__first1, *__first2);
4231 template<
typename _ForwardIterator,
typename _Tp>
4233 replace(_ForwardIterator __first, _ForwardIterator __last,
4234 const _Tp& __old_value,
const _Tp& __new_value)
4237 __glibcxx_function_requires(_Mutable_ForwardIteratorConcept<
4239 __glibcxx_function_requires(_EqualOpConcept<
4240 typename iterator_traits<_ForwardIterator>::value_type, _Tp>)
4241 __glibcxx_function_requires(_ConvertibleConcept<_Tp,
4242 typename iterator_traits<_ForwardIterator>::value_type>)
4243 __glibcxx_requires_valid_range(__first, __last);
4245 for (; __first != __last; ++__first)
4246 if (*__first == __old_value)
4247 *__first = __new_value;
4263 template<
typename _ForwardIterator,
typename _Predicate,
typename _Tp>
4265 replace_if(_ForwardIterator __first, _ForwardIterator __last,
4266 _Predicate __pred,
const _Tp& __new_value)
4269 __glibcxx_function_requires(_Mutable_ForwardIteratorConcept<
4271 __glibcxx_function_requires(_ConvertibleConcept<_Tp,
4272 typename iterator_traits<_ForwardIterator>::value_type>)
4273 __glibcxx_function_requires(_UnaryPredicateConcept<_Predicate,
4274 typename iterator_traits<_ForwardIterator>::value_type>)
4275 __glibcxx_requires_valid_range(__first, __last);
4277 for (; __first != __last; ++__first)
4278 if (__pred(*__first))
4279 *__first = __new_value;
4295 template<
typename _ForwardIterator,
typename _Generator>
4297 generate(_ForwardIterator __first, _ForwardIterator __last,
4301 __glibcxx_function_requires(_ForwardIteratorConcept<_ForwardIterator>)
4302 __glibcxx_function_requires(_GeneratorConcept<_Generator,
4303 typename iterator_traits<_ForwardIterator>::value_type>)
4304 __glibcxx_requires_valid_range(__first, __last);
4306 for (; __first != __last; ++__first)
4326 template<
typename _OutputIterator,
typename _Size,
typename _Generator>
4328 generate_n(_OutputIterator __first, _Size __n, _Generator __gen)
4331 __glibcxx_function_requires(_OutputIteratorConcept<_OutputIterator,
4333 __typeof__(__gen())>)
4335 for (__decltype(__n + 0) __niter = __n;
4336 __niter > 0; --__niter, ++__first)
4362 template<
typename _InputIterator,
typename _OutputIterator>
4363 inline _OutputIterator
4364 unique_copy(_InputIterator __first, _InputIterator __last,
4365 _OutputIterator __result)
4368 __glibcxx_function_requires(_InputIteratorConcept<_InputIterator>)
4369 __glibcxx_function_requires(_OutputIteratorConcept<_OutputIterator,
4370 typename iterator_traits<_InputIterator>::value_type>)
4371 __glibcxx_function_requires(_EqualityComparableConcept<
4372 typename iterator_traits<_InputIterator>::value_type>)
4373 __glibcxx_requires_valid_range(__first, __last);
4375 if (__first == __last)
4378 __gnu_cxx::__ops::__iter_equal_to_iter(),
4402 template<
typename _InputIterator,
typename _OutputIterator,
4403 typename _BinaryPredicate>
4404 inline _OutputIterator
4405 unique_copy(_InputIterator __first, _InputIterator __last,
4406 _OutputIterator __result,
4407 _BinaryPredicate __binary_pred)
4410 __glibcxx_function_requires(_InputIteratorConcept<_InputIterator>)
4411 __glibcxx_function_requires(_OutputIteratorConcept<_OutputIterator,
4412 typename iterator_traits<_InputIterator>::value_type>)
4413 __glibcxx_requires_valid_range(__first, __last);
4415 if (__first == __last)
4418 __gnu_cxx::__ops::__iter_comp_iter(__binary_pred),
4434 template<
typename _RandomAccessIterator>
4436 random_shuffle(_RandomAccessIterator __first, _RandomAccessIterator __last)
4439 __glibcxx_function_requires(_Mutable_RandomAccessIteratorConcept<
4440 _RandomAccessIterator>)
4441 __glibcxx_requires_valid_range(__first, __last);
4443 if (__first != __last)
4444 for (_RandomAccessIterator __i = __first + 1; __i != __last; ++__i)
4447 _RandomAccessIterator __j = __first
4448 + std::rand() % ((__i - __first) + 1);
4468 template<
typename _RandomAccessIterator,
typename _RandomNumberGenerator>
4470 random_shuffle(_RandomAccessIterator __first, _RandomAccessIterator __last,
4471 #
if __cplusplus >= 201103L
4472 _RandomNumberGenerator&& __rand)
4474 _RandomNumberGenerator& __rand)
4478 __glibcxx_function_requires(_Mutable_RandomAccessIteratorConcept<
4479 _RandomAccessIterator>)
4480 __glibcxx_requires_valid_range(__first, __last);
4482 if (__first == __last)
4484 for (_RandomAccessIterator __i = __first + 1; __i != __last; ++__i)
4486 _RandomAccessIterator __j = __first + __rand((__i - __first) + 1);
4508 template<
typename _ForwardIterator,
typename _Predicate>
4509 inline _ForwardIterator
4510 partition(_ForwardIterator __first, _ForwardIterator __last,
4514 __glibcxx_function_requires(_Mutable_ForwardIteratorConcept<
4516 __glibcxx_function_requires(_UnaryPredicateConcept<_Predicate,
4517 typename iterator_traits<_ForwardIterator>::value_type>)
4518 __glibcxx_requires_valid_range(__first, __last);
4541 template<
typename _RandomAccessIterator>
4543 partial_sort(_RandomAccessIterator __first,
4544 _RandomAccessIterator __middle,
4545 _RandomAccessIterator __last)
4548 __glibcxx_function_requires(_Mutable_RandomAccessIteratorConcept<
4549 _RandomAccessIterator>)
4550 __glibcxx_function_requires(_LessThanComparableConcept<
4551 typename iterator_traits<_RandomAccessIterator>::value_type>)
4552 __glibcxx_requires_valid_range(__first, __middle);
4553 __glibcxx_requires_valid_range(__middle, __last);
4555 std::__partial_sort(__first, __middle, __last,
4556 __gnu_cxx::__ops::__iter_less_iter());
4578 template<
typename _RandomAccessIterator,
typename _Compare>
4580 partial_sort(_RandomAccessIterator __first,
4581 _RandomAccessIterator __middle,
4582 _RandomAccessIterator __last,
4586 __glibcxx_function_requires(_Mutable_RandomAccessIteratorConcept<
4587 _RandomAccessIterator>)
4588 __glibcxx_function_requires(_BinaryPredicateConcept<_Compare,
4589 typename iterator_traits<_RandomAccessIterator>::value_type,
4590 typename iterator_traits<_RandomAccessIterator>::value_type>)
4591 __glibcxx_requires_valid_range(__first, __middle);
4592 __glibcxx_requires_valid_range(__middle, __last);
4594 std::__partial_sort(__first, __middle, __last,
4595 __gnu_cxx::__ops::__iter_comp_iter(__comp));
4613 template<
typename _RandomAccessIterator>
4615 nth_element(_RandomAccessIterator __first, _RandomAccessIterator __nth,
4616 _RandomAccessIterator __last)
4619 __glibcxx_function_requires(_Mutable_RandomAccessIteratorConcept<
4620 _RandomAccessIterator>)
4621 __glibcxx_function_requires(_LessThanComparableConcept<
4622 typename iterator_traits<_RandomAccessIterator>::value_type>)
4623 __glibcxx_requires_valid_range(__first, __nth);
4624 __glibcxx_requires_valid_range(__nth, __last);
4626 if (__first == __last || __nth == __last)
4629 std::__introselect(__first, __nth, __last,
4631 __gnu_cxx::__ops::__iter_less_iter());
4651 template<
typename _RandomAccessIterator,
typename _Compare>
4653 nth_element(_RandomAccessIterator __first, _RandomAccessIterator __nth,
4654 _RandomAccessIterator __last, _Compare __comp)
4657 __glibcxx_function_requires(_Mutable_RandomAccessIteratorConcept<
4658 _RandomAccessIterator>)
4659 __glibcxx_function_requires(_BinaryPredicateConcept<_Compare,
4660 typename iterator_traits<_RandomAccessIterator>::value_type,
4661 typename iterator_traits<_RandomAccessIterator>::value_type>)
4662 __glibcxx_requires_valid_range(__first, __nth);
4663 __glibcxx_requires_valid_range(__nth, __last);
4665 if (__first == __last || __nth == __last)
4668 std::__introselect(__first, __nth, __last,
4670 __gnu_cxx::__ops::__iter_comp_iter(__comp));
4687 template<
typename _RandomAccessIterator>
4689 sort(_RandomAccessIterator __first, _RandomAccessIterator __last)
4692 __glibcxx_function_requires(_Mutable_RandomAccessIteratorConcept<
4693 _RandomAccessIterator>)
4694 __glibcxx_function_requires(_LessThanComparableConcept<
4695 typename iterator_traits<_RandomAccessIterator>::value_type>)
4696 __glibcxx_requires_valid_range(__first, __last);
4698 std::__sort(__first, __last, __gnu_cxx::__ops::__iter_less_iter());
4716 template<
typename _RandomAccessIterator,
typename _Compare>
4718 sort(_RandomAccessIterator __first, _RandomAccessIterator __last,
4722 __glibcxx_function_requires(_Mutable_RandomAccessIteratorConcept<
4723 _RandomAccessIterator>)
4724 __glibcxx_function_requires(_BinaryPredicateConcept<_Compare,
4725 typename iterator_traits<_RandomAccessIterator>::value_type,
4726 typename iterator_traits<_RandomAccessIterator>::value_type>)
4727 __glibcxx_requires_valid_range(__first, __last);
4729 std::__sort(__first, __last, __gnu_cxx::__ops::__iter_comp_iter(__comp));
4732 template<
typename _InputIterator1,
typename _InputIterator2,
4733 typename _OutputIterator,
typename _Compare>
4735 __merge(_InputIterator1 __first1, _InputIterator1 __last1,
4736 _InputIterator2 __first2, _InputIterator2 __last2,
4737 _OutputIterator __result, _Compare __comp)
4739 while (__first1 != __last1 && __first2 != __last2)
4741 if (__comp(__first2, __first1))
4743 *__result = *__first2;
4748 *__result = *__first1;
4753 return std::copy(__first2, __last2,
4754 std::copy(__first1, __last1, __result));
4776 template<
typename _InputIterator1,
typename _InputIterator2,
4777 typename _OutputIterator>
4778 inline _OutputIterator
4779 merge(_InputIterator1 __first1, _InputIterator1 __last1,
4780 _InputIterator2 __first2, _InputIterator2 __last2,
4781 _OutputIterator __result)
4784 __glibcxx_function_requires(_InputIteratorConcept<_InputIterator1>)
4785 __glibcxx_function_requires(_InputIteratorConcept<_InputIterator2>)
4786 __glibcxx_function_requires(_OutputIteratorConcept<_OutputIterator,
4787 typename iterator_traits<_InputIterator1>::value_type>)
4788 __glibcxx_function_requires(_OutputIteratorConcept<_OutputIterator,
4789 typename iterator_traits<_InputIterator2>::value_type>)
4790 __glibcxx_function_requires(_LessThanOpConcept<
4791 typename iterator_traits<_InputIterator2>::value_type,
4792 typename iterator_traits<_InputIterator1>::value_type>)
4793 __glibcxx_requires_sorted_set(__first1, __last1, __first2);
4794 __glibcxx_requires_sorted_set(__first2, __last2, __first1);
4796 return _GLIBCXX_STD_A::__merge(__first1, __last1,
4797 __first2, __last2, __result,
4798 __gnu_cxx::__ops::__iter_less_iter());
4824 template<
typename _InputIterator1,
typename _InputIterator2,
4825 typename _OutputIterator,
typename _Compare>
4826 inline _OutputIterator
4827 merge(_InputIterator1 __first1, _InputIterator1 __last1,
4828 _InputIterator2 __first2, _InputIterator2 __last2,
4829 _OutputIterator __result, _Compare __comp)
4832 __glibcxx_function_requires(_InputIteratorConcept<_InputIterator1>)
4833 __glibcxx_function_requires(_InputIteratorConcept<_InputIterator2>)
4834 __glibcxx_function_requires(_OutputIteratorConcept<_OutputIterator,
4835 typename iterator_traits<_InputIterator1>::value_type>)
4836 __glibcxx_function_requires(_OutputIteratorConcept<_OutputIterator,
4837 typename iterator_traits<_InputIterator2>::value_type>)
4838 __glibcxx_function_requires(_BinaryPredicateConcept<_Compare,
4839 typename iterator_traits<_InputIterator2>::value_type,
4840 typename iterator_traits<_InputIterator1>::value_type>)
4841 __glibcxx_requires_sorted_set_pred(__first1, __last1, __first2, __comp);
4842 __glibcxx_requires_sorted_set_pred(__first2, __last2, __first1, __comp);
4844 return _GLIBCXX_STD_A::__merge(__first1, __last1,
4845 __first2, __last2, __result,
4846 __gnu_cxx::__ops::__iter_comp_iter(__comp));
4849 template<
typename _RandomAccessIterator,
typename _Compare>
4851 __stable_sort(_RandomAccessIterator __first, _RandomAccessIterator __last,
4854 typedef typename iterator_traits<_RandomAccessIterator>::value_type
4856 typedef typename iterator_traits<_RandomAccessIterator>::difference_type
4860 _TmpBuf __buf(__first, __last);
4862 if (__buf.begin() == 0)
4865 std::__stable_sort_adaptive(__first, __last, __buf.begin(),
4866 _DistanceType(__buf.size()), __comp);
4886 template<
typename _RandomAccessIterator>
4888 stable_sort(_RandomAccessIterator __first, _RandomAccessIterator __last)
4891 __glibcxx_function_requires(_Mutable_RandomAccessIteratorConcept<
4892 _RandomAccessIterator>)
4893 __glibcxx_function_requires(_LessThanComparableConcept<
4894 typename iterator_traits<_RandomAccessIterator>::value_type>)
4895 __glibcxx_requires_valid_range(__first, __last);
4897 _GLIBCXX_STD_A::__stable_sort(__first, __last,
4898 __gnu_cxx::__ops::__iter_less_iter());
4919 template<
typename _RandomAccessIterator,
typename _Compare>
4921 stable_sort(_RandomAccessIterator __first, _RandomAccessIterator __last,
4925 __glibcxx_function_requires(_Mutable_RandomAccessIteratorConcept<
4926 _RandomAccessIterator>)
4927 __glibcxx_function_requires(_BinaryPredicateConcept<_Compare,
4928 typename iterator_traits<_RandomAccessIterator>::value_type,
4929 typename iterator_traits<_RandomAccessIterator>::value_type>)
4930 __glibcxx_requires_valid_range(__first, __last);
4932 _GLIBCXX_STD_A::__stable_sort(__first, __last,
4933 __gnu_cxx::__ops::__iter_comp_iter(__comp));
4936 template<
typename _InputIterator1,
typename _InputIterator2,
4937 typename _OutputIterator,
4940 __set_union(_InputIterator1 __first1, _InputIterator1 __last1,
4941 _InputIterator2 __first2, _InputIterator2 __last2,
4942 _OutputIterator __result, _Compare __comp)
4944 while (__first1 != __last1 && __first2 != __last2)
4946 if (__comp(__first1, __first2))
4948 *__result = *__first1;
4951 else if (__comp(__first2, __first1))
4953 *__result = *__first2;
4958 *__result = *__first1;
4964 return std::copy(__first2, __last2,
4965 std::copy(__first1, __last1, __result));
4986 template<
typename _InputIterator1,
typename _InputIterator2,
4987 typename _OutputIterator>
4988 inline _OutputIterator
4989 set_union(_InputIterator1 __first1, _InputIterator1 __last1,
4990 _InputIterator2 __first2, _InputIterator2 __last2,
4991 _OutputIterator __result)
4994 __glibcxx_function_requires(_InputIteratorConcept<_InputIterator1>)
4995 __glibcxx_function_requires(_InputIteratorConcept<_InputIterator2>)
4996 __glibcxx_function_requires(_OutputIteratorConcept<_OutputIterator,
4997 typename iterator_traits<_InputIterator1>::value_type>)
4998 __glibcxx_function_requires(_OutputIteratorConcept<_OutputIterator,
4999 typename iterator_traits<_InputIterator2>::value_type>)
5000 __glibcxx_function_requires(_LessThanOpConcept<
5001 typename iterator_traits<_InputIterator1>::value_type,
5002 typename iterator_traits<_InputIterator2>::value_type>)
5003 __glibcxx_function_requires(_LessThanOpConcept<
5004 typename iterator_traits<_InputIterator2>::value_type,
5005 typename iterator_traits<_InputIterator1>::value_type>)
5006 __glibcxx_requires_sorted_set(__first1, __last1, __first2);
5007 __glibcxx_requires_sorted_set(__first2, __last2, __first1);
5009 return _GLIBCXX_STD_A::__set_union(__first1, __last1,
5010 __first2, __last2, __result,
5011 __gnu_cxx::__ops::__iter_less_iter());
5033 template<
typename _InputIterator1,
typename _InputIterator2,
5034 typename _OutputIterator,
typename _Compare>
5035 inline _OutputIterator
5036 set_union(_InputIterator1 __first1, _InputIterator1 __last1,
5037 _InputIterator2 __first2, _InputIterator2 __last2,
5038 _OutputIterator __result, _Compare __comp)
5041 __glibcxx_function_requires(_InputIteratorConcept<_InputIterator1>)
5042 __glibcxx_function_requires(_InputIteratorConcept<_InputIterator2>)
5043 __glibcxx_function_requires(_OutputIteratorConcept<_OutputIterator,
5044 typename iterator_traits<_InputIterator1>::value_type>)
5045 __glibcxx_function_requires(_OutputIteratorConcept<_OutputIterator,
5046 typename iterator_traits<_InputIterator2>::value_type>)
5047 __glibcxx_function_requires(_BinaryPredicateConcept<_Compare,
5048 typename iterator_traits<_InputIterator1>::value_type,
5049 typename iterator_traits<_InputIterator2>::value_type>)
5050 __glibcxx_function_requires(_BinaryPredicateConcept<_Compare,
5051 typename iterator_traits<_InputIterator2>::value_type,
5052 typename iterator_traits<_InputIterator1>::value_type>)
5053 __glibcxx_requires_sorted_set_pred(__first1, __last1, __first2, __comp);
5054 __glibcxx_requires_sorted_set_pred(__first2, __last2, __first1, __comp);
5056 return _GLIBCXX_STD_A::__set_union(__first1, __last1,
5057 __first2, __last2, __result,
5058 __gnu_cxx::__ops::__iter_comp_iter(__comp));
5061 template<
typename _InputIterator1,
typename _InputIterator2,
5062 typename _OutputIterator,
5065 __set_intersection(_InputIterator1 __first1, _InputIterator1 __last1,
5066 _InputIterator2 __first2, _InputIterator2 __last2,
5067 _OutputIterator __result, _Compare __comp)
5069 while (__first1 != __last1 && __first2 != __last2)
5070 if (__comp(__first1, __first2))
5072 else if (__comp(__first2, __first1))
5076 *__result = *__first1;
5101 template<
typename _InputIterator1,
typename _InputIterator2,
5102 typename _OutputIterator>
5103 inline _OutputIterator
5104 set_intersection(_InputIterator1 __first1, _InputIterator1 __last1,
5105 _InputIterator2 __first2, _InputIterator2 __last2,
5106 _OutputIterator __result)
5109 __glibcxx_function_requires(_InputIteratorConcept<_InputIterator1>)
5110 __glibcxx_function_requires(_InputIteratorConcept<_InputIterator2>)
5111 __glibcxx_function_requires(_OutputIteratorConcept<_OutputIterator,
5112 typename iterator_traits<_InputIterator1>::value_type>)
5113 __glibcxx_function_requires(_LessThanOpConcept<
5114 typename iterator_traits<_InputIterator1>::value_type,
5115 typename iterator_traits<_InputIterator2>::value_type>)
5116 __glibcxx_function_requires(_LessThanOpConcept<
5117 typename iterator_traits<_InputIterator2>::value_type,
5118 typename iterator_traits<_InputIterator1>::value_type>)
5119 __glibcxx_requires_sorted_set(__first1, __last1, __first2);
5120 __glibcxx_requires_sorted_set(__first2, __last2, __first1);
5122 return _GLIBCXX_STD_A::__set_intersection(__first1, __last1,
5123 __first2, __last2, __result,
5124 __gnu_cxx::__ops::__iter_less_iter());
5147 template<
typename _InputIterator1,
typename _InputIterator2,
5148 typename _OutputIterator,
typename _Compare>
5149 inline _OutputIterator
5150 set_intersection(_InputIterator1 __first1, _InputIterator1 __last1,
5151 _InputIterator2 __first2, _InputIterator2 __last2,
5152 _OutputIterator __result, _Compare __comp)
5155 __glibcxx_function_requires(_InputIteratorConcept<_InputIterator1>)
5156 __glibcxx_function_requires(_InputIteratorConcept<_InputIterator2>)
5157 __glibcxx_function_requires(_OutputIteratorConcept<_OutputIterator,
5158 typename iterator_traits<_InputIterator1>::value_type>)
5159 __glibcxx_function_requires(_BinaryPredicateConcept<_Compare,
5160 typename iterator_traits<_InputIterator1>::value_type,
5161 typename iterator_traits<_InputIterator2>::value_type>)
5162 __glibcxx_function_requires(_BinaryPredicateConcept<_Compare,
5163 typename iterator_traits<_InputIterator2>::value_type,
5164 typename iterator_traits<_InputIterator1>::value_type>)
5165 __glibcxx_requires_sorted_set_pred(__first1, __last1, __first2, __comp);
5166 __glibcxx_requires_sorted_set_pred(__first2, __last2, __first1, __comp);
5168 return _GLIBCXX_STD_A::__set_intersection(__first1, __last1,
5169 __first2, __last2, __result,
5170 __gnu_cxx::__ops::__iter_comp_iter(__comp));
5173 template<
typename _InputIterator1,
typename _InputIterator2,
5174 typename _OutputIterator,
5177 __set_difference(_InputIterator1 __first1, _InputIterator1 __last1,
5178 _InputIterator2 __first2, _InputIterator2 __last2,
5179 _OutputIterator __result, _Compare __comp)
5181 while (__first1 != __last1 && __first2 != __last2)
5182 if (__comp(__first1, __first2))
5184 *__result = *__first1;
5188 else if (__comp(__first2, __first1))
5195 return std::copy(__first1, __last1, __result);
5217 template<
typename _InputIterator1,
typename _InputIterator2,
5218 typename _OutputIterator>
5219 inline _OutputIterator
5220 set_difference(_InputIterator1 __first1, _InputIterator1 __last1,
5221 _InputIterator2 __first2, _InputIterator2 __last2,
5222 _OutputIterator __result)
5225 __glibcxx_function_requires(_InputIteratorConcept<_InputIterator1>)
5226 __glibcxx_function_requires(_InputIteratorConcept<_InputIterator2>)
5227 __glibcxx_function_requires(_OutputIteratorConcept<_OutputIterator,
5228 typename iterator_traits<_InputIterator1>::value_type>)
5229 __glibcxx_function_requires(_LessThanOpConcept<
5230 typename iterator_traits<_InputIterator1>::value_type,
5231 typename iterator_traits<_InputIterator2>::value_type>)
5232 __glibcxx_function_requires(_LessThanOpConcept<
5233 typename iterator_traits<_InputIterator2>::value_type,
5234 typename iterator_traits<_InputIterator1>::value_type>)
5235 __glibcxx_requires_sorted_set(__first1, __last1, __first2);
5236 __glibcxx_requires_sorted_set(__first2, __last2, __first1);
5238 return _GLIBCXX_STD_A::__set_difference(__first1, __last1,
5239 __first2, __last2, __result,
5240 __gnu_cxx::__ops::__iter_less_iter());
5265 template<
typename _InputIterator1,
typename _InputIterator2,
5266 typename _OutputIterator,
typename _Compare>
5267 inline _OutputIterator
5268 set_difference(_InputIterator1 __first1, _InputIterator1 __last1,
5269 _InputIterator2 __first2, _InputIterator2 __last2,
5270 _OutputIterator __result, _Compare __comp)
5273 __glibcxx_function_requires(_InputIteratorConcept<_InputIterator1>)
5274 __glibcxx_function_requires(_InputIteratorConcept<_InputIterator2>)
5275 __glibcxx_function_requires(_OutputIteratorConcept<_OutputIterator,
5276 typename iterator_traits<_InputIterator1>::value_type>)
5277 __glibcxx_function_requires(_BinaryPredicateConcept<_Compare,
5278 typename iterator_traits<_InputIterator1>::value_type,
5279 typename iterator_traits<_InputIterator2>::value_type>)
5280 __glibcxx_function_requires(_BinaryPredicateConcept<_Compare,
5281 typename iterator_traits<_InputIterator2>::value_type,
5282 typename iterator_traits<_InputIterator1>::value_type>)
5283 __glibcxx_requires_sorted_set_pred(__first1, __last1, __first2, __comp);
5284 __glibcxx_requires_sorted_set_pred(__first2, __last2, __first1, __comp);
5286 return _GLIBCXX_STD_A::__set_difference(__first1, __last1,
5287 __first2, __last2, __result,
5288 __gnu_cxx::__ops::__iter_comp_iter(__comp));
5291 template<
typename _InputIterator1,
typename _InputIterator2,
5292 typename _OutputIterator,
5295 __set_symmetric_difference(_InputIterator1 __first1,
5296 _InputIterator1 __last1,
5297 _InputIterator2 __first2,
5298 _InputIterator2 __last2,
5299 _OutputIterator __result,
5302 while (__first1 != __last1 && __first2 != __last2)
5303 if (__comp(__first1, __first2))
5305 *__result = *__first1;
5309 else if (__comp(__first2, __first1))
5311 *__result = *__first2;
5320 return std::copy(__first2, __last2,
5321 std::copy(__first1, __last1, __result));
5341 template<
typename _InputIterator1,
typename _InputIterator2,
5342 typename _OutputIterator>
5343 inline _OutputIterator
5344 set_symmetric_difference(_InputIterator1 __first1, _InputIterator1 __last1,
5345 _InputIterator2 __first2, _InputIterator2 __last2,
5346 _OutputIterator __result)
5349 __glibcxx_function_requires(_InputIteratorConcept<_InputIterator1>)
5350 __glibcxx_function_requires(_InputIteratorConcept<_InputIterator2>)
5351 __glibcxx_function_requires(_OutputIteratorConcept<_OutputIterator,
5352 typename iterator_traits<_InputIterator1>::value_type>)
5353 __glibcxx_function_requires(_OutputIteratorConcept<_OutputIterator,
5354 typename iterator_traits<_InputIterator2>::value_type>)
5355 __glibcxx_function_requires(_LessThanOpConcept<
5356 typename iterator_traits<_InputIterator1>::value_type,
5357 typename iterator_traits<_InputIterator2>::value_type>)
5358 __glibcxx_function_requires(_LessThanOpConcept<
5359 typename iterator_traits<_InputIterator2>::value_type,
5360 typename iterator_traits<_InputIterator1>::value_type>)
5361 __glibcxx_requires_sorted_set(__first1, __last1, __first2);
5362 __glibcxx_requires_sorted_set(__first2, __last2, __first1);
5364 return _GLIBCXX_STD_A::__set_symmetric_difference(__first1, __last1,
5365 __first2, __last2, __result,
5366 __gnu_cxx::__ops::__iter_less_iter());
5389 template<
typename _InputIterator1,
typename _InputIterator2,
5390 typename _OutputIterator,
typename _Compare>
5391 inline _OutputIterator
5392 set_symmetric_difference(_InputIterator1 __first1, _InputIterator1 __last1,
5393 _InputIterator2 __first2, _InputIterator2 __last2,
5394 _OutputIterator __result,
5398 __glibcxx_function_requires(_InputIteratorConcept<_InputIterator1>)
5399 __glibcxx_function_requires(_InputIteratorConcept<_InputIterator2>)
5400 __glibcxx_function_requires(_OutputIteratorConcept<_OutputIterator,
5401 typename iterator_traits<_InputIterator1>::value_type>)
5402 __glibcxx_function_requires(_OutputIteratorConcept<_OutputIterator,
5403 typename iterator_traits<_InputIterator2>::value_type>)
5404 __glibcxx_function_requires(_BinaryPredicateConcept<_Compare,
5405 typename iterator_traits<_InputIterator1>::value_type,
5406 typename iterator_traits<_InputIterator2>::value_type>)
5407 __glibcxx_function_requires(_BinaryPredicateConcept<_Compare,
5408 typename iterator_traits<_InputIterator2>::value_type,
5409 typename iterator_traits<_InputIterator1>::value_type>)
5410 __glibcxx_requires_sorted_set_pred(__first1, __last1, __first2, __comp);
5411 __glibcxx_requires_sorted_set_pred(__first2, __last2, __first1, __comp);
5413 return _GLIBCXX_STD_A::__set_symmetric_difference(__first1, __last1,
5414 __first2, __last2, __result,
5415 __gnu_cxx::__ops::__iter_comp_iter(__comp));
5418 template<
typename _ForwardIterator,
typename _Compare>
5419 _GLIBCXX14_CONSTEXPR
5421 __min_element(_ForwardIterator __first, _ForwardIterator __last,
5424 if (__first == __last)
5426 _ForwardIterator __result = __first;
5427 while (++__first != __last)
5428 if (__comp(__first, __result))
5440 template<
typename _ForwardIterator>
5441 _GLIBCXX14_CONSTEXPR
5443 inline min_element(_ForwardIterator __first, _ForwardIterator __last)
5446 __glibcxx_function_requires(_ForwardIteratorConcept<_ForwardIterator>)
5447 __glibcxx_function_requires(_LessThanComparableConcept<
5448 typename iterator_traits<_ForwardIterator>::value_type>)
5449 __glibcxx_requires_valid_range(__first, __last);
5451 return _GLIBCXX_STD_A::__min_element(__first, __last,
5452 __gnu_cxx::__ops::__iter_less_iter());
5464 template<
typename _ForwardIterator,
typename _Compare>
5465 _GLIBCXX14_CONSTEXPR
5466 inline _ForwardIterator
5467 min_element(_ForwardIterator __first, _ForwardIterator __last,
5471 __glibcxx_function_requires(_ForwardIteratorConcept<_ForwardIterator>)
5472 __glibcxx_function_requires(_BinaryPredicateConcept<_Compare,
5473 typename iterator_traits<_ForwardIterator>::value_type,
5474 typename iterator_traits<_ForwardIterator>::value_type>)
5475 __glibcxx_requires_valid_range(__first, __last);
5477 return _GLIBCXX_STD_A::__min_element(__first, __last,
5478 __gnu_cxx::__ops::__iter_comp_iter(__comp));
5481 template<
typename _ForwardIterator,
typename _Compare>
5482 _GLIBCXX14_CONSTEXPR
5484 __max_element(_ForwardIterator __first, _ForwardIterator __last,
5487 if (__first == __last)
return __first;
5488 _ForwardIterator __result = __first;
5489 while (++__first != __last)
5490 if (__comp(__result, __first))
5502 template<
typename _ForwardIterator>
5503 _GLIBCXX14_CONSTEXPR
5504 inline _ForwardIterator
5505 max_element(_ForwardIterator __first, _ForwardIterator __last)
5508 __glibcxx_function_requires(_ForwardIteratorConcept<_ForwardIterator>)
5509 __glibcxx_function_requires(_LessThanComparableConcept<
5510 typename iterator_traits<_ForwardIterator>::value_type>)
5511 __glibcxx_requires_valid_range(__first, __last);
5513 return _GLIBCXX_STD_A::__max_element(__first, __last,
5514 __gnu_cxx::__ops::__iter_less_iter());
5526 template<
typename _ForwardIterator,
typename _Compare>
5527 _GLIBCXX14_CONSTEXPR
5528 inline _ForwardIterator
5529 max_element(_ForwardIterator __first, _ForwardIterator __last,
5533 __glibcxx_function_requires(_ForwardIteratorConcept<_ForwardIterator>)
5534 __glibcxx_function_requires(_BinaryPredicateConcept<_Compare,
5535 typename iterator_traits<_ForwardIterator>::value_type,
5536 typename iterator_traits<_ForwardIterator>::value_type>)
5537 __glibcxx_requires_valid_range(__first, __last);
5539 return _GLIBCXX_STD_A::__max_element(__first, __last,
5540 __gnu_cxx::__ops::__iter_comp_iter(__comp));
5543 _GLIBCXX_END_NAMESPACE_ALGO
void advance(_InputIterator &__i, _Distance __n)
A generalization of pointer arithmetic.
_BidirectionalIterator1 __rotate_adaptive(_BidirectionalIterator1 __first, _BidirectionalIterator1 __middle, _BidirectionalIterator1 __last, _Distance __len1, _Distance __len2, _BidirectionalIterator2 __buffer, _Distance __buffer_size)
This is a helper function for the merge routines.
void __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.
_InputIterator find_if_not(_InputIterator __first, _InputIterator __last, _Predicate __pred)
Find the first element in a sequence for which a predicate is false.
_ForwardIterator __rotate(_ForwardIterator __first, _ForwardIterator __middle, _ForwardIterator __last, forward_iterator_tag)
This is a helper function for the rotate algorithm.
iterator begin()
As per Table mumble.
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.
_ForwardIterator __partition(_ForwardIterator __first, _ForwardIterator __last, _Predicate __pred, forward_iterator_tag)
This is a helper function...
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.
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.
bool none_of(_InputIterator __first, _InputIterator __last, _Predicate __pred)
Checks that a predicate is false for all the elements of a sequence.
Marking output iterators.
_OutputIterator __unique_copy(_ForwardIterator __first, _ForwardIterator __last, _OutputIterator __result, _BinaryPredicate __binary_pred, forward_iterator_tag, output_iterator_tag)
void __reverse(_BidirectionalIterator __first, _BidirectionalIterator __last, bidirectional_iterator_tag)
void iter_swap(_ForwardIterator1 __a, _ForwardIterator2 __b)
Swaps the contents of two iterators.
iterator_traits< _InputIterator >::difference_type distance(_InputIterator __first, _InputIterator __last)
A generalization of pointer arithmetic.
_EuclideanRingElement __gcd(_EuclideanRingElement __m, _EuclideanRingElement __n)
void __unguarded_linear_insert(_RandomAccessIterator __last, _Compare __comp)
This is a helper function for the sort routine.
void __insertion_sort(_RandomAccessIterator __first, _RandomAccessIterator __last, _Compare __comp)
This is a helper function for the sort routine.
_RandomAccessIterator __unguarded_partition(_RandomAccessIterator __first, _RandomAccessIterator __last, _RandomAccessIterator __pivot, _Compare __comp)
This is a helper function...
_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(__...
_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.
_GLIBCXX14_CONSTEXPR const _Tp & min(const _Tp &, const _Tp &)
This does what you think it does.
_GLIBCXX14_CONSTEXPR const _Tp & max(const _Tp &, const _Tp &)
This does what you think it does.
_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.
void __unguarded_insertion_sort(_RandomAccessIterator __first, _RandomAccessIterator __last, _Compare __comp)
This is a helper function for the sort routine.
Bidirectional iterators support a superset of forward iterator operations.
Random-access iterators support a superset of bidirectional iterator operations.
constexpr int __lg(int __n)
This is a helper function for the sort routines and for random.tcc.
_GLIBCXX14_CONSTEXPR pair< const _Tp &, const _Tp & > minmax(const _Tp &, const _Tp &)
Determines min and max at once as an ordered pair.
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.
void __introsort_loop(_RandomAccessIterator __first, _RandomAccessIterator __last, _Size __depth_limit, _Compare __comp)
This is a helper function for the sort routine.
Uniform discrete distribution for random numbers.
_InputIterator find_if(_InputIterator __first, _InputIterator __last, _Predicate __pred)
Find the first element in a sequence for which a predicate is true.
void __inplace_stable_sort(_RandomAccessIterator __first, _RandomAccessIterator __last, _Compare __comp)
This is a helper function for the stable sorting routines.
_ForwardIterator rotate(_ForwardIterator __first, _ForwardIterator __middle, _ForwardIterator __last)
Rotate the elements of a sequence.
_ForwardIterator2 swap_ranges(_ForwardIterator1 __first1, _ForwardIterator1 __last1, _ForwardIterator2 __first2)
Swap the elements of two sequences.
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.
_GLIBCXX14_CONSTEXPR _ForwardIterator max_element(_ForwardIterator __first, _ForwardIterator __last, _Compare __comp)
Return the maximum element in a range using comparison functor.
size_type requested_size() const
Returns the size requested by the constructor; may be >size().
iterator_traits< _Iter >::iterator_category __iterator_category(const _Iter &)
_T2 second
first is a copy of the first object
void __heap_select(_RandomAccessIterator __first, _RandomAccessIterator __middle, _RandomAccessIterator __last, _Compare __comp)
This is a helper function for the sort routines.
size_type size() const
As per Table mumble.
_ForwardIterator is_sorted_until(_ForwardIterator __first, _ForwardIterator __last, _Compare __comp)
Determines the end of a sorted sequence using comparison functor.
_ForwardIterator __search_n_aux(_ForwardIterator __first, _ForwardIterator __last, _Integer __count, _UnaryPredicate __unary_pred, std::forward_iterator_tag)
Struct holding two objects of arbitrary type.
_RandomAccessIterator __unguarded_partition_pivot(_RandomAccessIterator __first, _RandomAccessIterator __last, _Compare __comp)
This is a helper function...
_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 __final_insertion_sort(_RandomAccessIterator __first, _RandomAccessIterator __last, _Compare __comp)
This is a helper function for the sort routine.
Forward iterators support a superset of input iterator operations.
_T1 first
second_type is the second bound type
_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...
_InputIterator __find_if_not(_InputIterator __first, _InputIterator __last, _Predicate __pred)
Provided for stable_partition to use.
_GLIBCXX14_CONSTEXPR _ForwardIterator min_element(_ForwardIterator __first, _ForwardIterator __last, _Compare __comp)
Return the minimum element in a range using comparison functor.
ISO C++ entities toplevel namespace is std.