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,
339 forward_iterator_tag, forward_iterator_tag,
340 _BinaryPredicate __comp)
342 if (__first2 == __last2)
345 _ForwardIterator1 __result = __last1;
348 _ForwardIterator1 __new_result
349 = std::__search(__first1, __last1, __first2, __last2, __comp);
350 if (__new_result == __last1)
354 __result = __new_result;
355 __first1 = __new_result;
362 template<
typename _BidirectionalIterator1,
typename _BidirectionalIterator2,
363 typename _BinaryPredicate>
364 _BidirectionalIterator1
365 __find_end(_BidirectionalIterator1 __first1,
366 _BidirectionalIterator1 __last1,
367 _BidirectionalIterator2 __first2,
368 _BidirectionalIterator2 __last2,
369 bidirectional_iterator_tag, bidirectional_iterator_tag,
370 _BinaryPredicate __comp)
373 __glibcxx_function_requires(_BidirectionalIteratorConcept<
374 _BidirectionalIterator1>)
375 __glibcxx_function_requires(_BidirectionalIteratorConcept<
376 _BidirectionalIterator2>)
378 typedef reverse_iterator<_BidirectionalIterator1> _RevIterator1;
379 typedef reverse_iterator<_BidirectionalIterator2> _RevIterator2;
381 _RevIterator1 __rlast1(__first1);
382 _RevIterator2 __rlast2(__first2);
383 _RevIterator1 __rresult = std::__search(_RevIterator1(__last1), __rlast1,
384 _RevIterator2(__last2), __rlast2,
387 if (__rresult == __rlast1)
391 _BidirectionalIterator1 __result = __rresult.base();
423 template<
typename _ForwardIterator1,
typename _ForwardIterator2>
424 inline _ForwardIterator1
425 find_end(_ForwardIterator1 __first1, _ForwardIterator1 __last1,
426 _ForwardIterator2 __first2, _ForwardIterator2 __last2)
429 __glibcxx_function_requires(_ForwardIteratorConcept<_ForwardIterator1>)
430 __glibcxx_function_requires(_ForwardIteratorConcept<_ForwardIterator2>)
431 __glibcxx_function_requires(_EqualOpConcept<
432 typename iterator_traits<_ForwardIterator1>::value_type,
433 typename iterator_traits<_ForwardIterator2>::value_type>)
434 __glibcxx_requires_valid_range(__first1, __last1);
435 __glibcxx_requires_valid_range(__first2, __last2);
437 return std::__find_end(__first1, __last1, __first2, __last2,
440 __gnu_cxx::__ops::__iter_equal_to_iter());
471 template<
typename _ForwardIterator1,
typename _ForwardIterator2,
472 typename _BinaryPredicate>
473 inline _ForwardIterator1
474 find_end(_ForwardIterator1 __first1, _ForwardIterator1 __last1,
475 _ForwardIterator2 __first2, _ForwardIterator2 __last2,
476 _BinaryPredicate __comp)
479 __glibcxx_function_requires(_ForwardIteratorConcept<_ForwardIterator1>)
480 __glibcxx_function_requires(_ForwardIteratorConcept<_ForwardIterator2>)
481 __glibcxx_function_requires(_BinaryPredicateConcept<_BinaryPredicate,
482 typename iterator_traits<_ForwardIterator1>::value_type,
483 typename iterator_traits<_ForwardIterator2>::value_type>)
484 __glibcxx_requires_valid_range(__first1, __last1);
485 __glibcxx_requires_valid_range(__first2, __last2);
487 return std::__find_end(__first1, __last1, __first2, __last2,
490 __gnu_cxx::__ops::__iter_comp_iter(__comp));
493 #if __cplusplus >= 201103L
506 template<
typename _InputIterator,
typename _Predicate>
508 all_of(_InputIterator __first, _InputIterator __last, _Predicate __pred)
523 template<
typename _InputIterator,
typename _Predicate>
525 none_of(_InputIterator __first, _InputIterator __last, _Predicate __pred)
526 {
return __last == _GLIBCXX_STD_A::find_if(__first, __last, __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,
757 _OutputIterator __result, input_iterator_tag)
763 *__result = *__first;
774 template<
typename _RandomAccessIterator,
typename _Size,
775 typename _OutputIterator>
776 inline _OutputIterator
777 __copy_n(_RandomAccessIterator __first, _Size __n,
778 _OutputIterator __result, random_access_iterator_tag)
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>
824 pair<_OutputIterator1, _OutputIterator2>
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;
1241 template<
typename _ForwardIterator>
1244 _ForwardIterator __middle,
1245 _ForwardIterator __last,
1248 if (__first == __middle || __last == __middle)
1251 _ForwardIterator __first2 = __middle;
1257 if (__first == __middle)
1258 __middle = __first2;
1260 while (__first2 != __last);
1262 __first2 = __middle;
1264 while (__first2 != __last)
1269 if (__first == __middle)
1270 __middle = __first2;
1271 else if (__first2 == __last)
1272 __first2 = __middle;
1277 template<
typename _B
idirectionalIterator>
1280 _BidirectionalIterator __middle,
1281 _BidirectionalIterator __last,
1285 __glibcxx_function_requires(_Mutable_BidirectionalIteratorConcept<
1286 _BidirectionalIterator>)
1288 if (__first == __middle || __last == __middle)
1294 while (__first != __middle && __middle != __last)
1300 if (__first == __middle)
1307 template<
typename _RandomAccessIterator>
1310 _RandomAccessIterator __middle,
1311 _RandomAccessIterator __last,
1315 __glibcxx_function_requires(_Mutable_RandomAccessIteratorConcept<
1316 _RandomAccessIterator>)
1318 if (__first == __middle || __last == __middle)
1321 typedef typename iterator_traits<_RandomAccessIterator>::difference_type
1323 typedef typename iterator_traits<_RandomAccessIterator>::value_type
1326 _Distance __n = __last - __first;
1327 _Distance __k = __middle - __first;
1329 if (__k == __n - __k)
1335 _RandomAccessIterator __p = __first;
1339 if (__k < __n - __k)
1341 if (__is_pod(_ValueType) && __k == 1)
1343 _ValueType __t = _GLIBCXX_MOVE(*__p);
1344 _GLIBCXX_MOVE3(__p + 1, __p + __n, __p);
1345 *(__p + __n - 1) = _GLIBCXX_MOVE(__t);
1348 _RandomAccessIterator __q = __p + __k;
1349 for (_Distance __i = 0; __i < __n - __k; ++ __i)
1364 if (__is_pod(_ValueType) && __k == 1)
1366 _ValueType __t = _GLIBCXX_MOVE(*(__p + __n - 1));
1367 _GLIBCXX_MOVE_BACKWARD3(__p, __p + __n - 1, __p + __n);
1368 *__p = _GLIBCXX_MOVE(__t);
1371 _RandomAccessIterator __q = __p + __n;
1373 for (_Distance __i = 0; __i < __n - __k; ++ __i)
1408 template<
typename _ForwardIterator>
1410 rotate(_ForwardIterator __first, _ForwardIterator __middle,
1411 _ForwardIterator __last)
1414 __glibcxx_function_requires(_Mutable_ForwardIteratorConcept<
1416 __glibcxx_requires_valid_range(__first, __middle);
1417 __glibcxx_requires_valid_range(__middle, __last);
1443 template<
typename _ForwardIterator,
typename _OutputIterator>
1444 inline _OutputIterator
1445 rotate_copy(_ForwardIterator __first, _ForwardIterator __middle,
1446 _ForwardIterator __last, _OutputIterator __result)
1449 __glibcxx_function_requires(_ForwardIteratorConcept<_ForwardIterator>)
1450 __glibcxx_function_requires(_OutputIteratorConcept<_OutputIterator,
1451 typename iterator_traits<_ForwardIterator>::value_type>)
1452 __glibcxx_requires_valid_range(__first, __middle);
1453 __glibcxx_requires_valid_range(__middle, __last);
1455 return std::copy(__first, __middle,
1456 std::copy(__middle, __last, __result));
1460 template<
typename _ForwardIterator,
typename _Predicate>
1465 if (__first == __last)
1468 while (__pred(*__first))
1469 if (++__first == __last)
1472 _ForwardIterator __next = __first;
1474 while (++__next != __last)
1475 if (__pred(*__next))
1485 template<
typename _B
idirectionalIterator,
typename _Predicate>
1486 _BidirectionalIterator
1487 __partition(_BidirectionalIterator __first, _BidirectionalIterator __last,
1493 if (__first == __last)
1495 else if (__pred(*__first))
1501 if (__first == __last)
1503 else if (!
bool(__pred(*__last)))
1517 template<
typename _ForwardIterator,
typename _Predicate,
typename _Distance>
1520 _Predicate __pred, _Distance __len)
1524 _ForwardIterator __middle = __first;
1526 _ForwardIterator __left_split =
1530 _Distance __right_len = __len - __len / 2;
1531 _ForwardIterator __right_split =
1537 std::rotate(__left_split, __middle, __right_split);
1539 return __left_split;
1548 template<
typename _ForwardIterator,
typename _Pointer,
typename _Predicate,
1552 _ForwardIterator __last,
1553 _Predicate __pred, _Distance __len,
1555 _Distance __buffer_size)
1557 if (__len <= __buffer_size)
1559 _ForwardIterator __result1 = __first;
1560 _Pointer __result2 = __buffer;
1564 *__result2 = _GLIBCXX_MOVE(*__first);
1567 for (; __first != __last; ++__first)
1568 if (__pred(__first))
1570 *__result1 = _GLIBCXX_MOVE(*__first);
1575 *__result2 = _GLIBCXX_MOVE(*__first);
1578 _GLIBCXX_MOVE3(__buffer, __result2, __result1);
1583 _ForwardIterator __middle = __first;
1585 _ForwardIterator __left_split =
1587 __len / 2, __buffer,
1591 _Distance __right_len = __len - __len / 2;
1592 _ForwardIterator __right_split =
1598 __buffer, __buffer_size);
1599 std::rotate(__left_split, __middle, __right_split);
1601 return __left_split;
1605 template<
typename _ForwardIterator,
typename _Predicate>
1607 __stable_partition(_ForwardIterator __first, _ForwardIterator __last,
1612 if (__first == __last)
1615 typedef typename iterator_traits<_ForwardIterator>::value_type
1617 typedef typename iterator_traits<_ForwardIterator>::difference_type
1620 _Temporary_buffer<_ForwardIterator, _ValueType> __buf(__first, __last);
1621 if (__buf.size() > 0)
1624 _DistanceType(__buf.requested_size()),
1626 _DistanceType(__buf.size()));
1630 _DistanceType(__buf.requested_size()));
1650 template<
typename _ForwardIterator,
typename _Predicate>
1651 inline _ForwardIterator
1652 stable_partition(_ForwardIterator __first, _ForwardIterator __last,
1656 __glibcxx_function_requires(_Mutable_ForwardIteratorConcept<
1658 __glibcxx_function_requires(_UnaryPredicateConcept<_Predicate,
1659 typename iterator_traits<_ForwardIterator>::value_type>)
1660 __glibcxx_requires_valid_range(__first, __last);
1662 return std::__stable_partition(__first, __last,
1663 __gnu_cxx::__ops::__pred_iter(__pred));
1667 template<
typename _RandomAccessIterator,
typename _Compare>
1670 _RandomAccessIterator __middle,
1671 _RandomAccessIterator __last, _Compare __comp)
1673 std::__make_heap(__first, __middle, __comp);
1674 for (_RandomAccessIterator __i = __middle; __i < __last; ++__i)
1675 if (__comp(__i, __first))
1676 std::__pop_heap(__first, __middle, __i, __comp);
1681 template<
typename _InputIterator,
typename _RandomAccessIterator,
1683 _RandomAccessIterator
1684 __partial_sort_copy(_InputIterator __first, _InputIterator __last,
1685 _RandomAccessIterator __result_first,
1686 _RandomAccessIterator __result_last,
1689 typedef typename iterator_traits<_InputIterator>::value_type
1691 typedef iterator_traits<_RandomAccessIterator> _RItTraits;
1692 typedef typename _RItTraits::difference_type _DistanceType;
1694 if (__result_first == __result_last)
1695 return __result_last;
1696 _RandomAccessIterator __result_real_last = __result_first;
1697 while (__first != __last && __result_real_last != __result_last)
1699 *__result_real_last = *__first;
1700 ++__result_real_last;
1704 std::__make_heap(__result_first, __result_real_last, __comp);
1705 while (__first != __last)
1707 if (__comp(__first, __result_first))
1708 std::__adjust_heap(__result_first, _DistanceType(0),
1709 _DistanceType(__result_real_last
1711 _InputValueType(*__first), __comp);
1714 std::__sort_heap(__result_first, __result_real_last, __comp);
1715 return __result_real_last;
1736 template<
typename _InputIterator,
typename _RandomAccessIterator>
1737 inline _RandomAccessIterator
1738 partial_sort_copy(_InputIterator __first, _InputIterator __last,
1739 _RandomAccessIterator __result_first,
1740 _RandomAccessIterator __result_last)
1742 typedef typename iterator_traits<_InputIterator>::value_type
1744 typedef typename iterator_traits<_RandomAccessIterator>::value_type
1746 typedef typename iterator_traits<_RandomAccessIterator>::difference_type
1750 __glibcxx_function_requires(_InputIteratorConcept<_InputIterator>)
1751 __glibcxx_function_requires(_ConvertibleConcept<_InputValueType,
1753 __glibcxx_function_requires(_LessThanOpConcept<_InputValueType,
1755 __glibcxx_function_requires(_LessThanComparableConcept<_OutputValueType>)
1756 __glibcxx_requires_valid_range(__first, __last);
1757 __glibcxx_requires_valid_range(__result_first, __result_last);
1759 return std::__partial_sort_copy(__first, __last,
1760 __result_first, __result_last,
1761 __gnu_cxx::__ops::__iter_less_iter());
1784 template<
typename _InputIterator,
typename _RandomAccessIterator,
1786 inline _RandomAccessIterator
1787 partial_sort_copy(_InputIterator __first, _InputIterator __last,
1788 _RandomAccessIterator __result_first,
1789 _RandomAccessIterator __result_last,
1792 typedef typename iterator_traits<_InputIterator>::value_type
1794 typedef typename iterator_traits<_RandomAccessIterator>::value_type
1796 typedef typename iterator_traits<_RandomAccessIterator>::difference_type
1800 __glibcxx_function_requires(_InputIteratorConcept<_InputIterator>)
1801 __glibcxx_function_requires(_Mutable_RandomAccessIteratorConcept<
1802 _RandomAccessIterator>)
1803 __glibcxx_function_requires(_ConvertibleConcept<_InputValueType,
1805 __glibcxx_function_requires(_BinaryPredicateConcept<_Compare,
1806 _InputValueType, _OutputValueType>)
1807 __glibcxx_function_requires(_BinaryPredicateConcept<_Compare,
1808 _OutputValueType, _OutputValueType>)
1809 __glibcxx_requires_valid_range(__first, __last);
1810 __glibcxx_requires_valid_range(__result_first, __result_last);
1812 return std::__partial_sort_copy(__first, __last,
1813 __result_first, __result_last,
1814 __gnu_cxx::__ops::__iter_comp_iter(__comp));
1818 template<
typename _RandomAccessIterator,
typename _Compare>
1823 typename iterator_traits<_RandomAccessIterator>::value_type
1824 __val = _GLIBCXX_MOVE(*__last);
1825 _RandomAccessIterator __next = __last;
1827 while (__comp(__val, __next))
1829 *__last = _GLIBCXX_MOVE(*__next);
1833 *__last = _GLIBCXX_MOVE(__val);
1837 template<
typename _RandomAccessIterator,
typename _Compare>
1840 _RandomAccessIterator __last, _Compare __comp)
1842 if (__first == __last)
return;
1844 for (_RandomAccessIterator __i = __first + 1; __i != __last; ++__i)
1846 if (__comp(__i, __first))
1848 typename iterator_traits<_RandomAccessIterator>::value_type
1849 __val = _GLIBCXX_MOVE(*__i);
1850 _GLIBCXX_MOVE_BACKWARD3(__first, __i, __i + 1);
1851 *__first = _GLIBCXX_MOVE(__val);
1855 __gnu_cxx::__ops::__val_comp_iter(__comp));
1860 template<
typename _RandomAccessIterator,
typename _Compare>
1863 _RandomAccessIterator __last, _Compare __comp)
1865 for (_RandomAccessIterator __i = __first; __i != __last; ++__i)
1867 __gnu_cxx::__ops::__val_comp_iter(__comp));
1874 enum { _S_threshold = 16 };
1877 template<
typename _RandomAccessIterator,
typename _Compare>
1880 _RandomAccessIterator __last, _Compare __comp)
1882 if (__last - __first >
int(_S_threshold))
1893 template<
typename _RandomAccessIterator,
typename _Compare>
1894 _RandomAccessIterator
1896 _RandomAccessIterator __last,
1897 _RandomAccessIterator __pivot, _Compare __comp)
1901 while (__comp(__first, __pivot))
1904 while (__comp(__pivot, __last))
1906 if (!(__first < __last))
1914 template<
typename _RandomAccessIterator,
typename _Compare>
1915 inline _RandomAccessIterator
1917 _RandomAccessIterator __last, _Compare __comp)
1919 _RandomAccessIterator __mid = __first + (__last - __first) / 2;
1925 template<
typename _RandomAccessIterator,
typename _Compare>
1927 __partial_sort(_RandomAccessIterator __first,
1928 _RandomAccessIterator __middle,
1929 _RandomAccessIterator __last,
1933 std::__sort_heap(__first, __middle, __comp);
1937 template<
typename _RandomAccessIterator,
typename _Size,
typename _Compare>
1940 _RandomAccessIterator __last,
1941 _Size __depth_limit, _Compare __comp)
1943 while (__last - __first >
int(_S_threshold))
1945 if (__depth_limit == 0)
1947 std::__partial_sort(__first, __last, __last, __comp);
1951 _RandomAccessIterator __cut =
1960 template<
typename _RandomAccessIterator,
typename _Compare>
1962 __sort(_RandomAccessIterator __first, _RandomAccessIterator __last,
1965 if (__first != __last)
1974 template<
typename _RandomAccessIterator,
typename _Size,
typename _Compare>
1976 __introselect(_RandomAccessIterator __first, _RandomAccessIterator __nth,
1977 _RandomAccessIterator __last, _Size __depth_limit,
1980 while (__last - __first > 3)
1982 if (__depth_limit == 0)
1990 _RandomAccessIterator __cut =
2020 template<
typename _ForwardIterator,
typename _Tp,
typename _Compare>
2021 inline _ForwardIterator
2022 lower_bound(_ForwardIterator __first, _ForwardIterator __last,
2023 const _Tp& __val, _Compare __comp)
2025 typedef typename iterator_traits<_ForwardIterator>::value_type
2029 __glibcxx_function_requires(_ForwardIteratorConcept<_ForwardIterator>)
2030 __glibcxx_function_requires(_BinaryPredicateConcept<_Compare,
2032 __glibcxx_requires_partitioned_lower_pred(__first, __last,
2035 return std::__lower_bound(__first, __last, __val,
2036 __gnu_cxx::__ops::__iter_comp_val(__comp));
2039 template<
typename _ForwardIterator,
typename _Tp,
typename _Compare>
2041 __upper_bound(_ForwardIterator __first, _ForwardIterator __last,
2042 const _Tp& __val, _Compare __comp)
2044 typedef typename iterator_traits<_ForwardIterator>::difference_type
2051 _DistanceType __half = __len >> 1;
2052 _ForwardIterator __middle = __first;
2054 if (__comp(__val, __middle))
2060 __len = __len - __half - 1;
2077 template<
typename _ForwardIterator,
typename _Tp>
2078 inline _ForwardIterator
2079 upper_bound(_ForwardIterator __first, _ForwardIterator __last,
2082 typedef typename iterator_traits<_ForwardIterator>::value_type
2086 __glibcxx_function_requires(_ForwardIteratorConcept<_ForwardIterator>)
2087 __glibcxx_function_requires(_LessThanOpConcept<_Tp, _ValueType>)
2088 __glibcxx_requires_partitioned_upper(__first, __last, __val);
2090 return std::__upper_bound(__first, __last, __val,
2091 __gnu_cxx::__ops::__val_less_iter());
2109 template<
typename _ForwardIterator,
typename _Tp,
typename _Compare>
2110 inline _ForwardIterator
2111 upper_bound(_ForwardIterator __first, _ForwardIterator __last,
2112 const _Tp& __val, _Compare __comp)
2114 typedef typename iterator_traits<_ForwardIterator>::value_type
2118 __glibcxx_function_requires(_ForwardIteratorConcept<_ForwardIterator>)
2119 __glibcxx_function_requires(_BinaryPredicateConcept<_Compare,
2121 __glibcxx_requires_partitioned_upper_pred(__first, __last,
2124 return std::__upper_bound(__first, __last, __val,
2125 __gnu_cxx::__ops::__val_comp_iter(__comp));
2128 template<
typename _ForwardIterator,
typename _Tp,
2129 typename _CompareItTp,
typename _CompareTpIt>
2130 pair<_ForwardIterator, _ForwardIterator>
2131 __equal_range(_ForwardIterator __first, _ForwardIterator __last,
2133 _CompareItTp __comp_it_val, _CompareTpIt __comp_val_it)
2135 typedef typename iterator_traits<_ForwardIterator>::difference_type
2142 _DistanceType __half = __len >> 1;
2143 _ForwardIterator __middle = __first;
2145 if (__comp_it_val(__middle, __val))
2149 __len = __len - __half - 1;
2151 else if (__comp_val_it(__val, __middle))
2155 _ForwardIterator __left
2156 = std::__lower_bound(__first, __middle, __val, __comp_it_val);
2158 _ForwardIterator __right
2159 = std::__upper_bound(++__middle, __first, __val, __comp_val_it);
2160 return pair<_ForwardIterator, _ForwardIterator>(__left, __right);
2163 return pair<_ForwardIterator, _ForwardIterator>(__first, __first);
2183 template<
typename _ForwardIterator,
typename _Tp>
2184 inline pair<_ForwardIterator, _ForwardIterator>
2185 equal_range(_ForwardIterator __first, _ForwardIterator __last,
2188 typedef typename iterator_traits<_ForwardIterator>::value_type
2192 __glibcxx_function_requires(_ForwardIteratorConcept<_ForwardIterator>)
2193 __glibcxx_function_requires(_LessThanOpConcept<_ValueType, _Tp>)
2194 __glibcxx_function_requires(_LessThanOpConcept<_Tp, _ValueType>)
2195 __glibcxx_requires_partitioned_lower(__first, __last, __val);
2196 __glibcxx_requires_partitioned_upper(__first, __last, __val);
2198 return std::__equal_range(__first, __last, __val,
2199 __gnu_cxx::__ops::__iter_less_val(),
2200 __gnu_cxx::__ops::__val_less_iter());
2220 template<
typename _ForwardIterator,
typename _Tp,
typename _Compare>
2221 inline pair<_ForwardIterator, _ForwardIterator>
2222 equal_range(_ForwardIterator __first, _ForwardIterator __last,
2223 const _Tp& __val, _Compare __comp)
2225 typedef typename iterator_traits<_ForwardIterator>::value_type
2229 __glibcxx_function_requires(_ForwardIteratorConcept<_ForwardIterator>)
2230 __glibcxx_function_requires(_BinaryPredicateConcept<_Compare,
2232 __glibcxx_function_requires(_BinaryPredicateConcept<_Compare,
2234 __glibcxx_requires_partitioned_lower_pred(__first, __last,
2236 __glibcxx_requires_partitioned_upper_pred(__first, __last,
2239 return std::__equal_range(__first, __last, __val,
2240 __gnu_cxx::__ops::__iter_comp_val(__comp),
2241 __gnu_cxx::__ops::__val_comp_iter(__comp));
2256 template<
typename _ForwardIterator,
typename _Tp>
2258 binary_search(_ForwardIterator __first, _ForwardIterator __last,
2261 typedef typename iterator_traits<_ForwardIterator>::value_type
2265 __glibcxx_function_requires(_ForwardIteratorConcept<_ForwardIterator>)
2266 __glibcxx_function_requires(_LessThanOpConcept<_Tp, _ValueType>)
2267 __glibcxx_requires_partitioned_lower(__first, __last, __val);
2268 __glibcxx_requires_partitioned_upper(__first, __last, __val);
2270 _ForwardIterator __i
2271 = std::__lower_bound(__first, __last, __val,
2272 __gnu_cxx::__ops::__iter_less_val());
2273 return __i != __last && !(__val < *__i);
2291 template<
typename _ForwardIterator,
typename _Tp,
typename _Compare>
2293 binary_search(_ForwardIterator __first, _ForwardIterator __last,
2294 const _Tp& __val, _Compare __comp)
2296 typedef typename iterator_traits<_ForwardIterator>::value_type
2300 __glibcxx_function_requires(_ForwardIteratorConcept<_ForwardIterator>)
2301 __glibcxx_function_requires(_BinaryPredicateConcept<_Compare,
2303 __glibcxx_requires_partitioned_lower_pred(__first, __last,
2305 __glibcxx_requires_partitioned_upper_pred(__first, __last,
2308 _ForwardIterator __i
2309 = std::__lower_bound(__first, __last, __val,
2310 __gnu_cxx::__ops::__iter_comp_val(__comp));
2311 return __i != __last && !bool(__comp(__val, *__i));
2317 template<
typename _InputIterator1,
typename _InputIterator2,
2318 typename _OutputIterator,
typename _Compare>
2321 _InputIterator2 __first2, _InputIterator2 __last2,
2322 _OutputIterator __result, _Compare __comp)
2324 while (__first1 != __last1 && __first2 != __last2)
2326 if (__comp(__first2, __first1))
2328 *__result = _GLIBCXX_MOVE(*__first2);
2333 *__result = _GLIBCXX_MOVE(*__first1);
2338 if (__first1 != __last1)
2339 _GLIBCXX_MOVE3(__first1, __last1, __result);
2343 template<
typename _BidirectionalIterator1,
typename _BidirectionalIterator2,
2344 typename _BidirectionalIterator3,
typename _Compare>
2347 _BidirectionalIterator1 __last1,
2348 _BidirectionalIterator2 __first2,
2349 _BidirectionalIterator2 __last2,
2350 _BidirectionalIterator3 __result,
2353 if (__first1 == __last1)
2355 _GLIBCXX_MOVE_BACKWARD3(__first2, __last2, __result);
2358 else if (__first2 == __last2)
2365 if (__comp(__last2, __last1))
2367 *--__result = _GLIBCXX_MOVE(*__last1);
2368 if (__first1 == __last1)
2370 _GLIBCXX_MOVE_BACKWARD3(__first2, ++__last2, __result);
2377 *--__result = _GLIBCXX_MOVE(*__last2);
2378 if (__first2 == __last2)
2386 template<
typename _BidirectionalIterator1,
typename _BidirectionalIterator2,
2388 _BidirectionalIterator1
2390 _BidirectionalIterator1 __middle,
2391 _BidirectionalIterator1 __last,
2392 _Distance __len1, _Distance __len2,
2393 _BidirectionalIterator2 __buffer,
2394 _Distance __buffer_size)
2396 _BidirectionalIterator2 __buffer_end;
2397 if (__len1 > __len2 && __len2 <= __buffer_size)
2401 __buffer_end = _GLIBCXX_MOVE3(__middle, __last, __buffer);
2402 _GLIBCXX_MOVE_BACKWARD3(__first, __middle, __last);
2403 return _GLIBCXX_MOVE3(__buffer, __buffer_end, __first);
2408 else if (__len1 <= __buffer_size)
2412 __buffer_end = _GLIBCXX_MOVE3(__first, __middle, __buffer);
2413 _GLIBCXX_MOVE3(__middle, __last, __first);
2414 return _GLIBCXX_MOVE_BACKWARD3(__buffer, __buffer_end, __last);
2428 template<
typename _BidirectionalIterator,
typename _Distance,
2429 typename _Pointer,
typename _Compare>
2432 _BidirectionalIterator __middle,
2433 _BidirectionalIterator __last,
2434 _Distance __len1, _Distance __len2,
2435 _Pointer __buffer, _Distance __buffer_size,
2438 if (__len1 <= __len2 && __len1 <= __buffer_size)
2440 _Pointer __buffer_end = _GLIBCXX_MOVE3(__first, __middle, __buffer);
2444 else if (__len2 <= __buffer_size)
2446 _Pointer __buffer_end = _GLIBCXX_MOVE3(__middle, __last, __buffer);
2448 __buffer_end, __last, __comp);
2452 _BidirectionalIterator __first_cut = __first;
2453 _BidirectionalIterator __second_cut = __middle;
2454 _Distance __len11 = 0;
2455 _Distance __len22 = 0;
2456 if (__len1 > __len2)
2458 __len11 = __len1 / 2;
2461 = std::__lower_bound(__middle, __last, *__first_cut,
2462 __gnu_cxx::__ops::__iter_comp_val(__comp));
2467 __len22 = __len2 / 2;
2470 = std::__upper_bound(__first, __middle, *__second_cut,
2471 __gnu_cxx::__ops::__val_comp_iter(__comp));
2474 _BidirectionalIterator __new_middle
2476 __len1 - __len11, __len22, __buffer,
2479 __len22, __buffer, __buffer_size, __comp);
2482 __len2 - __len22, __buffer,
2483 __buffer_size, __comp);
2488 template<
typename _BidirectionalIterator,
typename _Distance,
2492 _BidirectionalIterator __middle,
2493 _BidirectionalIterator __last,
2494 _Distance __len1, _Distance __len2,
2497 if (__len1 == 0 || __len2 == 0)
2499 if (__len1 + __len2 == 2)
2501 if (__comp(__middle, __first))
2505 _BidirectionalIterator __first_cut = __first;
2506 _BidirectionalIterator __second_cut = __middle;
2507 _Distance __len11 = 0;
2508 _Distance __len22 = 0;
2509 if (__len1 > __len2)
2511 __len11 = __len1 / 2;
2514 = std::__lower_bound(__middle, __last, *__first_cut,
2515 __gnu_cxx::__ops::__iter_comp_val(__comp));
2520 __len22 = __len2 / 2;
2523 = std::__upper_bound(__first, __middle, *__second_cut,
2524 __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);
2554 typedef _Temporary_buffer<_BidirectionalIterator, _ValueType> _TmpBuf;
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 inline pair<const _Tp&, const _Tp&>
3301 __glibcxx_function_requires(_LessThanComparableConcept<_Tp>)
3303 return __b < __a ? pair<const _Tp&, const _Tp&>(__b, __a)
3316 template<
typename _Tp,
typename _Compare>
3317 inline pair<const _Tp&, const _Tp&>
3318 minmax(
const _Tp& __a,
const _Tp& __b, _Compare __comp)
3324 template<
typename _ForwardIterator,
typename _Compare>
3325 pair<_ForwardIterator, _ForwardIterator>
3326 __minmax_element(_ForwardIterator __first, _ForwardIterator __last,
3329 _ForwardIterator __next = __first;
3330 if (__first == __last
3331 || ++__next == __last)
3334 _ForwardIterator __min, __max;
3335 if (__comp(__next, __first))
3349 while (__first != __last)
3352 if (++__next == __last)
3354 if (__comp(__first, __min))
3356 else if (!__comp(__first, __max))
3361 if (__comp(__next, __first))
3363 if (__comp(__next, __min))
3365 if (!__comp(__first, __max))
3370 if (__comp(__first, __min))
3372 if (!__comp(__next, __max))
3394 template<
typename _ForwardIterator>
3395 inline pair<_ForwardIterator, _ForwardIterator>
3396 minmax_element(_ForwardIterator __first, _ForwardIterator __last)
3399 __glibcxx_function_requires(_ForwardIteratorConcept<_ForwardIterator>)
3400 __glibcxx_function_requires(_LessThanComparableConcept<
3401 typename iterator_traits<_ForwardIterator>::value_type>)
3402 __glibcxx_requires_valid_range(__first, __last);
3404 return std::__minmax_element(__first, __last,
3405 __gnu_cxx::__ops::__iter_less_iter());
3420 template<
typename _ForwardIterator,
typename _Compare>
3421 inline pair<_ForwardIterator, _ForwardIterator>
3422 minmax_element(_ForwardIterator __first, _ForwardIterator __last,
3426 __glibcxx_function_requires(_ForwardIteratorConcept<_ForwardIterator>)
3427 __glibcxx_function_requires(_BinaryPredicateConcept<_Compare,
3428 typename iterator_traits<_ForwardIterator>::value_type,
3429 typename iterator_traits<_ForwardIterator>::value_type>)
3430 __glibcxx_requires_valid_range(__first, __last);
3432 return std::__minmax_element(__first, __last,
3433 __gnu_cxx::__ops::__iter_comp_iter(__comp));
3437 template<
typename _Tp>
3439 min(initializer_list<_Tp> __l)
3440 {
return *std::min_element(__l.begin(), __l.end()); }
3442 template<
typename _Tp,
typename _Compare>
3444 min(initializer_list<_Tp> __l, _Compare __comp)
3447 template<
typename _Tp>
3449 max(initializer_list<_Tp> __l)
3452 template<
typename _Tp,
typename _Compare>
3454 max(initializer_list<_Tp> __l, _Compare __comp)
3457 template<
typename _Tp>
3458 inline pair<_Tp, _Tp>
3459 minmax(initializer_list<_Tp> __l)
3461 pair<const _Tp*, const _Tp*> __p =
3466 template<
typename _Tp,
typename _Compare>
3467 inline pair<_Tp, _Tp>
3468 minmax(initializer_list<_Tp> __l, _Compare __comp)
3470 pair<const _Tp*, const _Tp*> __p =
3475 template<
typename _ForwardIterator1,
typename _ForwardIterator2,
3476 typename _BinaryPredicate>
3478 __is_permutation(_ForwardIterator1 __first1, _ForwardIterator1 __last1,
3479 _ForwardIterator2 __first2, _BinaryPredicate __pred)
3483 for (; __first1 != __last1; ++__first1, ++__first2)
3484 if (!__pred(__first1, __first2))
3487 if (__first1 == __last1)
3492 _ForwardIterator2 __last2 = __first2;
3494 for (_ForwardIterator1 __scan = __first1; __scan != __last1; ++__scan)
3497 __gnu_cxx::__ops::__iter_comp_iter(__pred, __scan)))
3501 = std::__count_if(__first2, __last2,
3502 __gnu_cxx::__ops::__iter_comp_iter(__pred, __scan));
3503 if (0 == __matches ||
3504 std::__count_if(__scan, __last1,
3505 __gnu_cxx::__ops::__iter_comp_iter(__pred, __scan))
3524 template<
typename _ForwardIterator1,
typename _ForwardIterator2>
3526 is_permutation(_ForwardIterator1 __first1, _ForwardIterator1 __last1,
3527 _ForwardIterator2 __first2)
3530 __glibcxx_function_requires(_ForwardIteratorConcept<_ForwardIterator1>)
3531 __glibcxx_function_requires(_ForwardIteratorConcept<_ForwardIterator2>)
3532 __glibcxx_function_requires(_EqualOpConcept<
3533 typename iterator_traits<_ForwardIterator1>::value_type,
3534 typename iterator_traits<_ForwardIterator2>::value_type>)
3535 __glibcxx_requires_valid_range(__first1, __last1);
3537 return std::__is_permutation(__first1, __last1, __first2,
3538 __gnu_cxx::__ops::__iter_equal_to_iter());
3555 template<
typename _ForwardIterator1,
typename _ForwardIterator2,
3556 typename _BinaryPredicate>
3558 is_permutation(_ForwardIterator1 __first1, _ForwardIterator1 __last1,
3559 _ForwardIterator2 __first2, _BinaryPredicate __pred)
3562 __glibcxx_function_requires(_ForwardIteratorConcept<_ForwardIterator1>)
3563 __glibcxx_function_requires(_ForwardIteratorConcept<_ForwardIterator2>)
3564 __glibcxx_function_requires(_BinaryPredicateConcept<_BinaryPredicate,
3565 typename iterator_traits<_ForwardIterator1>::value_type,
3566 typename iterator_traits<_ForwardIterator2>::value_type>)
3567 __glibcxx_requires_valid_range(__first1, __last1);
3569 return std::__is_permutation(__first1, __last1, __first2,
3570 __gnu_cxx::__ops::__iter_comp_iter(__pred));
3573 #if __cplusplus > 201103L
3574 template<
typename _ForwardIterator1,
typename _ForwardIterator2,
3575 typename _BinaryPredicate>
3577 __is_permutation(_ForwardIterator1 __first1, _ForwardIterator1 __last1,
3578 _ForwardIterator2 __first2, _ForwardIterator2 __last2,
3579 _BinaryPredicate __pred)
3582 =
typename iterator_traits<_ForwardIterator1>::iterator_category;
3584 =
typename iterator_traits<_ForwardIterator2>::iterator_category;
3585 using _It1_is_RA = is_same<_Cat1, random_access_iterator_tag>;
3586 using _It2_is_RA = is_same<_Cat2, random_access_iterator_tag>;
3587 constexpr
bool __ra_iters = _It1_is_RA() && _It2_is_RA();
3598 for (; __first1 != __last1; ++__first1, ++__first2)
3599 if (!__pred(__first1, __first2))
3604 if (__first1 == __last1)
3611 if (__d1 == 0 && __d2 == 0)
3617 for (_ForwardIterator1 __scan = __first1; __scan != __last1; ++__scan)
3620 __gnu_cxx::__ops::__iter_comp_iter(__pred, __scan)))
3623 auto __matches = std::__count_if(__first2, __last2,
3624 __gnu_cxx::__ops::__iter_comp_iter(__pred, __scan));
3626 || std::__count_if(__scan, __last1,
3627 __gnu_cxx::__ops::__iter_comp_iter(__pred, __scan))
3647 template<
typename _ForwardIterator1,
typename _ForwardIterator2>
3649 is_permutation(_ForwardIterator1 __first1, _ForwardIterator1 __last1,
3650 _ForwardIterator2 __first2, _ForwardIterator2 __last2)
3652 __glibcxx_requires_valid_range(__first1, __last1);
3653 __glibcxx_requires_valid_range(__first2, __last2);
3656 std::__is_permutation(__first1, __last1, __first2, __last2,
3657 __gnu_cxx::__ops::__iter_equal_to_iter());
3674 template<
typename _ForwardIterator1,
typename _ForwardIterator2,
3675 typename _BinaryPredicate>
3677 is_permutation(_ForwardIterator1 __first1, _ForwardIterator1 __last1,
3678 _ForwardIterator2 __first2, _ForwardIterator2 __last2,
3679 _BinaryPredicate __pred)
3681 __glibcxx_requires_valid_range(__first1, __last1);
3682 __glibcxx_requires_valid_range(__first2, __last2);
3684 return std::__is_permutation(__first1, __last1, __first2, __last2,
3685 __gnu_cxx::__ops::__iter_comp_iter(__pred));
3689 #ifdef _GLIBCXX_USE_C99_STDINT_TR1
3702 template<
typename _RandomAccessIterator,
3703 typename _UniformRandomNumberGenerator>
3705 shuffle(_RandomAccessIterator __first, _RandomAccessIterator __last,
3706 _UniformRandomNumberGenerator&& __g)
3709 __glibcxx_function_requires(_Mutable_RandomAccessIteratorConcept<
3710 _RandomAccessIterator>)
3711 __glibcxx_requires_valid_range(__first, __last);
3713 if (__first == __last)
3716 typedef typename iterator_traits<_RandomAccessIterator>::difference_type
3719 typedef typename std::make_unsigned<_DistanceType>::type __ud_type;
3721 typedef typename __distr_type::param_type __p_type;
3724 for (_RandomAccessIterator __i = __first + 1; __i != __last; ++__i)
3725 std::iter_swap(__i, __first + __d(__g, __p_type(0, __i - __first)));
3731 _GLIBCXX_END_NAMESPACE_VERSION
3733 _GLIBCXX_BEGIN_NAMESPACE_ALGO
3747 template<
typename _InputIterator,
typename _Function>
3749 for_each(_InputIterator __first, _InputIterator __last, _Function __f)
3752 __glibcxx_function_requires(_InputIteratorConcept<_InputIterator>)
3753 __glibcxx_requires_valid_range(__first, __last);
3754 for (; __first != __last; ++__first)
3756 return _GLIBCXX_MOVE(__f);
3768 template<
typename _InputIterator,
typename _Tp>
3769 inline _InputIterator
3770 find(_InputIterator __first, _InputIterator __last,
3774 __glibcxx_function_requires(_InputIteratorConcept<_InputIterator>)
3775 __glibcxx_function_requires(_EqualOpConcept<
3776 typename iterator_traits<_InputIterator>::value_type, _Tp>)
3777 __glibcxx_requires_valid_range(__first, __last);
3779 __gnu_cxx::__ops::__iter_equals_val(__val));
3792 template<
typename _InputIterator,
typename _Predicate>
3793 inline _InputIterator
3794 find_if(_InputIterator __first, _InputIterator __last,
3798 __glibcxx_function_requires(_InputIteratorConcept<_InputIterator>)
3799 __glibcxx_function_requires(_UnaryPredicateConcept<_Predicate,
3800 typename iterator_traits<_InputIterator>::value_type>)
3801 __glibcxx_requires_valid_range(__first, __last);
3804 __gnu_cxx::__ops::__pred_iter(__pred));
3823 template<
typename _InputIterator,
typename _ForwardIterator>
3825 find_first_of(_InputIterator __first1, _InputIterator __last1,
3826 _ForwardIterator __first2, _ForwardIterator __last2)
3829 __glibcxx_function_requires(_InputIteratorConcept<_InputIterator>)
3830 __glibcxx_function_requires(_ForwardIteratorConcept<_ForwardIterator>)
3831 __glibcxx_function_requires(_EqualOpConcept<
3832 typename iterator_traits<_InputIterator>::value_type,
3833 typename iterator_traits<_ForwardIterator>::value_type>)
3834 __glibcxx_requires_valid_range(__first1, __last1);
3835 __glibcxx_requires_valid_range(__first2, __last2);
3837 for (; __first1 != __last1; ++__first1)
3838 for (_ForwardIterator __iter = __first2; __iter != __last2; ++__iter)
3839 if (*__first1 == *__iter)
3863 template<
typename _InputIterator,
typename _ForwardIterator,
3864 typename _BinaryPredicate>
3866 find_first_of(_InputIterator __first1, _InputIterator __last1,
3867 _ForwardIterator __first2, _ForwardIterator __last2,
3868 _BinaryPredicate __comp)
3871 __glibcxx_function_requires(_InputIteratorConcept<_InputIterator>)
3872 __glibcxx_function_requires(_ForwardIteratorConcept<_ForwardIterator>)
3873 __glibcxx_function_requires(_BinaryPredicateConcept<_BinaryPredicate,
3874 typename iterator_traits<_InputIterator>::value_type,
3875 typename iterator_traits<_ForwardIterator>::value_type>)
3876 __glibcxx_requires_valid_range(__first1, __last1);
3877 __glibcxx_requires_valid_range(__first2, __last2);
3879 for (; __first1 != __last1; ++__first1)
3880 for (_ForwardIterator __iter = __first2; __iter != __last2; ++__iter)
3881 if (__comp(*__first1, *__iter))
3895 template<
typename _ForwardIterator>
3896 inline _ForwardIterator
3897 adjacent_find(_ForwardIterator __first, _ForwardIterator __last)
3900 __glibcxx_function_requires(_ForwardIteratorConcept<_ForwardIterator>)
3901 __glibcxx_function_requires(_EqualityComparableConcept<
3902 typename iterator_traits<_ForwardIterator>::value_type>)
3903 __glibcxx_requires_valid_range(__first, __last);
3905 return std::__adjacent_find(__first, __last,
3906 __gnu_cxx::__ops::__iter_equal_to_iter());
3920 template<
typename _ForwardIterator,
typename _BinaryPredicate>
3921 inline _ForwardIterator
3922 adjacent_find(_ForwardIterator __first, _ForwardIterator __last,
3923 _BinaryPredicate __binary_pred)
3926 __glibcxx_function_requires(_ForwardIteratorConcept<_ForwardIterator>)
3927 __glibcxx_function_requires(_BinaryPredicateConcept<_BinaryPredicate,
3928 typename iterator_traits<_ForwardIterator>::value_type,
3929 typename iterator_traits<_ForwardIterator>::value_type>)
3930 __glibcxx_requires_valid_range(__first, __last);
3932 return std::__adjacent_find(__first, __last,
3933 __gnu_cxx::__ops::__iter_comp_iter(__binary_pred));
3945 template<
typename _InputIterator,
typename _Tp>
3946 inline typename iterator_traits<_InputIterator>::difference_type
3947 count(_InputIterator __first, _InputIterator __last,
const _Tp& __value)
3950 __glibcxx_function_requires(_InputIteratorConcept<_InputIterator>)
3951 __glibcxx_function_requires(_EqualOpConcept<
3952 typename iterator_traits<_InputIterator>::value_type, _Tp>)
3953 __glibcxx_requires_valid_range(__first, __last);
3955 return std::__count_if(__first, __last,
3956 __gnu_cxx::__ops::__iter_equals_val(__value));
3968 template<
typename _InputIterator,
typename _Predicate>
3969 inline typename iterator_traits<_InputIterator>::difference_type
3970 count_if(_InputIterator __first, _InputIterator __last, _Predicate __pred)
3973 __glibcxx_function_requires(_InputIteratorConcept<_InputIterator>)
3974 __glibcxx_function_requires(_UnaryPredicateConcept<_Predicate,
3975 typename iterator_traits<_InputIterator>::value_type>)
3976 __glibcxx_requires_valid_range(__first, __last);
3978 return std::__count_if(__first, __last,
3979 __gnu_cxx::__ops::__pred_iter(__pred));
4008 template<
typename _ForwardIterator1,
typename _ForwardIterator2>
4009 inline _ForwardIterator1
4010 search(_ForwardIterator1 __first1, _ForwardIterator1 __last1,
4011 _ForwardIterator2 __first2, _ForwardIterator2 __last2)
4014 __glibcxx_function_requires(_ForwardIteratorConcept<_ForwardIterator1>)
4015 __glibcxx_function_requires(_ForwardIteratorConcept<_ForwardIterator2>)
4016 __glibcxx_function_requires(_EqualOpConcept<
4017 typename iterator_traits<_ForwardIterator1>::value_type,
4018 typename iterator_traits<_ForwardIterator2>::value_type>)
4019 __glibcxx_requires_valid_range(__first1, __last1);
4020 __glibcxx_requires_valid_range(__first2, __last2);
4022 return std::__search(__first1, __last1, __first2, __last2,
4023 __gnu_cxx::__ops::__iter_equal_to_iter());
4047 template<
typename _ForwardIterator1,
typename _ForwardIterator2,
4048 typename _BinaryPredicate>
4049 inline _ForwardIterator1
4050 search(_ForwardIterator1 __first1, _ForwardIterator1 __last1,
4051 _ForwardIterator2 __first2, _ForwardIterator2 __last2,
4052 _BinaryPredicate __predicate)
4055 __glibcxx_function_requires(_ForwardIteratorConcept<_ForwardIterator1>)
4056 __glibcxx_function_requires(_ForwardIteratorConcept<_ForwardIterator2>)
4057 __glibcxx_function_requires(_BinaryPredicateConcept<_BinaryPredicate,
4058 typename iterator_traits<_ForwardIterator1>::value_type,
4059 typename iterator_traits<_ForwardIterator2>::value_type>)
4060 __glibcxx_requires_valid_range(__first1, __last1);
4061 __glibcxx_requires_valid_range(__first2, __last2);
4063 return std::__search(__first1, __last1, __first2, __last2,
4064 __gnu_cxx::__ops::__iter_comp_iter(__predicate));
4082 template<
typename _ForwardIterator,
typename _Integer,
typename _Tp>
4083 inline _ForwardIterator
4084 search_n(_ForwardIterator __first, _ForwardIterator __last,
4085 _Integer __count,
const _Tp& __val)
4088 __glibcxx_function_requires(_ForwardIteratorConcept<_ForwardIterator>)
4089 __glibcxx_function_requires(_EqualOpConcept<
4090 typename iterator_traits<_ForwardIterator>::value_type, _Tp>)
4091 __glibcxx_requires_valid_range(__first, __last);
4093 return std::__search_n(__first, __last, __count,
4094 __gnu_cxx::__ops::__iter_equals_val(__val));
4115 template<
typename _ForwardIterator,
typename _Integer,
typename _Tp,
4116 typename _BinaryPredicate>
4117 inline _ForwardIterator
4118 search_n(_ForwardIterator __first, _ForwardIterator __last,
4119 _Integer __count,
const _Tp& __val,
4120 _BinaryPredicate __binary_pred)
4123 __glibcxx_function_requires(_ForwardIteratorConcept<_ForwardIterator>)
4124 __glibcxx_function_requires(_BinaryPredicateConcept<_BinaryPredicate,
4125 typename iterator_traits<_ForwardIterator>::value_type, _Tp>)
4126 __glibcxx_requires_valid_range(__first, __last);
4128 return std::__search_n(__first, __last, __count,
4129 __gnu_cxx::__ops::__iter_comp_val(__binary_pred, __val));
4149 template<
typename _InputIterator,
typename _OutputIterator,
4150 typename _UnaryOperation>
4152 transform(_InputIterator __first, _InputIterator __last,
4153 _OutputIterator __result, _UnaryOperation __unary_op)
4156 __glibcxx_function_requires(_InputIteratorConcept<_InputIterator>)
4157 __glibcxx_function_requires(_OutputIteratorConcept<_OutputIterator,
4159 __typeof__(__unary_op(*__first))>)
4160 __glibcxx_requires_valid_range(__first, __last);
4162 for (; __first != __last; ++__first, ++__result)
4163 *__result = __unary_op(*__first);
4186 template<
typename _InputIterator1,
typename _InputIterator2,
4187 typename _OutputIterator,
typename _BinaryOperation>
4189 transform(_InputIterator1 __first1, _InputIterator1 __last1,
4190 _InputIterator2 __first2, _OutputIterator __result,
4191 _BinaryOperation __binary_op)
4194 __glibcxx_function_requires(_InputIteratorConcept<_InputIterator1>)
4195 __glibcxx_function_requires(_InputIteratorConcept<_InputIterator2>)
4196 __glibcxx_function_requires(_OutputIteratorConcept<_OutputIterator,
4198 __typeof__(__binary_op(*__first1,*__first2))>)
4199 __glibcxx_requires_valid_range(__first1, __last1);
4201 for (; __first1 != __last1; ++__first1, ++__first2, ++__result)
4202 *__result = __binary_op(*__first1, *__first2);
4219 template<
typename _ForwardIterator,
typename _Tp>
4221 replace(_ForwardIterator __first, _ForwardIterator __last,
4222 const _Tp& __old_value,
const _Tp& __new_value)
4225 __glibcxx_function_requires(_Mutable_ForwardIteratorConcept<
4227 __glibcxx_function_requires(_EqualOpConcept<
4228 typename iterator_traits<_ForwardIterator>::value_type, _Tp>)
4229 __glibcxx_function_requires(_ConvertibleConcept<_Tp,
4230 typename iterator_traits<_ForwardIterator>::value_type>)
4231 __glibcxx_requires_valid_range(__first, __last);
4233 for (; __first != __last; ++__first)
4234 if (*__first == __old_value)
4235 *__first = __new_value;
4251 template<
typename _ForwardIterator,
typename _Predicate,
typename _Tp>
4253 replace_if(_ForwardIterator __first, _ForwardIterator __last,
4254 _Predicate __pred,
const _Tp& __new_value)
4257 __glibcxx_function_requires(_Mutable_ForwardIteratorConcept<
4259 __glibcxx_function_requires(_ConvertibleConcept<_Tp,
4260 typename iterator_traits<_ForwardIterator>::value_type>)
4261 __glibcxx_function_requires(_UnaryPredicateConcept<_Predicate,
4262 typename iterator_traits<_ForwardIterator>::value_type>)
4263 __glibcxx_requires_valid_range(__first, __last);
4265 for (; __first != __last; ++__first)
4266 if (__pred(*__first))
4267 *__first = __new_value;
4283 template<
typename _ForwardIterator,
typename _Generator>
4285 generate(_ForwardIterator __first, _ForwardIterator __last,
4289 __glibcxx_function_requires(_ForwardIteratorConcept<_ForwardIterator>)
4290 __glibcxx_function_requires(_GeneratorConcept<_Generator,
4291 typename iterator_traits<_ForwardIterator>::value_type>)
4292 __glibcxx_requires_valid_range(__first, __last);
4294 for (; __first != __last; ++__first)
4314 template<
typename _OutputIterator,
typename _Size,
typename _Generator>
4316 generate_n(_OutputIterator __first, _Size __n, _Generator __gen)
4319 __glibcxx_function_requires(_OutputIteratorConcept<_OutputIterator,
4321 __typeof__(__gen())>)
4323 for (__decltype(__n + 0) __niter = __n;
4324 __niter > 0; --__niter, ++__first)
4350 template<
typename _InputIterator,
typename _OutputIterator>
4351 inline _OutputIterator
4352 unique_copy(_InputIterator __first, _InputIterator __last,
4353 _OutputIterator __result)
4356 __glibcxx_function_requires(_InputIteratorConcept<_InputIterator>)
4357 __glibcxx_function_requires(_OutputIteratorConcept<_OutputIterator,
4358 typename iterator_traits<_InputIterator>::value_type>)
4359 __glibcxx_function_requires(_EqualityComparableConcept<
4360 typename iterator_traits<_InputIterator>::value_type>)
4361 __glibcxx_requires_valid_range(__first, __last);
4363 if (__first == __last)
4366 __gnu_cxx::__ops::__iter_equal_to_iter(),
4390 template<
typename _InputIterator,
typename _OutputIterator,
4391 typename _BinaryPredicate>
4392 inline _OutputIterator
4393 unique_copy(_InputIterator __first, _InputIterator __last,
4394 _OutputIterator __result,
4395 _BinaryPredicate __binary_pred)
4398 __glibcxx_function_requires(_InputIteratorConcept<_InputIterator>)
4399 __glibcxx_function_requires(_OutputIteratorConcept<_OutputIterator,
4400 typename iterator_traits<_InputIterator>::value_type>)
4401 __glibcxx_requires_valid_range(__first, __last);
4403 if (__first == __last)
4406 __gnu_cxx::__ops::__iter_comp_iter(__binary_pred),
4422 template<
typename _RandomAccessIterator>
4424 random_shuffle(_RandomAccessIterator __first, _RandomAccessIterator __last)
4427 __glibcxx_function_requires(_Mutable_RandomAccessIteratorConcept<
4428 _RandomAccessIterator>)
4429 __glibcxx_requires_valid_range(__first, __last);
4431 if (__first != __last)
4432 for (_RandomAccessIterator __i = __first + 1; __i != __last; ++__i)
4433 std::iter_swap(__i, __first + (std::rand() % ((__i - __first) + 1)));
4450 template<
typename _RandomAccessIterator,
typename _RandomNumberGenerator>
4452 random_shuffle(_RandomAccessIterator __first, _RandomAccessIterator __last,
4453 #
if __cplusplus >= 201103L
4454 _RandomNumberGenerator&& __rand)
4456 _RandomNumberGenerator& __rand)
4460 __glibcxx_function_requires(_Mutable_RandomAccessIteratorConcept<
4461 _RandomAccessIterator>)
4462 __glibcxx_requires_valid_range(__first, __last);
4464 if (__first == __last)
4466 for (_RandomAccessIterator __i = __first + 1; __i != __last; ++__i)
4486 template<
typename _ForwardIterator,
typename _Predicate>
4487 inline _ForwardIterator
4488 partition(_ForwardIterator __first, _ForwardIterator __last,
4492 __glibcxx_function_requires(_Mutable_ForwardIteratorConcept<
4494 __glibcxx_function_requires(_UnaryPredicateConcept<_Predicate,
4495 typename iterator_traits<_ForwardIterator>::value_type>)
4496 __glibcxx_requires_valid_range(__first, __last);
4519 template<
typename _RandomAccessIterator>
4521 partial_sort(_RandomAccessIterator __first,
4522 _RandomAccessIterator __middle,
4523 _RandomAccessIterator __last)
4526 __glibcxx_function_requires(_Mutable_RandomAccessIteratorConcept<
4527 _RandomAccessIterator>)
4528 __glibcxx_function_requires(_LessThanComparableConcept<
4529 typename iterator_traits<_RandomAccessIterator>::value_type>)
4530 __glibcxx_requires_valid_range(__first, __middle);
4531 __glibcxx_requires_valid_range(__middle, __last);
4533 std::__partial_sort(__first, __middle, __last,
4534 __gnu_cxx::__ops::__iter_less_iter());
4556 template<
typename _RandomAccessIterator,
typename _Compare>
4558 partial_sort(_RandomAccessIterator __first,
4559 _RandomAccessIterator __middle,
4560 _RandomAccessIterator __last,
4564 __glibcxx_function_requires(_Mutable_RandomAccessIteratorConcept<
4565 _RandomAccessIterator>)
4566 __glibcxx_function_requires(_BinaryPredicateConcept<_Compare,
4567 typename iterator_traits<_RandomAccessIterator>::value_type,
4568 typename iterator_traits<_RandomAccessIterator>::value_type>)
4569 __glibcxx_requires_valid_range(__first, __middle);
4570 __glibcxx_requires_valid_range(__middle, __last);
4572 std::__partial_sort(__first, __middle, __last,
4573 __gnu_cxx::__ops::__iter_comp_iter(__comp));
4591 template<
typename _RandomAccessIterator>
4593 nth_element(_RandomAccessIterator __first, _RandomAccessIterator __nth,
4594 _RandomAccessIterator __last)
4597 __glibcxx_function_requires(_Mutable_RandomAccessIteratorConcept<
4598 _RandomAccessIterator>)
4599 __glibcxx_function_requires(_LessThanComparableConcept<
4600 typename iterator_traits<_RandomAccessIterator>::value_type>)
4601 __glibcxx_requires_valid_range(__first, __nth);
4602 __glibcxx_requires_valid_range(__nth, __last);
4604 if (__first == __last || __nth == __last)
4607 std::__introselect(__first, __nth, __last,
4609 __gnu_cxx::__ops::__iter_less_iter());
4629 template<
typename _RandomAccessIterator,
typename _Compare>
4631 nth_element(_RandomAccessIterator __first, _RandomAccessIterator __nth,
4632 _RandomAccessIterator __last, _Compare __comp)
4635 __glibcxx_function_requires(_Mutable_RandomAccessIteratorConcept<
4636 _RandomAccessIterator>)
4637 __glibcxx_function_requires(_BinaryPredicateConcept<_Compare,
4638 typename iterator_traits<_RandomAccessIterator>::value_type,
4639 typename iterator_traits<_RandomAccessIterator>::value_type>)
4640 __glibcxx_requires_valid_range(__first, __nth);
4641 __glibcxx_requires_valid_range(__nth, __last);
4643 if (__first == __last || __nth == __last)
4646 std::__introselect(__first, __nth, __last,
4648 __gnu_cxx::__ops::__iter_comp_iter(__comp));
4665 template<
typename _RandomAccessIterator>
4667 sort(_RandomAccessIterator __first, _RandomAccessIterator __last)
4670 __glibcxx_function_requires(_Mutable_RandomAccessIteratorConcept<
4671 _RandomAccessIterator>)
4672 __glibcxx_function_requires(_LessThanComparableConcept<
4673 typename iterator_traits<_RandomAccessIterator>::value_type>)
4674 __glibcxx_requires_valid_range(__first, __last);
4676 std::__sort(__first, __last, __gnu_cxx::__ops::__iter_less_iter());
4694 template<
typename _RandomAccessIterator,
typename _Compare>
4696 sort(_RandomAccessIterator __first, _RandomAccessIterator __last,
4700 __glibcxx_function_requires(_Mutable_RandomAccessIteratorConcept<
4701 _RandomAccessIterator>)
4702 __glibcxx_function_requires(_BinaryPredicateConcept<_Compare,
4703 typename iterator_traits<_RandomAccessIterator>::value_type,
4704 typename iterator_traits<_RandomAccessIterator>::value_type>)
4705 __glibcxx_requires_valid_range(__first, __last);
4707 std::__sort(__first, __last, __gnu_cxx::__ops::__iter_comp_iter(__comp));
4710 template<
typename _InputIterator1,
typename _InputIterator2,
4711 typename _OutputIterator,
typename _Compare>
4713 __merge(_InputIterator1 __first1, _InputIterator1 __last1,
4714 _InputIterator2 __first2, _InputIterator2 __last2,
4715 _OutputIterator __result, _Compare __comp)
4717 while (__first1 != __last1 && __first2 != __last2)
4719 if (__comp(__first2, __first1))
4721 *__result = *__first2;
4726 *__result = *__first1;
4731 return std::copy(__first2, __last2,
4732 std::copy(__first1, __last1, __result));
4754 template<
typename _InputIterator1,
typename _InputIterator2,
4755 typename _OutputIterator>
4756 inline _OutputIterator
4757 merge(_InputIterator1 __first1, _InputIterator1 __last1,
4758 _InputIterator2 __first2, _InputIterator2 __last2,
4759 _OutputIterator __result)
4762 __glibcxx_function_requires(_InputIteratorConcept<_InputIterator1>)
4763 __glibcxx_function_requires(_InputIteratorConcept<_InputIterator2>)
4764 __glibcxx_function_requires(_OutputIteratorConcept<_OutputIterator,
4765 typename iterator_traits<_InputIterator1>::value_type>)
4766 __glibcxx_function_requires(_OutputIteratorConcept<_OutputIterator,
4767 typename iterator_traits<_InputIterator2>::value_type>)
4768 __glibcxx_function_requires(_LessThanOpConcept<
4769 typename iterator_traits<_InputIterator2>::value_type,
4770 typename iterator_traits<_InputIterator1>::value_type>)
4771 __glibcxx_requires_sorted_set(__first1, __last1, __first2);
4772 __glibcxx_requires_sorted_set(__first2, __last2, __first1);
4774 return _GLIBCXX_STD_A::__merge(__first1, __last1,
4775 __first2, __last2, __result,
4776 __gnu_cxx::__ops::__iter_less_iter());
4802 template<
typename _InputIterator1,
typename _InputIterator2,
4803 typename _OutputIterator,
typename _Compare>
4804 inline _OutputIterator
4805 merge(_InputIterator1 __first1, _InputIterator1 __last1,
4806 _InputIterator2 __first2, _InputIterator2 __last2,
4807 _OutputIterator __result, _Compare __comp)
4810 __glibcxx_function_requires(_InputIteratorConcept<_InputIterator1>)
4811 __glibcxx_function_requires(_InputIteratorConcept<_InputIterator2>)
4812 __glibcxx_function_requires(_OutputIteratorConcept<_OutputIterator,
4813 typename iterator_traits<_InputIterator1>::value_type>)
4814 __glibcxx_function_requires(_OutputIteratorConcept<_OutputIterator,
4815 typename iterator_traits<_InputIterator2>::value_type>)
4816 __glibcxx_function_requires(_BinaryPredicateConcept<_Compare,
4817 typename iterator_traits<_InputIterator2>::value_type,
4818 typename iterator_traits<_InputIterator1>::value_type>)
4819 __glibcxx_requires_sorted_set_pred(__first1, __last1, __first2, __comp);
4820 __glibcxx_requires_sorted_set_pred(__first2, __last2, __first1, __comp);
4822 return _GLIBCXX_STD_A::__merge(__first1, __last1,
4823 __first2, __last2, __result,
4824 __gnu_cxx::__ops::__iter_comp_iter(__comp));
4827 template<
typename _RandomAccessIterator,
typename _Compare>
4829 __stable_sort(_RandomAccessIterator __first, _RandomAccessIterator __last,
4832 typedef typename iterator_traits<_RandomAccessIterator>::value_type
4834 typedef typename iterator_traits<_RandomAccessIterator>::difference_type
4837 typedef _Temporary_buffer<_RandomAccessIterator, _ValueType> _TmpBuf;
4838 _TmpBuf __buf(__first, __last);
4840 if (__buf.begin() == 0)
4843 std::__stable_sort_adaptive(__first, __last, __buf.begin(),
4844 _DistanceType(__buf.size()), __comp);
4864 template<
typename _RandomAccessIterator>
4866 stable_sort(_RandomAccessIterator __first, _RandomAccessIterator __last)
4869 __glibcxx_function_requires(_Mutable_RandomAccessIteratorConcept<
4870 _RandomAccessIterator>)
4871 __glibcxx_function_requires(_LessThanComparableConcept<
4872 typename iterator_traits<_RandomAccessIterator>::value_type>)
4873 __glibcxx_requires_valid_range(__first, __last);
4875 _GLIBCXX_STD_A::__stable_sort(__first, __last,
4876 __gnu_cxx::__ops::__iter_less_iter());
4897 template<
typename _RandomAccessIterator,
typename _Compare>
4899 stable_sort(_RandomAccessIterator __first, _RandomAccessIterator __last,
4903 __glibcxx_function_requires(_Mutable_RandomAccessIteratorConcept<
4904 _RandomAccessIterator>)
4905 __glibcxx_function_requires(_BinaryPredicateConcept<_Compare,
4906 typename iterator_traits<_RandomAccessIterator>::value_type,
4907 typename iterator_traits<_RandomAccessIterator>::value_type>)
4908 __glibcxx_requires_valid_range(__first, __last);
4910 _GLIBCXX_STD_A::__stable_sort(__first, __last,
4911 __gnu_cxx::__ops::__iter_comp_iter(__comp));
4914 template<
typename _InputIterator1,
typename _InputIterator2,
4915 typename _OutputIterator,
4918 __set_union(_InputIterator1 __first1, _InputIterator1 __last1,
4919 _InputIterator2 __first2, _InputIterator2 __last2,
4920 _OutputIterator __result, _Compare __comp)
4922 while (__first1 != __last1 && __first2 != __last2)
4924 if (__comp(__first1, __first2))
4926 *__result = *__first1;
4929 else if (__comp(__first2, __first1))
4931 *__result = *__first2;
4936 *__result = *__first1;
4942 return std::copy(__first2, __last2,
4943 std::copy(__first1, __last1, __result));
4964 template<
typename _InputIterator1,
typename _InputIterator2,
4965 typename _OutputIterator>
4966 inline _OutputIterator
4967 set_union(_InputIterator1 __first1, _InputIterator1 __last1,
4968 _InputIterator2 __first2, _InputIterator2 __last2,
4969 _OutputIterator __result)
4972 __glibcxx_function_requires(_InputIteratorConcept<_InputIterator1>)
4973 __glibcxx_function_requires(_InputIteratorConcept<_InputIterator2>)
4974 __glibcxx_function_requires(_OutputIteratorConcept<_OutputIterator,
4975 typename iterator_traits<_InputIterator1>::value_type>)
4976 __glibcxx_function_requires(_OutputIteratorConcept<_OutputIterator,
4977 typename iterator_traits<_InputIterator2>::value_type>)
4978 __glibcxx_function_requires(_LessThanOpConcept<
4979 typename iterator_traits<_InputIterator1>::value_type,
4980 typename iterator_traits<_InputIterator2>::value_type>)
4981 __glibcxx_function_requires(_LessThanOpConcept<
4982 typename iterator_traits<_InputIterator2>::value_type,
4983 typename iterator_traits<_InputIterator1>::value_type>)
4984 __glibcxx_requires_sorted_set(__first1, __last1, __first2);
4985 __glibcxx_requires_sorted_set(__first2, __last2, __first1);
4987 return _GLIBCXX_STD_A::__set_union(__first1, __last1,
4988 __first2, __last2, __result,
4989 __gnu_cxx::__ops::__iter_less_iter());
5011 template<
typename _InputIterator1,
typename _InputIterator2,
5012 typename _OutputIterator,
typename _Compare>
5013 inline _OutputIterator
5014 set_union(_InputIterator1 __first1, _InputIterator1 __last1,
5015 _InputIterator2 __first2, _InputIterator2 __last2,
5016 _OutputIterator __result, _Compare __comp)
5019 __glibcxx_function_requires(_InputIteratorConcept<_InputIterator1>)
5020 __glibcxx_function_requires(_InputIteratorConcept<_InputIterator2>)
5021 __glibcxx_function_requires(_OutputIteratorConcept<_OutputIterator,
5022 typename iterator_traits<_InputIterator1>::value_type>)
5023 __glibcxx_function_requires(_OutputIteratorConcept<_OutputIterator,
5024 typename iterator_traits<_InputIterator2>::value_type>)
5025 __glibcxx_function_requires(_BinaryPredicateConcept<_Compare,
5026 typename iterator_traits<_InputIterator1>::value_type,
5027 typename iterator_traits<_InputIterator2>::value_type>)
5028 __glibcxx_function_requires(_BinaryPredicateConcept<_Compare,
5029 typename iterator_traits<_InputIterator2>::value_type,
5030 typename iterator_traits<_InputIterator1>::value_type>)
5031 __glibcxx_requires_sorted_set_pred(__first1, __last1, __first2, __comp);
5032 __glibcxx_requires_sorted_set_pred(__first2, __last2, __first1, __comp);
5034 return _GLIBCXX_STD_A::__set_union(__first1, __last1,
5035 __first2, __last2, __result,
5036 __gnu_cxx::__ops::__iter_comp_iter(__comp));
5039 template<
typename _InputIterator1,
typename _InputIterator2,
5040 typename _OutputIterator,
5043 __set_intersection(_InputIterator1 __first1, _InputIterator1 __last1,
5044 _InputIterator2 __first2, _InputIterator2 __last2,
5045 _OutputIterator __result, _Compare __comp)
5047 while (__first1 != __last1 && __first2 != __last2)
5048 if (__comp(__first1, __first2))
5050 else if (__comp(__first2, __first1))
5054 *__result = *__first1;
5079 template<
typename _InputIterator1,
typename _InputIterator2,
5080 typename _OutputIterator>
5081 inline _OutputIterator
5082 set_intersection(_InputIterator1 __first1, _InputIterator1 __last1,
5083 _InputIterator2 __first2, _InputIterator2 __last2,
5084 _OutputIterator __result)
5087 __glibcxx_function_requires(_InputIteratorConcept<_InputIterator1>)
5088 __glibcxx_function_requires(_InputIteratorConcept<_InputIterator2>)
5089 __glibcxx_function_requires(_OutputIteratorConcept<_OutputIterator,
5090 typename iterator_traits<_InputIterator1>::value_type>)
5091 __glibcxx_function_requires(_LessThanOpConcept<
5092 typename iterator_traits<_InputIterator1>::value_type,
5093 typename iterator_traits<_InputIterator2>::value_type>)
5094 __glibcxx_function_requires(_LessThanOpConcept<
5095 typename iterator_traits<_InputIterator2>::value_type,
5096 typename iterator_traits<_InputIterator1>::value_type>)
5097 __glibcxx_requires_sorted_set(__first1, __last1, __first2);
5098 __glibcxx_requires_sorted_set(__first2, __last2, __first1);
5100 return _GLIBCXX_STD_A::__set_intersection(__first1, __last1,
5101 __first2, __last2, __result,
5102 __gnu_cxx::__ops::__iter_less_iter());
5125 template<
typename _InputIterator1,
typename _InputIterator2,
5126 typename _OutputIterator,
typename _Compare>
5127 inline _OutputIterator
5128 set_intersection(_InputIterator1 __first1, _InputIterator1 __last1,
5129 _InputIterator2 __first2, _InputIterator2 __last2,
5130 _OutputIterator __result, _Compare __comp)
5133 __glibcxx_function_requires(_InputIteratorConcept<_InputIterator1>)
5134 __glibcxx_function_requires(_InputIteratorConcept<_InputIterator2>)
5135 __glibcxx_function_requires(_OutputIteratorConcept<_OutputIterator,
5136 typename iterator_traits<_InputIterator1>::value_type>)
5137 __glibcxx_function_requires(_BinaryPredicateConcept<_Compare,
5138 typename iterator_traits<_InputIterator1>::value_type,
5139 typename iterator_traits<_InputIterator2>::value_type>)
5140 __glibcxx_function_requires(_BinaryPredicateConcept<_Compare,
5141 typename iterator_traits<_InputIterator2>::value_type,
5142 typename iterator_traits<_InputIterator1>::value_type>)
5143 __glibcxx_requires_sorted_set_pred(__first1, __last1, __first2, __comp);
5144 __glibcxx_requires_sorted_set_pred(__first2, __last2, __first1, __comp);
5146 return _GLIBCXX_STD_A::__set_intersection(__first1, __last1,
5147 __first2, __last2, __result,
5148 __gnu_cxx::__ops::__iter_comp_iter(__comp));
5151 template<
typename _InputIterator1,
typename _InputIterator2,
5152 typename _OutputIterator,
5155 __set_difference(_InputIterator1 __first1, _InputIterator1 __last1,
5156 _InputIterator2 __first2, _InputIterator2 __last2,
5157 _OutputIterator __result, _Compare __comp)
5159 while (__first1 != __last1 && __first2 != __last2)
5160 if (__comp(__first1, __first2))
5162 *__result = *__first1;
5166 else if (__comp(__first2, __first1))
5173 return std::copy(__first1, __last1, __result);
5195 template<
typename _InputIterator1,
typename _InputIterator2,
5196 typename _OutputIterator>
5197 inline _OutputIterator
5198 set_difference(_InputIterator1 __first1, _InputIterator1 __last1,
5199 _InputIterator2 __first2, _InputIterator2 __last2,
5200 _OutputIterator __result)
5203 __glibcxx_function_requires(_InputIteratorConcept<_InputIterator1>)
5204 __glibcxx_function_requires(_InputIteratorConcept<_InputIterator2>)
5205 __glibcxx_function_requires(_OutputIteratorConcept<_OutputIterator,
5206 typename iterator_traits<_InputIterator1>::value_type>)
5207 __glibcxx_function_requires(_LessThanOpConcept<
5208 typename iterator_traits<_InputIterator1>::value_type,
5209 typename iterator_traits<_InputIterator2>::value_type>)
5210 __glibcxx_function_requires(_LessThanOpConcept<
5211 typename iterator_traits<_InputIterator2>::value_type,
5212 typename iterator_traits<_InputIterator1>::value_type>)
5213 __glibcxx_requires_sorted_set(__first1, __last1, __first2);
5214 __glibcxx_requires_sorted_set(__first2, __last2, __first1);
5216 return _GLIBCXX_STD_A::__set_difference(__first1, __last1,
5217 __first2, __last2, __result,
5218 __gnu_cxx::__ops::__iter_less_iter());
5243 template<
typename _InputIterator1,
typename _InputIterator2,
5244 typename _OutputIterator,
typename _Compare>
5245 inline _OutputIterator
5246 set_difference(_InputIterator1 __first1, _InputIterator1 __last1,
5247 _InputIterator2 __first2, _InputIterator2 __last2,
5248 _OutputIterator __result, _Compare __comp)
5251 __glibcxx_function_requires(_InputIteratorConcept<_InputIterator1>)
5252 __glibcxx_function_requires(_InputIteratorConcept<_InputIterator2>)
5253 __glibcxx_function_requires(_OutputIteratorConcept<_OutputIterator,
5254 typename iterator_traits<_InputIterator1>::value_type>)
5255 __glibcxx_function_requires(_BinaryPredicateConcept<_Compare,
5256 typename iterator_traits<_InputIterator1>::value_type,
5257 typename iterator_traits<_InputIterator2>::value_type>)
5258 __glibcxx_function_requires(_BinaryPredicateConcept<_Compare,
5259 typename iterator_traits<_InputIterator2>::value_type,
5260 typename iterator_traits<_InputIterator1>::value_type>)
5261 __glibcxx_requires_sorted_set_pred(__first1, __last1, __first2, __comp);
5262 __glibcxx_requires_sorted_set_pred(__first2, __last2, __first1, __comp);
5264 return _GLIBCXX_STD_A::__set_difference(__first1, __last1,
5265 __first2, __last2, __result,
5266 __gnu_cxx::__ops::__iter_comp_iter(__comp));
5269 template<
typename _InputIterator1,
typename _InputIterator2,
5270 typename _OutputIterator,
5273 __set_symmetric_difference(_InputIterator1 __first1,
5274 _InputIterator1 __last1,
5275 _InputIterator2 __first2,
5276 _InputIterator2 __last2,
5277 _OutputIterator __result,
5280 while (__first1 != __last1 && __first2 != __last2)
5281 if (__comp(__first1, __first2))
5283 *__result = *__first1;
5287 else if (__comp(__first2, __first1))
5289 *__result = *__first2;
5298 return std::copy(__first2, __last2,
5299 std::copy(__first1, __last1, __result));
5319 template<
typename _InputIterator1,
typename _InputIterator2,
5320 typename _OutputIterator>
5321 inline _OutputIterator
5322 set_symmetric_difference(_InputIterator1 __first1, _InputIterator1 __last1,
5323 _InputIterator2 __first2, _InputIterator2 __last2,
5324 _OutputIterator __result)
5327 __glibcxx_function_requires(_InputIteratorConcept<_InputIterator1>)
5328 __glibcxx_function_requires(_InputIteratorConcept<_InputIterator2>)
5329 __glibcxx_function_requires(_OutputIteratorConcept<_OutputIterator,
5330 typename iterator_traits<_InputIterator1>::value_type>)
5331 __glibcxx_function_requires(_OutputIteratorConcept<_OutputIterator,
5332 typename iterator_traits<_InputIterator2>::value_type>)
5333 __glibcxx_function_requires(_LessThanOpConcept<
5334 typename iterator_traits<_InputIterator1>::value_type,
5335 typename iterator_traits<_InputIterator2>::value_type>)
5336 __glibcxx_function_requires(_LessThanOpConcept<
5337 typename iterator_traits<_InputIterator2>::value_type,
5338 typename iterator_traits<_InputIterator1>::value_type>)
5339 __glibcxx_requires_sorted_set(__first1, __last1, __first2);
5340 __glibcxx_requires_sorted_set(__first2, __last2, __first1);
5342 return _GLIBCXX_STD_A::__set_symmetric_difference(__first1, __last1,
5343 __first2, __last2, __result,
5344 __gnu_cxx::__ops::__iter_less_iter());
5367 template<
typename _InputIterator1,
typename _InputIterator2,
5368 typename _OutputIterator,
typename _Compare>
5369 inline _OutputIterator
5370 set_symmetric_difference(_InputIterator1 __first1, _InputIterator1 __last1,
5371 _InputIterator2 __first2, _InputIterator2 __last2,
5372 _OutputIterator __result,
5376 __glibcxx_function_requires(_InputIteratorConcept<_InputIterator1>)
5377 __glibcxx_function_requires(_InputIteratorConcept<_InputIterator2>)
5378 __glibcxx_function_requires(_OutputIteratorConcept<_OutputIterator,
5379 typename iterator_traits<_InputIterator1>::value_type>)
5380 __glibcxx_function_requires(_OutputIteratorConcept<_OutputIterator,
5381 typename iterator_traits<_InputIterator2>::value_type>)
5382 __glibcxx_function_requires(_BinaryPredicateConcept<_Compare,
5383 typename iterator_traits<_InputIterator1>::value_type,
5384 typename iterator_traits<_InputIterator2>::value_type>)
5385 __glibcxx_function_requires(_BinaryPredicateConcept<_Compare,
5386 typename iterator_traits<_InputIterator2>::value_type,
5387 typename iterator_traits<_InputIterator1>::value_type>)
5388 __glibcxx_requires_sorted_set_pred(__first1, __last1, __first2, __comp);
5389 __glibcxx_requires_sorted_set_pred(__first2, __last2, __first1, __comp);
5391 return _GLIBCXX_STD_A::__set_symmetric_difference(__first1, __last1,
5392 __first2, __last2, __result,
5393 __gnu_cxx::__ops::__iter_comp_iter(__comp));
5396 template<
typename _ForwardIterator,
typename _Compare>
5398 __min_element(_ForwardIterator __first, _ForwardIterator __last,
5401 if (__first == __last)
5403 _ForwardIterator __result = __first;
5404 while (++__first != __last)
5405 if (__comp(__first, __result))
5417 template<
typename _ForwardIterator>
5419 inline min_element(_ForwardIterator __first, _ForwardIterator __last)
5422 __glibcxx_function_requires(_ForwardIteratorConcept<_ForwardIterator>)
5423 __glibcxx_function_requires(_LessThanComparableConcept<
5424 typename iterator_traits<_ForwardIterator>::value_type>)
5425 __glibcxx_requires_valid_range(__first, __last);
5427 return _GLIBCXX_STD_A::__min_element(__first, __last,
5428 __gnu_cxx::__ops::__iter_less_iter());
5440 template<
typename _ForwardIterator,
typename _Compare>
5441 inline _ForwardIterator
5442 min_element(_ForwardIterator __first, _ForwardIterator __last,
5446 __glibcxx_function_requires(_ForwardIteratorConcept<_ForwardIterator>)
5447 __glibcxx_function_requires(_BinaryPredicateConcept<_Compare,
5448 typename iterator_traits<_ForwardIterator>::value_type,
5449 typename iterator_traits<_ForwardIterator>::value_type>)
5450 __glibcxx_requires_valid_range(__first, __last);
5452 return _GLIBCXX_STD_A::__min_element(__first, __last,
5453 __gnu_cxx::__ops::__iter_comp_iter(__comp));
5456 template<
typename _ForwardIterator,
typename _Compare>
5458 __max_element(_ForwardIterator __first, _ForwardIterator __last,
5461 if (__first == __last)
return __first;
5462 _ForwardIterator __result = __first;
5463 while (++__first != __last)
5464 if (__comp(__result, __first))
5476 template<
typename _ForwardIterator>
5477 inline _ForwardIterator
5478 max_element(_ForwardIterator __first, _ForwardIterator __last)
5481 __glibcxx_function_requires(_ForwardIteratorConcept<_ForwardIterator>)
5482 __glibcxx_function_requires(_LessThanComparableConcept<
5483 typename iterator_traits<_ForwardIterator>::value_type>)
5484 __glibcxx_requires_valid_range(__first, __last);
5486 return _GLIBCXX_STD_A::__max_element(__first, __last,
5487 __gnu_cxx::__ops::__iter_less_iter());
5499 template<
typename _ForwardIterator,
typename _Compare>
5500 inline _ForwardIterator
5501 max_element(_ForwardIterator __first, _ForwardIterator __last,
5505 __glibcxx_function_requires(_ForwardIteratorConcept<_ForwardIterator>)
5506 __glibcxx_function_requires(_BinaryPredicateConcept<_Compare,
5507 typename iterator_traits<_ForwardIterator>::value_type,
5508 typename iterator_traits<_ForwardIterator>::value_type>)
5509 __glibcxx_requires_valid_range(__first, __last);
5511 return _GLIBCXX_STD_A::__max_element(__first, __last,
5512 __gnu_cxx::__ops::__iter_comp_iter(__comp));
5515 _GLIBCXX_END_NAMESPACE_ALGO
void __final_insertion_sort(_RandomAccessIterator __first, _RandomAccessIterator __last, _Compare __comp)
This is a helper function for the sort routine.
_ForwardIterator2 swap_ranges(_ForwardIterator1 __first1, _ForwardIterator1 __last1, _ForwardIterator2 __first2)
Swap the elements of two sequences.
_InputIterator find_if_not(_InputIterator __first, _InputIterator __last, _Predicate __pred)
Find the first element in a sequence for which a predicate is false.
_RandomAccessIterator __unguarded_partition_pivot(_RandomAccessIterator __first, _RandomAccessIterator __last, _Compare __comp)
This is a helper function...
_RandomAccessIterator __unguarded_partition(_RandomAccessIterator __first, _RandomAccessIterator __last, _RandomAccessIterator __pivot, _Compare __comp)
This is a helper function...
Forward iterators support a superset of input iterator operations.
constexpr pair< typename __decay_and_strip< _T1 >::__type, typename __decay_and_strip< _T2 >::__type > make_pair(_T1 &&__x, _T2 &&__y)
A convenience wrapper for creating a pair from two objects.
_OutputIterator __unique_copy(_ForwardIterator __first, _ForwardIterator __last, _OutputIterator __result, _BinaryPredicate __binary_pred, forward_iterator_tag, output_iterator_tag)
_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.
_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...
void __introsort_loop(_RandomAccessIterator __first, _RandomAccessIterator __last, _Size __depth_limit, _Compare __comp)
This is a helper function for the sort routine.
Struct holding two objects of arbitrary type.
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.
pair< const _Tp &, const _Tp & > minmax(const _Tp &, const _Tp &)
Determines min and max at once as an ordered pair.
_ForwardIterator __inplace_stable_partition(_ForwardIterator __first, _Predicate __pred, _Distance __len)
This is a helper function... Requires __len != 0 and !__pred(*__first), same as __stable_partition_ad...
constexpr int __lg(int __n)
This is a helper function for the sort routines and for random.tcc.
void __inplace_stable_sort(_RandomAccessIterator __first, _RandomAccessIterator __last, _Compare __comp)
This is a helper function for the stable sorting routines.
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.
Random-access iterators support a superset of bidirectional iterator operations.
void __move_median_to_first(_Iterator __result, _Iterator __a, _Iterator __b, _Iterator __c, _Compare __comp)
Swaps the median value of *__a, *__b and *__c under __comp to *__result.
iterator_traits< _InputIterator >::difference_type distance(_InputIterator __first, _InputIterator __last)
A generalization of pointer arithmetic.
void iter_swap(_ForwardIterator1 __a, _ForwardIterator2 __b)
Swaps the contents of two iterators.
void __unguarded_insertion_sort(_RandomAccessIterator __first, _RandomAccessIterator __last, _Compare __comp)
This is a helper function for the sort routine.
const _Tp & max(const _Tp &, const _Tp &)
This does what you think it does.
_ForwardIterator __partition(_ForwardIterator __first, _ForwardIterator __last, _Predicate __pred, forward_iterator_tag)
This is a helper function...
_ForwardIterator is_sorted_until(_ForwardIterator __first, _ForwardIterator __last, _Compare __comp)
Determines the end of a sorted sequence using comparison functor.
void __unguarded_linear_insert(_RandomAccessIterator __last, _Compare __comp)
This is a helper function for the sort routine.
_ForwardIterator max_element(_ForwardIterator __first, _ForwardIterator __last, _Compare __comp)
Return the maximum element in a range using comparison functor.
size_t count() const noexcept
Returns the number of bits which are set.
void __reverse(_BidirectionalIterator __first, _BidirectionalIterator __last, bidirectional_iterator_tag)
const _Tp & min(const _Tp &, const _Tp &)
This does what you think it does.
void __rotate(_ForwardIterator __first, _ForwardIterator __middle, _ForwardIterator __last, forward_iterator_tag)
This is a helper function for the rotate algorithm.
void __insertion_sort(_RandomAccessIterator __first, _RandomAccessIterator __last, _Compare __comp)
This is a helper function for the sort routine.
_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.
_ForwardIterator __stable_partition_adaptive(_ForwardIterator __first, _ForwardIterator __last, _Predicate __pred, _Distance __len, _Pointer __buffer, _Distance __buffer_size)
This is a helper function... Requires __first != __last and !__pred(__first) and __len == distance(__...
void __heap_select(_RandomAccessIterator __first, _RandomAccessIterator __middle, _RandomAccessIterator __last, _Compare __comp)
This is a helper function for the sort routines.
_InputIterator __find_if_not(_InputIterator __first, _InputIterator __last, _Predicate __pred)
Provided for stable_partition to use.
Bidirectional iterators support a superset of forward iterator operations.
bool none_of(_InputIterator __first, _InputIterator __last, _Predicate __pred)
Checks that a predicate is false for all the elements of a sequence.
_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.
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.
_EuclideanRingElement __gcd(_EuclideanRingElement __m, _EuclideanRingElement __n)
void advance(_InputIterator &__i, _Distance __n)
A generalization of pointer arithmetic.
void swap(function< _Res(_Args...)> &__x, function< _Res(_Args...)> &__y)
Swap the targets of two polymorphic function object wrappers.
iterator_traits< _Iter >::iterator_category __iterator_category(const _Iter &)
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.
Marking output iterators.
void rotate(_ForwardIterator __first, _ForwardIterator __middle, _ForwardIterator __last)
Rotate the elements of a sequence.
Uniform discrete distribution for random numbers. A discrete random distribution on the range with e...
_ForwardIterator min_element(_ForwardIterator __first, _ForwardIterator __last, _Compare __comp)
Return the minimum element in a range using comparison functor.
_ForwardIterator __search_n_aux(_ForwardIterator __first, _ForwardIterator __last, _Integer __count, _UnaryPredicate __unary_pred, std::forward_iterator_tag)
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.