30 #ifndef _RANGES_ALGO_H
31 #define _RANGES_ALGO_H 1
33 #if __cplusplus > 201703L
38 #if __cpp_lib_concepts
39 namespace std _GLIBCXX_VISIBILITY(default)
41 _GLIBCXX_BEGIN_NAMESPACE_VERSION
46 template<
typename _Comp,
typename _Proj>
48 __make_comp_proj(_Comp& __comp, _Proj& __proj)
50 return [&] (
auto&& __lhs,
auto&& __rhs) ->
bool {
51 using _TL = decltype(__lhs);
52 using _TR = decltype(__rhs);
59 template<
typename _Pred,
typename _Proj>
61 __make_pred_proj(_Pred& __pred, _Proj& __proj)
63 return [&] <
typename _Tp> (_Tp&& __arg) ->
bool {
72 template<input_iterator _Iter, sentinel_for<_Iter> _Sent,
73 typename _Proj =
identity,
74 indirect_unary_predicate<projected<_Iter, _Proj>> _Pred>
76 operator()(_Iter __first, _Sent __last,
77 _Pred __pred, _Proj __proj = {})
const
79 for (; __first != __last; ++__first)
85 template<input_range _Range,
typename _Proj = identity,
86 indirect_unary_predicate<projected<iterator_t<_Range>, _Proj>>
89 operator()(_Range&& __r, _Pred __pred, _Proj __proj = {})
const
96 inline constexpr __all_of_fn all_of{};
100 template<input_iterator _Iter, sentinel_for<_Iter> _Sent,
101 typename _Proj =
identity,
102 indirect_unary_predicate<projected<_Iter, _Proj>> _Pred>
104 operator()(_Iter __first, _Sent __last,
105 _Pred __pred, _Proj __proj = {})
const
107 for (; __first != __last; ++__first)
113 template<input_range _Range,
typename _Proj = identity,
114 indirect_unary_predicate<projected<iterator_t<_Range>, _Proj>>
117 operator()(_Range&& __r, _Pred __pred, _Proj __proj = {})
const
124 inline constexpr __any_of_fn any_of{};
128 template<input_iterator _Iter, sentinel_for<_Iter> _Sent,
129 typename _Proj =
identity,
130 indirect_unary_predicate<projected<_Iter, _Proj>> _Pred>
132 operator()(_Iter __first, _Sent __last,
133 _Pred __pred, _Proj __proj = {})
const
135 for (; __first != __last; ++__first)
141 template<input_range _Range,
typename _Proj = identity,
142 indirect_unary_predicate<projected<iterator_t<_Range>, _Proj>>
145 operator()(_Range&& __r, _Pred __pred, _Proj __proj = {})
const
152 inline constexpr __none_of_fn none_of{};
154 template<
typename _Iter,
typename _Fp>
157 [[no_unique_address]] _Iter in;
158 [[no_unique_address]] _Fp fun;
160 template<
typename _Iter2,
typename _F2p>
161 requires convertible_to<const _Iter&, _Iter2>
162 && convertible_to<const _Fp&, _F2p>
164 operator in_fun_result<_Iter2, _F2p>() const &
165 {
return {in, fun}; }
167 template<
typename _Iter2,
typename _F2p>
168 requires convertible_to<_Iter, _Iter2> && convertible_to<_Fp, _F2p>
170 operator in_fun_result<_Iter2, _F2p>() &&
174 template<
typename _Iter,
typename _Fp>
175 using for_each_result = in_fun_result<_Iter, _Fp>;
179 template<input_iterator _Iter, sentinel_for<_Iter> _Sent,
180 typename _Proj =
identity,
181 indirectly_unary_invocable<projected<_Iter, _Proj>> _Fun>
182 constexpr for_each_result<_Iter, _Fun>
183 operator()(_Iter __first, _Sent __last, _Fun __f, _Proj __proj = {})
const
185 for (; __first != __last; ++__first)
190 template<input_range _Range,
typename _Proj = identity,
191 indirectly_unary_invocable<projected<iterator_t<_Range>, _Proj>>
193 constexpr for_each_result<borrowed_iterator_t<_Range>, _Fun>
194 operator()(_Range&& __r, _Fun __f, _Proj __proj = {})
const
201 inline constexpr __for_each_fn for_each{};
203 template<
typename _Iter,
typename _Fp>
204 using for_each_n_result = in_fun_result<_Iter, _Fp>;
206 struct __for_each_n_fn
208 template<input_iterator _Iter,
typename _Proj = identity,
209 indirectly_unary_invocable<projected<_Iter, _Proj>> _Fun>
210 constexpr for_each_n_result<_Iter, _Fun>
211 operator()(_Iter __first, iter_difference_t<_Iter> __n,
212 _Fun __f, _Proj __proj = {})
const
214 if constexpr (random_access_iterator<_Iter>)
218 auto __last = __first + __n;
234 inline constexpr __for_each_n_fn for_each_n{};
238 template<input_iterator _Iter, sentinel_for<_Iter> _Sent,
typename _Tp,
239 typename _Proj =
identity>
240 requires indirect_binary_predicate<ranges::equal_to,
241 projected<_Iter, _Proj>,
const _Tp*>
243 operator()(_Iter __first, _Sent __last,
244 const _Tp& __value, _Proj __proj = {})
const
246 while (__first != __last
252 template<input_range _Range,
typename _Tp,
typename _Proj =
identity>
253 requires indirect_binary_predicate<ranges::equal_to,
254 projected<iterator_t<_Range>, _Proj>,
256 constexpr borrowed_iterator_t<_Range>
257 operator()(_Range&& __r,
const _Tp& __value, _Proj __proj = {})
const
264 inline constexpr __find_fn find{};
268 template<input_iterator _Iter, sentinel_for<_Iter> _Sent,
269 typename _Proj =
identity,
270 indirect_unary_predicate<projected<_Iter, _Proj>> _Pred>
272 operator()(_Iter __first, _Sent __last,
273 _Pred __pred, _Proj __proj = {})
const
275 while (__first != __last
281 template<input_range _Range,
typename _Proj = identity,
282 indirect_unary_predicate<projected<iterator_t<_Range>, _Proj>>
284 constexpr borrowed_iterator_t<_Range>
285 operator()(_Range&& __r, _Pred __pred, _Proj __proj = {})
const
292 inline constexpr __find_if_fn find_if{};
294 struct __find_if_not_fn
296 template<input_iterator _Iter, sentinel_for<_Iter> _Sent,
297 typename _Proj =
identity,
298 indirect_unary_predicate<projected<_Iter, _Proj>> _Pred>
300 operator()(_Iter __first, _Sent __last,
301 _Pred __pred, _Proj __proj = {})
const
303 while (__first != __last
309 template<input_range _Range,
typename _Proj = identity,
310 indirect_unary_predicate<projected<iterator_t<_Range>, _Proj>>
312 constexpr borrowed_iterator_t<_Range>
313 operator()(_Range&& __r, _Pred __pred, _Proj __proj = {})
const
320 inline constexpr __find_if_not_fn find_if_not{};
322 struct __find_first_of_fn
324 template<input_iterator _Iter1, sentinel_for<_Iter1> _Sent1,
325 forward_iterator _Iter2, sentinel_for<_Iter2> _Sent2,
326 typename _Pred = ranges::equal_to,
327 typename _Proj1 =
identity,
typename _Proj2 =
identity>
328 requires indirectly_comparable<_Iter1, _Iter2, _Pred, _Proj1, _Proj2>
330 operator()(_Iter1 __first1, _Sent1 __last1,
331 _Iter2 __first2, _Sent2 __last2, _Pred __pred = {},
332 _Proj1 __proj1 = {}, _Proj2 __proj2 = {})
const
334 for (; __first1 != __last1; ++__first1)
335 for (
auto __iter = __first2; __iter != __last2; ++__iter)
343 template<input_range _Range1, forward_range _Range2,
344 typename _Pred = ranges::equal_to,
345 typename _Proj1 = identity,
typename _Proj2 = identity>
346 requires indirectly_comparable<iterator_t<_Range1>, iterator_t<_Range2>,
347 _Pred, _Proj1, _Proj2>
348 constexpr borrowed_iterator_t<_Range1>
349 operator()(_Range1&& __r1, _Range2&& __r2, _Pred __pred = {},
350 _Proj1 __proj1 = {}, _Proj2 __proj2 = {})
const
359 inline constexpr __find_first_of_fn find_first_of{};
363 template<input_iterator _Iter, sentinel_for<_Iter> _Sent,
364 typename _Tp,
typename _Proj =
identity>
365 requires indirect_binary_predicate<ranges::equal_to,
366 projected<_Iter, _Proj>,
368 constexpr iter_difference_t<_Iter>
369 operator()(_Iter __first, _Sent __last,
370 const _Tp& __value, _Proj __proj = {})
const
372 iter_difference_t<_Iter> __n = 0;
373 for (; __first != __last; ++__first)
379 template<input_range _Range,
typename _Tp,
typename _Proj =
identity>
380 requires indirect_binary_predicate<ranges::equal_to,
381 projected<iterator_t<_Range>, _Proj>,
383 constexpr range_difference_t<_Range>
384 operator()(_Range&& __r,
const _Tp& __value, _Proj __proj = {})
const
391 inline constexpr __count_fn count{};
395 template<input_iterator _Iter, sentinel_for<_Iter> _Sent,
396 typename _Proj =
identity,
397 indirect_unary_predicate<projected<_Iter, _Proj>> _Pred>
398 constexpr iter_difference_t<_Iter>
399 operator()(_Iter __first, _Sent __last,
400 _Pred __pred, _Proj __proj = {})
const
402 iter_difference_t<_Iter> __n = 0;
403 for (; __first != __last; ++__first)
409 template<input_range _Range,
410 typename _Proj = identity,
411 indirect_unary_predicate<projected<iterator_t<_Range>, _Proj>>
413 constexpr range_difference_t<_Range>
414 operator()(_Range&& __r, _Pred __pred, _Proj __proj = {})
const
421 inline constexpr __count_if_fn count_if{};
423 template<
typename _Iter1,
typename _Iter2>
426 [[no_unique_address]] _Iter1 in1;
427 [[no_unique_address]] _Iter2 in2;
429 template<
typename _IIter1,
typename _IIter2>
430 requires convertible_to<const _Iter1&, _IIter1>
431 && convertible_to<const _Iter2&, _IIter2>
433 operator in_in_result<_IIter1, _IIter2>() const &
434 {
return {in1, in2}; }
436 template<
typename _IIter1,
typename _IIter2>
437 requires convertible_to<_Iter1, _IIter1>
438 && convertible_to<_Iter2, _IIter2>
440 operator in_in_result<_IIter1, _IIter2>() &&
444 template<
typename _Iter1,
typename _Iter2>
445 using mismatch_result = in_in_result<_Iter1, _Iter2>;
449 template<input_iterator _Iter1, sentinel_for<_Iter1> _Sent1,
450 input_iterator _Iter2, sentinel_for<_Iter2> _Sent2,
451 typename _Pred = ranges::equal_to,
452 typename _Proj1 =
identity,
typename _Proj2 =
identity>
453 requires indirectly_comparable<_Iter1, _Iter2, _Pred, _Proj1, _Proj2>
454 constexpr mismatch_result<_Iter1, _Iter2>
455 operator()(_Iter1 __first1, _Sent1 __last1,
456 _Iter2 __first2, _Sent2 __last2, _Pred __pred = {},
457 _Proj1 __proj1 = {}, _Proj2 __proj2 = {})
const
459 while (__first1 != __last1 && __first2 != __last2
470 template<input_range _Range1, input_range _Range2,
471 typename _Pred = ranges::equal_to,
472 typename _Proj1 = identity,
typename _Proj2 = identity>
473 requires indirectly_comparable<iterator_t<_Range1>, iterator_t<_Range2>,
474 _Pred, _Proj1, _Proj2>
475 constexpr mismatch_result<iterator_t<_Range1>, iterator_t<_Range2>>
476 operator()(_Range1&& __r1, _Range2&& __r2, _Pred __pred = {},
477 _Proj1 __proj1 = {}, _Proj2 __proj2 = {})
const
486 inline constexpr __mismatch_fn mismatch{};
490 template<forward_iterator _Iter1, sentinel_for<_Iter1> _Sent1,
491 forward_iterator _Iter2, sentinel_for<_Iter2> _Sent2,
492 typename _Pred = ranges::equal_to,
493 typename _Proj1 =
identity,
typename _Proj2 =
identity>
494 requires indirectly_comparable<_Iter1, _Iter2, _Pred, _Proj1, _Proj2>
495 constexpr subrange<_Iter1>
496 operator()(_Iter1 __first1, _Sent1 __last1,
497 _Iter2 __first2, _Sent2 __last2, _Pred __pred = {},
498 _Proj1 __proj1 = {}, _Proj2 __proj2 = {})
const
500 if (__first1 == __last1 || __first2 == __last2)
501 return {__first1, __first1};
507 if (__first1 == __last1)
508 return {__first1, __first1};
515 auto __cur1 = __first1;
516 auto __cur2 = __first2;
519 if (++__cur2 == __last2)
520 return {__first1, ++__cur1};
521 if (++__cur1 == __last1)
522 return {__cur1, __cur1};
534 template<forward_range _Range1, forward_range _Range2,
535 typename _Pred = ranges::equal_to,
536 typename _Proj1 = identity,
typename _Proj2 = identity>
537 requires indirectly_comparable<iterator_t<_Range1>, iterator_t<_Range2>,
538 _Pred, _Proj1, _Proj2>
539 constexpr borrowed_subrange_t<_Range1>
540 operator()(_Range1&& __r1, _Range2&& __r2, _Pred __pred = {},
541 _Proj1 __proj1 = {}, _Proj2 __proj2 = {})
const
550 inline constexpr __search_fn search{};
554 template<forward_iterator _Iter, sentinel_for<_Iter> _Sent,
typename _Tp,
555 typename _Pred = ranges::equal_to,
typename _Proj =
identity>
556 requires indirectly_comparable<_Iter, const _Tp*, _Pred, _Proj>
557 constexpr subrange<_Iter>
558 operator()(_Iter __first, _Sent __last, iter_difference_t<_Iter> __count,
559 const _Tp& __value, _Pred __pred = {}, _Proj __proj = {})
const
562 return {__first, __first};
564 auto __value_comp = [&] <
typename _Rp> (_Rp&& __arg) ->
bool {
565 return std::__invoke(__pred, std::forward<_Rp>(__arg), __value);
569 __first = ranges::find_if(
std::move(__first), __last,
572 if (__first == __last)
573 return {__first, __first};
576 auto __end = __first;
577 return {__first, ++__end};
581 if constexpr (sized_sentinel_for<_Sent, _Iter>
582 && random_access_iterator<_Iter>)
584 auto __tail_size = __last - __first;
585 auto __remainder = __count;
587 while (__remainder <= __tail_size)
589 __first += __remainder;
590 __tail_size -= __remainder;
591 auto __backtrack = __first;
594 if (--__remainder == 0)
595 return {__first - __count, __first};
597 __remainder = __count + 1 - (__first - __backtrack);
599 auto __i = __first + __tail_size;
604 __first = ranges::find_if(__first, __last, __value_comp, __proj);
605 while (__first != __last)
610 while (__i != __last && __n != 1
617 return {__first, __i};
620 __first = ranges::find_if(++__i, __last, __value_comp, __proj);
622 return {__first, __first};
626 template<forward_range _Range,
typename _Tp,
627 typename _Pred = ranges::equal_to,
typename _Proj = identity>
628 requires indirectly_comparable<iterator_t<_Range>,
const _Tp*,
630 constexpr borrowed_subrange_t<_Range>
631 operator()(_Range&& __r, range_difference_t<_Range> __count,
632 const _Tp& __value, _Pred __pred = {}, _Proj __proj = {})
const
640 inline constexpr __search_n_fn search_n{};
644 template<forward_iterator _Iter1, sentinel_for<_Iter1> _Sent1,
645 forward_iterator _Iter2, sentinel_for<_Iter2> _Sent2,
646 typename _Pred = ranges::equal_to,
647 typename _Proj1 =
identity,
typename _Proj2 =
identity>
648 requires indirectly_comparable<_Iter1, _Iter2, _Pred, _Proj1, _Proj2>
649 constexpr subrange<_Iter1>
650 operator()(_Iter1 __first1, _Sent1 __last1,
651 _Iter2 __first2, _Sent2 __last2, _Pred __pred = {},
652 _Proj1 __proj1 = {}, _Proj2 __proj2 = {})
const
654 if constexpr (bidirectional_iterator<_Iter1>
655 && bidirectional_iterator<_Iter2>)
657 auto __i1 = ranges::next(__first1, __last1);
658 auto __i2 = ranges::next(__first2, __last2);
660 = ranges::search(reverse_iterator<_Iter1>{__i1},
661 reverse_iterator<_Iter1>{__first1},
662 reverse_iterator<_Iter2>{__i2},
663 reverse_iterator<_Iter2>{__first2},
666 auto __result_first =
ranges::end(__rresult).base();
668 if (__result_last == __first1)
671 return {__result_first, __result_last};
675 auto __i = ranges::next(__first1, __last1);
676 if (__first2 == __last2)
679 auto __result_begin = __i;
680 auto __result_end = __i;
683 auto __new_range = ranges::search(__first1, __last1,
685 __pred, __proj1, __proj2);
688 if (__new_result_begin == __last1)
689 return {__result_begin, __result_end};
692 __result_begin = __new_result_begin;
693 __result_end = __new_result_end;
694 __first1 = __result_begin;
701 template<forward_range _Range1, forward_range _Range2,
702 typename _Pred = ranges::equal_to,
703 typename _Proj1 = identity,
typename _Proj2 = identity>
704 requires indirectly_comparable<iterator_t<_Range1>, iterator_t<_Range2>,
705 _Pred, _Proj1, _Proj2>
706 constexpr borrowed_subrange_t<_Range1>
707 operator()(_Range1&& __r1, _Range2&& __r2, _Pred __pred = {},
708 _Proj1 __proj1 = {}, _Proj2 __proj2 = {})
const
717 inline constexpr __find_end_fn find_end{};
719 struct __adjacent_find_fn
721 template<forward_iterator _Iter, sentinel_for<_Iter> _Sent,
722 typename _Proj =
identity,
723 indirect_binary_predicate<projected<_Iter, _Proj>,
724 projected<_Iter, _Proj>> _Pred
727 operator()(_Iter __first, _Sent __last,
728 _Pred __pred = {}, _Proj __proj = {})
const
730 if (__first == __last)
732 auto __next = __first;
733 for (; ++__next != __last; __first = __next)
743 template<forward_range _Range,
typename _Proj = identity,
744 indirect_binary_predicate<
745 projected<iterator_t<_Range>, _Proj>,
746 projected<iterator_t<_Range>, _Proj>> _Pred = ranges::equal_to>
747 constexpr borrowed_iterator_t<_Range>
748 operator()(_Range&& __r, _Pred __pred = {}, _Proj __proj = {})
const
755 inline constexpr __adjacent_find_fn adjacent_find{};
757 struct __is_permutation_fn
759 template<forward_iterator _Iter1, sentinel_for<_Iter1> _Sent1,
760 forward_iterator _Iter2, sentinel_for<_Iter2> _Sent2,
761 typename _Proj1 =
identity,
typename _Proj2 =
identity,
762 indirect_equivalence_relation<projected<_Iter1, _Proj1>,
763 projected<_Iter2, _Proj2>> _Pred
766 operator()(_Iter1 __first1, _Sent1 __last1,
767 _Iter2 __first2, _Sent2 __last2, _Pred __pred = {},
768 _Proj1 __proj1 = {}, _Proj2 __proj2 = {})
const
770 constexpr
bool __sized_iters
771 = (sized_sentinel_for<_Sent1, _Iter1>
772 && sized_sentinel_for<_Sent2, _Iter2>);
773 if constexpr (__sized_iters)
783 for (; __first1 != __last1 && __first2 != __last2;
784 ++__first1, (void)++__first2)
790 if constexpr (__sized_iters)
792 if (__first1 == __last1)
799 if (__d1 == 0 && __d2 == 0)
805 for (
auto __scan = __first1; __scan != __last1; ++__scan)
808 auto __comp_scan = [&] <
typename _Tp> (_Tp&& __arg) ->
bool {
810 std::forward<_Tp>(__arg));
812 if (__scan != ranges::find_if(__first1, __scan,
813 __comp_scan, __proj1))
816 auto __matches = ranges::count_if(__first2, __last2,
817 __comp_scan, __proj2);
819 || ranges::count_if(__scan, __last1,
820 __comp_scan, __proj1) != __matches)
826 template<forward_range _Range1, forward_range _Range2,
827 typename _Proj1 = identity,
typename _Proj2 = identity,
828 indirect_equivalence_relation<
829 projected<iterator_t<_Range1>, _Proj1>,
830 projected<iterator_t<_Range2>, _Proj2>> _Pred = ranges::equal_to>
832 operator()(_Range1&& __r1, _Range2&& __r2, _Pred __pred = {},
833 _Proj1 __proj1 = {}, _Proj2 __proj2 = {})
const
842 inline constexpr __is_permutation_fn is_permutation{};
844 template<
typename _Iter,
typename _Out>
845 using copy_if_result = in_out_result<_Iter, _Out>;
849 template<input_iterator _Iter, sentinel_for<_Iter> _Sent,
850 weakly_incrementable _Out,
typename _Proj =
identity,
851 indirect_unary_predicate<projected<_Iter, _Proj>> _Pred>
852 requires indirectly_copyable<_Iter, _Out>
853 constexpr copy_if_result<_Iter, _Out>
854 operator()(_Iter __first, _Sent __last, _Out __result,
855 _Pred __pred, _Proj __proj = {})
const
857 for (; __first != __last; ++__first)
860 *__result = *__first;
866 template<input_range _Range, weakly_incrementable _Out,
867 typename _Proj = identity,
868 indirect_unary_predicate<projected<iterator_t<_Range>, _Proj>>
870 requires indirectly_copyable<iterator_t<_Range>, _Out>
871 constexpr copy_if_result<borrowed_iterator_t<_Range>, _Out>
872 operator()(_Range&& __r, _Out __result,
873 _Pred __pred, _Proj __proj = {})
const
881 inline constexpr __copy_if_fn copy_if{};
883 template<
typename _Iter1,
typename _Iter2>
884 using swap_ranges_result = in_in_result<_Iter1, _Iter2>;
886 struct __swap_ranges_fn
888 template<input_iterator _Iter1, sentinel_for<_Iter1> _Sent1,
889 input_iterator _Iter2, sentinel_for<_Iter2> _Sent2>
890 requires indirectly_swappable<_Iter1, _Iter2>
891 constexpr swap_ranges_result<_Iter1, _Iter2>
892 operator()(_Iter1 __first1, _Sent1 __last1,
893 _Iter2 __first2, _Sent2 __last2)
const
895 for (; __first1 != __last1 && __first2 != __last2;
896 ++__first1, (void)++__first2)
897 ranges::iter_swap(__first1, __first2);
901 template<input_range _Range1, input_range _Range2>
902 requires indirectly_swappable<iterator_t<_Range1>, iterator_t<_Range2>>
903 constexpr swap_ranges_result<borrowed_iterator_t<_Range1>,
904 borrowed_iterator_t<_Range2>>
905 operator()(_Range1&& __r1, _Range2&& __r2)
const
912 inline constexpr __swap_ranges_fn swap_ranges{};
914 template<
typename _Iter,
typename _Out>
915 using unary_transform_result = in_out_result<_Iter, _Out>;
917 template<
typename _Iter1,
typename _Iter2,
typename _Out>
918 struct in_in_out_result
920 [[no_unique_address]] _Iter1 in1;
921 [[no_unique_address]] _Iter2 in2;
922 [[no_unique_address]] _Out out;
924 template<
typename _IIter1,
typename _IIter2,
typename _OOut>
925 requires convertible_to<const _Iter1&, _IIter1>
926 && convertible_to<const _Iter2&, _IIter2>
927 && convertible_to<const _Out&, _OOut>
929 operator in_in_out_result<_IIter1, _IIter2, _OOut>() const &
930 {
return {in1, in2, out}; }
932 template<
typename _IIter1,
typename _IIter2,
typename _OOut>
933 requires convertible_to<_Iter1, _IIter1>
934 && convertible_to<_Iter2, _IIter2>
935 && convertible_to<_Out, _OOut>
937 operator in_in_out_result<_IIter1, _IIter2, _OOut>() &&
941 template<
typename _Iter1,
typename _Iter2,
typename _Out>
942 using binary_transform_result = in_in_out_result<_Iter1, _Iter2, _Out>;
944 struct __transform_fn
946 template<input_iterator _Iter, sentinel_for<_Iter> _Sent,
947 weakly_incrementable _Out,
948 copy_constructible _Fp,
typename _Proj =
identity>
949 requires indirectly_writable<_Out,
950 indirect_result_t<_Fp&,
951 projected<_Iter, _Proj>>>
952 constexpr unary_transform_result<_Iter, _Out>
953 operator()(_Iter __first1, _Sent __last1, _Out __result,
954 _Fp __op, _Proj __proj = {})
const
956 for (; __first1 != __last1; ++__first1, (void)++__result)
961 template<input_range _Range, weakly_incrementable _Out,
962 copy_constructible _Fp,
typename _Proj = identity>
963 requires indirectly_writable<_Out,
964 indirect_result_t<_Fp&,
965 projected<iterator_t<_Range>, _Proj>>>
966 constexpr unary_transform_result<borrowed_iterator_t<_Range>, _Out>
967 operator()(_Range&& __r, _Out __result, _Fp __op, _Proj __proj = {})
const
974 template<input_iterator _Iter1, sentinel_for<_Iter1> _Sent1,
975 input_iterator _Iter2, sentinel_for<_Iter2> _Sent2,
976 weakly_incrementable _Out, copy_constructible _Fp,
977 typename _Proj1 =
identity,
typename _Proj2 =
identity>
978 requires indirectly_writable<_Out,
979 indirect_result_t<_Fp&,
980 projected<_Iter1, _Proj1>,
981 projected<_Iter2, _Proj2>>>
982 constexpr binary_transform_result<_Iter1, _Iter2, _Out>
983 operator()(_Iter1 __first1, _Sent1 __last1,
984 _Iter2 __first2, _Sent2 __last2,
985 _Out __result, _Fp __binary_op,
986 _Proj1 __proj1 = {}, _Proj2 __proj2 = {})
const
988 for (; __first1 != __last1 && __first2 != __last2;
989 ++__first1, (void)++__first2, ++__result)
996 template<input_range _Range1, input_range _Range2,
997 weakly_incrementable _Out, copy_constructible _Fp,
998 typename _Proj1 = identity,
typename _Proj2 = identity>
999 requires indirectly_writable<_Out,
1000 indirect_result_t<_Fp&,
1001 projected<iterator_t<_Range1>, _Proj1>,
1002 projected<iterator_t<_Range2>, _Proj2>>>
1003 constexpr binary_transform_result<borrowed_iterator_t<_Range1>,
1004 borrowed_iterator_t<_Range2>, _Out>
1005 operator()(_Range1&& __r1, _Range2&& __r2, _Out __result, _Fp __binary_op,
1006 _Proj1 __proj1 = {}, _Proj2 __proj2 = {})
const
1015 inline constexpr __transform_fn transform{};
1019 template<input_iterator _Iter, sentinel_for<_Iter> _Sent,
1020 typename _Tp1,
typename _Tp2,
typename _Proj =
identity>
1021 requires indirectly_writable<_Iter, const _Tp2&>
1022 && indirect_binary_predicate<ranges::equal_to, projected<_Iter, _Proj>,
1025 operator()(_Iter __first, _Sent __last,
1026 const _Tp1& __old_value,
const _Tp2& __new_value,
1027 _Proj __proj = {})
const
1029 for (; __first != __last; ++__first)
1031 *__first = __new_value;
1035 template<input_range _Range,
1036 typename _Tp1,
typename _Tp2,
typename _Proj = identity>
1037 requires indirectly_writable<iterator_t<_Range>,
const _Tp2&>
1038 && indirect_binary_predicate<ranges::equal_to,
1039 projected<iterator_t<_Range>, _Proj>,
1041 constexpr borrowed_iterator_t<_Range>
1042 operator()(_Range&& __r,
1043 const _Tp1& __old_value,
const _Tp2& __new_value,
1044 _Proj __proj = {})
const
1047 __old_value, __new_value,
std::move(__proj));
1051 inline constexpr __replace_fn replace{};
1053 struct __replace_if_fn
1055 template<input_iterator _Iter, sentinel_for<_Iter> _Sent,
1056 typename _Tp,
typename _Proj =
identity,
1057 indirect_unary_predicate<projected<_Iter, _Proj>> _Pred>
1058 requires indirectly_writable<_Iter, const _Tp&>
1060 operator()(_Iter __first, _Sent __last,
1061 _Pred __pred,
const _Tp& __new_value, _Proj __proj = {})
const
1063 for (; __first != __last; ++__first)
1065 *__first = __new_value;
1069 template<input_range _Range,
typename _Tp,
typename _Proj = identity,
1070 indirect_unary_predicate<projected<iterator_t<_Range>, _Proj>>
1072 requires indirectly_writable<iterator_t<_Range>,
const _Tp&>
1073 constexpr borrowed_iterator_t<_Range>
1074 operator()(_Range&& __r,
1075 _Pred __pred,
const _Tp& __new_value, _Proj __proj = {})
const
1082 inline constexpr __replace_if_fn replace_if{};
1084 template<
typename _Iter,
typename _Out>
1085 using replace_copy_result = in_out_result<_Iter, _Out>;
1087 struct __replace_copy_fn
1089 template<input_iterator _Iter, sentinel_for<_Iter> _Sent,
1090 typename _Tp1,
typename _Tp2, output_iterator<const _Tp2&> _Out,
1091 typename _Proj =
identity>
1092 requires indirectly_copyable<_Iter, _Out>
1093 && indirect_binary_predicate<ranges::equal_to,
1094 projected<_Iter, _Proj>,
const _Tp1*>
1095 constexpr replace_copy_result<_Iter, _Out>
1096 operator()(_Iter __first, _Sent __last, _Out __result,
1097 const _Tp1& __old_value,
const _Tp2& __new_value,
1098 _Proj __proj = {})
const
1100 for (; __first != __last; ++__first, (void)++__result)
1102 *__result = __new_value;
1104 *__result = *__first;
1108 template<input_range _Range,
typename _Tp1,
typename _Tp2,
1109 output_iterator<const _Tp2&> _Out,
typename _Proj = identity>
1110 requires indirectly_copyable<iterator_t<_Range>, _Out>
1111 && indirect_binary_predicate<ranges::equal_to,
1112 projected<iterator_t<_Range>, _Proj>,
1114 constexpr replace_copy_result<borrowed_iterator_t<_Range>, _Out>
1115 operator()(_Range&& __r, _Out __result,
1116 const _Tp1& __old_value,
const _Tp2& __new_value,
1117 _Proj __proj = {})
const
1125 inline constexpr __replace_copy_fn replace_copy{};
1127 template<
typename _Iter,
typename _Out>
1128 using replace_copy_if_result = in_out_result<_Iter, _Out>;
1130 struct __replace_copy_if_fn
1132 template<input_iterator _Iter, sentinel_for<_Iter> _Sent,
1133 typename _Tp, output_iterator<const _Tp&> _Out,
1134 typename _Proj =
identity,
1135 indirect_unary_predicate<projected<_Iter, _Proj>> _Pred>
1136 requires indirectly_copyable<_Iter, _Out>
1137 constexpr replace_copy_if_result<_Iter, _Out>
1138 operator()(_Iter __first, _Sent __last, _Out __result,
1139 _Pred __pred,
const _Tp& __new_value, _Proj __proj = {})
const
1141 for (; __first != __last; ++__first, (void)++__result)
1143 *__result = __new_value;
1145 *__result = *__first;
1149 template<input_range _Range,
1150 typename _Tp, output_iterator<const _Tp&> _Out,
1151 typename _Proj = identity,
1152 indirect_unary_predicate<projected<iterator_t<_Range>, _Proj>>
1154 requires indirectly_copyable<iterator_t<_Range>, _Out>
1155 constexpr replace_copy_if_result<borrowed_iterator_t<_Range>, _Out>
1156 operator()(_Range&& __r, _Out __result,
1157 _Pred __pred,
const _Tp& __new_value, _Proj __proj = {})
const
1165 inline constexpr __replace_copy_if_fn replace_copy_if{};
1167 struct __generate_n_fn
1169 template<input_or_output_iterator _Out, copy_constructible _Fp>
1170 requires invocable<_Fp&>
1171 && indirectly_writable<_Out, invoke_result_t<_Fp&>>
1173 operator()(_Out __first, iter_difference_t<_Out> __n, _Fp __gen)
const
1175 for (; __n > 0; --__n, (void)++__first)
1181 inline constexpr __generate_n_fn generate_n{};
1183 struct __generate_fn
1185 template<input_or_output_iterator _Out, sentinel_for<_Out> _Sent,
1186 copy_constructible _Fp>
1187 requires invocable<_Fp&>
1188 && indirectly_writable<_Out, invoke_result_t<_Fp&>>
1190 operator()(_Out __first, _Sent __last, _Fp __gen)
const
1192 for (; __first != __last; ++__first)
1197 template<
typename _Range, copy_constructible _Fp>
1198 requires invocable<_Fp&> && output_range<_Range, invoke_result_t<_Fp&>>
1199 constexpr borrowed_iterator_t<_Range>
1200 operator()(_Range&& __r, _Fp __gen)
const
1206 inline constexpr __generate_fn generate{};
1208 struct __remove_if_fn
1210 template<permutable _Iter, sentinel_for<_Iter> _Sent,
1211 typename _Proj =
identity,
1212 indirect_unary_predicate<projected<_Iter, _Proj>> _Pred>
1213 constexpr subrange<_Iter>
1214 operator()(_Iter __first, _Sent __last,
1215 _Pred __pred, _Proj __proj = {})
const
1217 __first = ranges::find_if(__first, __last, __pred, __proj);
1218 if (__first == __last)
1219 return {__first, __first};
1221 auto __result = __first;
1223 for (; __first != __last; ++__first)
1230 return {__result, __first};
1233 template<forward_range _Range,
typename _Proj = identity,
1234 indirect_unary_predicate<projected<iterator_t<_Range>, _Proj>>
1236 requires permutable<iterator_t<_Range>>
1237 constexpr borrowed_subrange_t<_Range>
1238 operator()(_Range&& __r, _Pred __pred, _Proj __proj = {})
const
1245 inline constexpr __remove_if_fn remove_if{};
1249 template<permutable _Iter, sentinel_for<_Iter> _Sent,
1250 typename _Tp,
typename _Proj =
identity>
1251 requires indirect_binary_predicate<ranges::equal_to,
1252 projected<_Iter, _Proj>,
1254 constexpr subrange<_Iter>
1255 operator()(_Iter __first, _Sent __last,
1256 const _Tp& __value, _Proj __proj = {})
const
1258 auto __pred = [&] (
auto&& __arg) ->
bool {
1259 return std::forward<decltype(__arg)>(__arg) == __value;
1261 return ranges::remove_if(__first, __last,
1265 template<forward_range _Range,
typename _Tp,
typename _Proj =
identity>
1266 requires permutable<iterator_t<_Range>>
1267 && indirect_binary_predicate<ranges::equal_to,
1268 projected<iterator_t<_Range>, _Proj>,
1270 constexpr borrowed_subrange_t<_Range>
1271 operator()(_Range&& __r,
const _Tp& __value, _Proj __proj = {})
const
1278 inline constexpr __remove_fn remove{};
1280 template<
typename _Iter,
typename _Out>
1281 using remove_copy_if_result = in_out_result<_Iter, _Out>;
1283 struct __remove_copy_if_fn
1285 template<input_iterator _Iter, sentinel_for<_Iter> _Sent,
1286 weakly_incrementable _Out,
typename _Proj =
identity,
1287 indirect_unary_predicate<projected<_Iter, _Proj>> _Pred>
1288 requires indirectly_copyable<_Iter, _Out>
1289 constexpr remove_copy_if_result<_Iter, _Out>
1290 operator()(_Iter __first, _Sent __last, _Out __result,
1291 _Pred __pred, _Proj __proj = {})
const
1293 for (; __first != __last; ++__first)
1296 *__result = *__first;
1302 template<input_range _Range, weakly_incrementable _Out,
1303 typename _Proj = identity,
1304 indirect_unary_predicate<projected<iterator_t<_Range>, _Proj>>
1306 requires indirectly_copyable<iterator_t<_Range>, _Out>
1307 constexpr remove_copy_if_result<borrowed_iterator_t<_Range>, _Out>
1308 operator()(_Range&& __r, _Out __result,
1309 _Pred __pred, _Proj __proj = {})
const
1317 inline constexpr __remove_copy_if_fn remove_copy_if{};
1319 template<
typename _Iter,
typename _Out>
1320 using remove_copy_result = in_out_result<_Iter, _Out>;
1322 struct __remove_copy_fn
1324 template<input_iterator _Iter, sentinel_for<_Iter> _Sent,
1325 weakly_incrementable _Out,
typename _Tp,
typename _Proj =
identity>
1326 requires indirectly_copyable<_Iter, _Out>
1327 && indirect_binary_predicate<ranges::equal_to,
1328 projected<_Iter, _Proj>,
1330 constexpr remove_copy_result<_Iter, _Out>
1331 operator()(_Iter __first, _Sent __last, _Out __result,
1332 const _Tp& __value, _Proj __proj = {})
const
1334 for (; __first != __last; ++__first)
1337 *__result = *__first;
1343 template<input_range _Range, weakly_incrementable _Out,
1344 typename _Tp,
typename _Proj = identity>
1345 requires indirectly_copyable<iterator_t<_Range>, _Out>
1346 && indirect_binary_predicate<ranges::equal_to,
1347 projected<iterator_t<_Range>, _Proj>,
1349 constexpr remove_copy_result<borrowed_iterator_t<_Range>, _Out>
1350 operator()(_Range&& __r, _Out __result,
1351 const _Tp& __value, _Proj __proj = {})
const
1358 inline constexpr __remove_copy_fn remove_copy{};
1362 template<permutable _Iter, sentinel_for<_Iter> _Sent,
1363 typename _Proj =
identity,
1364 indirect_equivalence_relation<
1365 projected<_Iter, _Proj>> _Comp = ranges::equal_to>
1366 constexpr subrange<_Iter>
1367 operator()(_Iter __first, _Sent __last,
1368 _Comp __comp = {}, _Proj __proj = {})
const
1370 __first = ranges::adjacent_find(__first, __last, __comp, __proj);
1371 if (__first == __last)
1372 return {__first, __first};
1374 auto __dest = __first;
1376 while (++__first != __last)
1381 return {++__dest, __first};
1384 template<forward_range _Range,
typename _Proj = identity,
1385 indirect_equivalence_relation<
1386 projected<iterator_t<_Range>, _Proj>> _Comp = ranges::equal_to>
1387 requires permutable<iterator_t<_Range>>
1388 constexpr borrowed_subrange_t<_Range>
1389 operator()(_Range&& __r, _Comp __comp = {}, _Proj __proj = {})
const
1396 inline constexpr __unique_fn unique{};
1400 template<
typename _Out,
typename _Tp>
1401 concept __can_reread_output = input_iterator<_Out>
1402 && same_as<_Tp, iter_value_t<_Out>>;
1405 template<
typename _Iter,
typename _Out>
1406 using unique_copy_result = in_out_result<_Iter, _Out>;
1408 struct __unique_copy_fn
1410 template<input_iterator _Iter, sentinel_for<_Iter> _Sent,
1411 weakly_incrementable _Out,
typename _Proj =
identity,
1412 indirect_equivalence_relation<
1413 projected<_Iter, _Proj>> _Comp = ranges::equal_to>
1414 requires indirectly_copyable<_Iter, _Out>
1415 && (forward_iterator<_Iter>
1416 || __detail::__can_reread_output<_Out, iter_value_t<_Iter>>
1417 || indirectly_copyable_storable<_Iter, _Out>)
1418 constexpr unique_copy_result<_Iter, _Out>
1419 operator()(_Iter __first, _Sent __last, _Out __result,
1420 _Comp __comp = {}, _Proj __proj = {})
const
1422 if (__first == __last)
1426 if constexpr (forward_iterator<_Iter>)
1428 auto __next = __first;
1429 *__result = *__next;
1430 while (++__next != __last)
1436 *++__result = *__first;
1440 else if constexpr (__detail::__can_reread_output<_Out, iter_value_t<_Iter>>)
1442 *__result = *__first;
1443 while (++__first != __last)
1447 *++__result = *__first;
1452 auto __value = *__first;
1453 *__result = __value;
1454 while (++__first != __last)
1461 *++__result = __value;
1468 template<input_range _Range,
1469 weakly_incrementable _Out,
typename _Proj = identity,
1470 indirect_equivalence_relation<
1471 projected<iterator_t<_Range>, _Proj>> _Comp = ranges::equal_to>
1472 requires indirectly_copyable<iterator_t<_Range>, _Out>
1473 && (forward_iterator<iterator_t<_Range>>
1474 || __detail::__can_reread_output<_Out, range_value_t<_Range>>
1475 || indirectly_copyable_storable<iterator_t<_Range>, _Out>)
1476 constexpr unique_copy_result<borrowed_iterator_t<_Range>, _Out>
1477 operator()(_Range&& __r, _Out __result,
1478 _Comp __comp = {}, _Proj __proj = {})
const
1486 inline constexpr __unique_copy_fn unique_copy{};
1490 template<b
idirectional_iterator _Iter, sentinel_for<_Iter> _Sent>
1491 requires permutable<_Iter>
1493 operator()(_Iter __first, _Sent __last)
const
1495 auto __i = ranges::next(__first, __last);
1498 if constexpr (random_access_iterator<_Iter>)
1500 if (__first != __last)
1503 while (__first < __tail)
1505 ranges::iter_swap(__first, __tail);
1515 if (__first == __tail || __first == --__tail)
1519 ranges::iter_swap(__first, __tail);
1526 template<b
idirectional_range _Range>
1527 requires permutable<iterator_t<_Range>>
1528 constexpr borrowed_iterator_t<_Range>
1529 operator()(_Range&& __r)
const
1535 inline constexpr __reverse_fn reverse{};
1537 template<
typename _Iter,
typename _Out>
1538 using reverse_copy_result = in_out_result<_Iter, _Out>;
1540 struct __reverse_copy_fn
1542 template<b
idirectional_iterator _Iter, sentinel_for<_Iter> _Sent,
1543 weakly_incrementable _Out>
1544 requires indirectly_copyable<_Iter, _Out>
1545 constexpr reverse_copy_result<_Iter, _Out>
1546 operator()(_Iter __first, _Sent __last, _Out __result)
const
1548 auto __i = ranges::next(__first, __last);
1550 while (__first != __tail)
1553 *__result = *__tail;
1559 template<b
idirectional_range _Range, weakly_incrementable _Out>
1560 requires indirectly_copyable<iterator_t<_Range>, _Out>
1561 constexpr reverse_copy_result<borrowed_iterator_t<_Range>, _Out>
1562 operator()(_Range&& __r, _Out __result)
const
1569 inline constexpr __reverse_copy_fn reverse_copy{};
1573 template<permutable _Iter, sentinel_for<_Iter> _Sent>
1574 constexpr subrange<_Iter>
1575 operator()(_Iter __first, _Iter __middle, _Sent __last)
const
1577 auto __lasti = ranges::next(__first, __last);
1578 if (__first == __middle)
1579 return {__lasti, __lasti};
1580 if (__last == __middle)
1583 if constexpr (random_access_iterator<_Iter>)
1585 auto __n = __lasti - __first;
1586 auto __k = __middle - __first;
1588 if (__k == __n - __k)
1590 ranges::swap_ranges(__first, __middle, __middle, __middle + __k);
1595 auto __ret = __first + (__lasti - __middle);
1599 if (__k < __n - __k)
1603 if constexpr (__is_pod(iter_value_t<_Iter>))
1611 auto __q = __p + __k;
1612 for (decltype(__n) __i = 0; __i < __n - __k; ++ __i)
1614 ranges::iter_swap(__p, __q);
1621 ranges::swap(__n, __k);
1629 if constexpr (__is_pod(iter_value_t<_Iter>))
1637 auto __q = __p + __n;
1639 for (decltype(__n) __i = 0; __i < __n - __k; ++ __i)
1643 ranges::iter_swap(__p, __q);
1648 std::swap(__n, __k);
1652 else if constexpr (bidirectional_iterator<_Iter>)
1654 auto __tail = __lasti;
1656 ranges::reverse(__first, __middle);
1657 ranges::reverse(__middle, __tail);
1659 while (__first != __middle && __middle != __tail)
1661 ranges::iter_swap(__first, --__tail);
1665 if (__first == __middle)
1667 ranges::reverse(__middle, __tail);
1672 ranges::reverse(__first, __middle);
1678 auto __first2 = __middle;
1681 ranges::iter_swap(__first, __first2);
1684 if (__first == __middle)
1685 __middle = __first2;
1686 }
while (__first2 != __last);
1688 auto __ret = __first;
1690 __first2 = __middle;
1692 while (__first2 != __last)
1694 ranges::iter_swap(__first, __first2);
1697 if (__first == __middle)
1698 __middle = __first2;
1699 else if (__first2 == __last)
1700 __first2 = __middle;
1706 template<forward_range _Range>
1707 requires permutable<iterator_t<_Range>>
1708 constexpr borrowed_subrange_t<_Range>
1709 operator()(_Range&& __r, iterator_t<_Range> __middle)
const
1716 inline constexpr __rotate_fn rotate{};
1718 template<
typename _Iter,
typename _Out>
1719 using rotate_copy_result = in_out_result<_Iter, _Out>;
1721 struct __rotate_copy_fn
1723 template<forward_iterator _Iter, sentinel_for<_Iter> _Sent,
1724 weakly_incrementable _Out>
1725 requires indirectly_copyable<_Iter, _Out>
1726 constexpr rotate_copy_result<_Iter, _Out>
1727 operator()(_Iter __first, _Iter __middle, _Sent __last,
1728 _Out __result)
const
1730 auto __copy1 = ranges::copy(__middle,
1733 auto __copy2 = ranges::copy(
std::move(__first),
1739 template<forward_range _Range, weakly_incrementable _Out>
1740 requires indirectly_copyable<iterator_t<_Range>, _Out>
1741 constexpr rotate_copy_result<borrowed_iterator_t<_Range>, _Out>
1742 operator()(_Range&& __r, iterator_t<_Range> __middle, _Out __result)
const
1749 inline constexpr __rotate_copy_fn rotate_copy{};
1753 template<input_iterator _Iter, sentinel_for<_Iter> _Sent,
1754 weakly_incrementable _Out,
typename _Gen>
1755 requires (forward_iterator<_Iter> || random_access_iterator<_Out>)
1756 && indirectly_copyable<_Iter, _Out>
1757 && uniform_random_bit_generator<remove_reference_t<_Gen>>
1759 operator()(_Iter __first, _Sent __last, _Out __out,
1760 iter_difference_t<_Iter> __n, _Gen&& __g)
const
1762 if constexpr (forward_iterator<_Iter>)
1766 auto __lasti = ranges::next(__first, __last);
1768 std::move(__out), __n, std::forward<_Gen>(__g));
1772 using __distrib_type
1773 = uniform_int_distribution<iter_difference_t<_Iter>>;
1774 using __param_type =
typename __distrib_type::param_type;
1775 __distrib_type __d{};
1776 iter_difference_t<_Iter> __sample_sz = 0;
1777 while (__first != __last && __sample_sz != __n)
1779 __out[__sample_sz++] = *__first;
1782 for (
auto __pop_sz = __sample_sz; __first != __last;
1783 ++__first, (void) ++__pop_sz)
1785 const auto __k = __d(__g, __param_type{0, __pop_sz});
1787 __out[__k] = *__first;
1789 return __out + __sample_sz;
1793 template<input_range _Range, weakly_incrementable _Out,
typename _Gen>
1794 requires (forward_range<_Range> || random_access_iterator<_Out>)
1795 && indirectly_copyable<iterator_t<_Range>, _Out>
1796 && uniform_random_bit_generator<remove_reference_t<_Gen>>
1798 operator()(_Range&& __r, _Out __out,
1799 range_difference_t<_Range> __n, _Gen&& __g)
const
1803 std::forward<_Gen>(__g));
1807 inline constexpr __sample_fn
sample{};
1809 #ifdef _GLIBCXX_USE_C99_STDINT_TR1
1812 template<random_access_iterator _Iter, sentinel_for<_Iter> _Sent,
1814 requires permutable<_Iter>
1815 && uniform_random_bit_generator<remove_reference_t<_Gen>>
1817 operator()(_Iter __first, _Sent __last, _Gen&& __g)
const
1819 auto __lasti = ranges::next(__first, __last);
1820 std::shuffle(
std::move(__first), __lasti, std::forward<_Gen>(__g));
1824 template<random_access_range _Range,
typename _Gen>
1825 requires permutable<iterator_t<_Range>>
1826 && uniform_random_bit_generator<remove_reference_t<_Gen>>
1827 borrowed_iterator_t<_Range>
1828 operator()(_Range&& __r, _Gen&& __g)
const
1831 std::forward<_Gen>(__g));
1835 inline constexpr __shuffle_fn shuffle{};
1838 struct __push_heap_fn
1840 template<random_access_iterator _Iter, sentinel_for<_Iter> _Sent,
1841 typename _Comp = ranges::less,
typename _Proj =
identity>
1842 requires sortable<_Iter, _Comp, _Proj>
1844 operator()(_Iter __first, _Sent __last,
1845 _Comp __comp = {}, _Proj __proj = {})
const
1847 auto __lasti = ranges::next(__first, __last);
1848 std::push_heap(__first, __lasti,
1849 __detail::__make_comp_proj(__comp, __proj));
1853 template<random_access_range _Range,
1854 typename _Comp = ranges::less,
typename _Proj = identity>
1855 requires sortable<iterator_t<_Range>, _Comp, _Proj>
1856 constexpr borrowed_iterator_t<_Range>
1857 operator()(_Range&& __r, _Comp __comp = {}, _Proj __proj = {})
const
1864 inline constexpr __push_heap_fn push_heap{};
1866 struct __pop_heap_fn
1868 template<random_access_iterator _Iter, sentinel_for<_Iter> _Sent,
1869 typename _Comp = ranges::less,
typename _Proj =
identity>
1870 requires sortable<_Iter, _Comp, _Proj>
1872 operator()(_Iter __first, _Sent __last,
1873 _Comp __comp = {}, _Proj __proj = {})
const
1875 auto __lasti = ranges::next(__first, __last);
1876 std::pop_heap(__first, __lasti,
1877 __detail::__make_comp_proj(__comp, __proj));
1881 template<random_access_range _Range,
1882 typename _Comp = ranges::less,
typename _Proj = identity>
1883 requires sortable<iterator_t<_Range>, _Comp, _Proj>
1884 constexpr borrowed_iterator_t<_Range>
1885 operator()(_Range&& __r, _Comp __comp = {}, _Proj __proj = {})
const
1892 inline constexpr __pop_heap_fn pop_heap{};
1894 struct __make_heap_fn
1896 template<random_access_iterator _Iter, sentinel_for<_Iter> _Sent,
1897 typename _Comp = ranges::less,
typename _Proj =
identity>
1898 requires sortable<_Iter, _Comp, _Proj>
1900 operator()(_Iter __first, _Sent __last,
1901 _Comp __comp = {}, _Proj __proj = {})
const
1903 auto __lasti = ranges::next(__first, __last);
1904 std::make_heap(__first, __lasti,
1905 __detail::__make_comp_proj(__comp, __proj));
1909 template<random_access_range _Range,
1910 typename _Comp = ranges::less,
typename _Proj = identity>
1911 requires sortable<iterator_t<_Range>, _Comp, _Proj>
1912 constexpr borrowed_iterator_t<_Range>
1913 operator()(_Range&& __r, _Comp __comp = {}, _Proj __proj = {})
const
1920 inline constexpr __make_heap_fn make_heap{};
1922 struct __sort_heap_fn
1924 template<random_access_iterator _Iter, sentinel_for<_Iter> _Sent,
1925 typename _Comp = ranges::less,
typename _Proj =
identity>
1926 requires sortable<_Iter, _Comp, _Proj>
1928 operator()(_Iter __first, _Sent __last,
1929 _Comp __comp = {}, _Proj __proj = {})
const
1931 auto __lasti = ranges::next(__first, __last);
1932 std::sort_heap(__first, __lasti,
1933 __detail::__make_comp_proj(__comp, __proj));
1937 template<random_access_range _Range,
1938 typename _Comp = ranges::less,
typename _Proj = identity>
1939 requires sortable<iterator_t<_Range>, _Comp, _Proj>
1940 constexpr borrowed_iterator_t<_Range>
1941 operator()(_Range&& __r, _Comp __comp = {}, _Proj __proj = {})
const
1948 inline constexpr __sort_heap_fn sort_heap{};
1950 struct __is_heap_until_fn
1952 template<random_access_iterator _Iter, sentinel_for<_Iter> _Sent,
1953 typename _Proj =
identity,
1954 indirect_strict_weak_order<projected<_Iter, _Proj>>
1955 _Comp = ranges::less>
1957 operator()(_Iter __first, _Sent __last,
1958 _Comp __comp = {}, _Proj __proj = {})
const
1961 iter_difference_t<_Iter> __parent = 0, __child = 1;
1962 for (; __child < __n; ++__child)
1966 return __first + __child;
1967 else if ((__child & 1) == 0)
1970 return __first + __n;
1973 template<random_access_range _Range,
1974 typename _Proj = identity,
1975 indirect_strict_weak_order<projected<iterator_t<_Range>, _Proj>>
1976 _Comp = ranges::less>
1977 constexpr borrowed_iterator_t<_Range>
1978 operator()(_Range&& __r, _Comp __comp = {}, _Proj __proj = {})
const
1985 inline constexpr __is_heap_until_fn is_heap_until{};
1989 template<random_access_iterator _Iter, sentinel_for<_Iter> _Sent,
1990 typename _Proj =
identity,
1991 indirect_strict_weak_order<projected<_Iter, _Proj>>
1992 _Comp = ranges::less>
1994 operator()(_Iter __first, _Sent __last,
1995 _Comp __comp = {}, _Proj __proj = {})
const
1998 == ranges::is_heap_until(__first, __last,
2003 template<random_access_range _Range,
2004 typename _Proj = identity,
2005 indirect_strict_weak_order<projected<iterator_t<_Range>, _Proj>>
2006 _Comp = ranges::less>
2008 operator()(_Range&& __r, _Comp __comp = {}, _Proj __proj = {})
const
2015 inline constexpr __is_heap_fn is_heap{};
2019 template<random_access_iterator _Iter, sentinel_for<_Iter> _Sent,
2020 typename _Comp = ranges::less,
typename _Proj =
identity>
2021 requires sortable<_Iter, _Comp, _Proj>
2023 operator()(_Iter __first, _Sent __last,
2024 _Comp __comp = {}, _Proj __proj = {})
const
2026 auto __lasti = ranges::next(__first, __last);
2028 __detail::__make_comp_proj(__comp, __proj));
2032 template<random_access_range _Range,
2033 typename _Comp = ranges::less,
typename _Proj = identity>
2034 requires sortable<iterator_t<_Range>, _Comp, _Proj>
2035 constexpr borrowed_iterator_t<_Range>
2036 operator()(_Range&& __r, _Comp __comp = {}, _Proj __proj = {})
const
2043 inline constexpr __sort_fn sort{};
2045 struct __stable_sort_fn
2047 template<random_access_iterator _Iter, sentinel_for<_Iter> _Sent,
2048 typename _Comp = ranges::less,
typename _Proj =
identity>
2049 requires sortable<_Iter, _Comp, _Proj>
2051 operator()(_Iter __first, _Sent __last,
2052 _Comp __comp = {}, _Proj __proj = {})
const
2054 auto __lasti = ranges::next(__first, __last);
2055 std::stable_sort(
std::move(__first), __lasti,
2056 __detail::__make_comp_proj(__comp, __proj));
2060 template<random_access_range _Range,
2061 typename _Comp = ranges::less,
typename _Proj = identity>
2062 requires sortable<iterator_t<_Range>, _Comp, _Proj>
2063 borrowed_iterator_t<_Range>
2064 operator()(_Range&& __r, _Comp __comp = {}, _Proj __proj = {})
const
2071 inline constexpr __stable_sort_fn stable_sort{};
2073 struct __partial_sort_fn
2075 template<random_access_iterator _Iter, sentinel_for<_Iter> _Sent,
2076 typename _Comp = ranges::less,
typename _Proj =
identity>
2077 requires sortable<_Iter, _Comp, _Proj>
2079 operator()(_Iter __first, _Iter __middle, _Sent __last,
2080 _Comp __comp = {}, _Proj __proj = {})
const
2082 if (__first == __middle)
2083 return ranges::next(__first, __last);
2085 ranges::make_heap(__first, __middle, __comp, __proj);
2086 auto __i = __middle;
2087 for (; __i != __last; ++__i)
2092 ranges::pop_heap(__first, __middle, __comp, __proj);
2093 ranges::iter_swap(__middle-1, __i);
2094 ranges::push_heap(__first, __middle, __comp, __proj);
2096 ranges::sort_heap(__first, __middle, __comp, __proj);
2101 template<random_access_range _Range,
2102 typename _Comp = ranges::less,
typename _Proj = identity>
2103 requires sortable<iterator_t<_Range>, _Comp, _Proj>
2104 constexpr borrowed_iterator_t<_Range>
2105 operator()(_Range&& __r, iterator_t<_Range> __middle,
2106 _Comp __comp = {}, _Proj __proj = {})
const
2114 inline constexpr __partial_sort_fn partial_sort{};
2116 template<
typename _Iter,
typename _Out>
2117 using partial_sort_copy_result = in_out_result<_Iter, _Out>;
2119 struct __partial_sort_copy_fn
2121 template<input_iterator _Iter1, sentinel_for<_Iter1> _Sent1,
2122 random_access_iterator _Iter2, sentinel_for<_Iter2> _Sent2,
2123 typename _Comp = ranges::less,
2124 typename _Proj1 =
identity,
typename _Proj2 =
identity>
2125 requires indirectly_copyable<_Iter1, _Iter2>
2126 && sortable<_Iter2, _Comp, _Proj2>
2127 && indirect_strict_weak_order<_Comp,
2128 projected<_Iter1, _Proj1>,
2129 projected<_Iter2, _Proj2>>
2130 constexpr partial_sort_copy_result<_Iter1, _Iter2>
2131 operator()(_Iter1 __first, _Sent1 __last,
2132 _Iter2 __result_first, _Sent2 __result_last,
2134 _Proj1 __proj1 = {}, _Proj2 __proj2 = {})
const
2136 if (__result_first == __result_last)
2139 auto __lasti = ranges::next(
std::move(__first),
2144 auto __result_real_last = __result_first;
2145 while (__first != __last && __result_real_last != __result_last)
2147 *__result_real_last = *__first;
2148 ++__result_real_last;
2152 ranges::make_heap(__result_first, __result_real_last, __comp, __proj2);
2153 for (; __first != __last; ++__first)
2158 ranges::pop_heap(__result_first, __result_real_last,
2160 *(__result_real_last-1) = *__first;
2161 ranges::push_heap(__result_first, __result_real_last,
2164 ranges::sort_heap(__result_first, __result_real_last, __comp, __proj2);
2169 template<input_range _Range1, random_access_range _Range2,
2170 typename _Comp = ranges::less,
2171 typename _Proj1 = identity,
typename _Proj2 = identity>
2172 requires indirectly_copyable<iterator_t<_Range1>, iterator_t<_Range2>>
2173 && sortable<iterator_t<_Range2>, _Comp, _Proj2>
2174 && indirect_strict_weak_order<_Comp,
2175 projected<iterator_t<_Range1>, _Proj1>,
2176 projected<iterator_t<_Range2>, _Proj2>>
2177 constexpr partial_sort_copy_result<borrowed_iterator_t<_Range1>,
2178 borrowed_iterator_t<_Range2>>
2179 operator()(_Range1&& __r, _Range2&& __out, _Comp __comp = {},
2180 _Proj1 __proj1 = {}, _Proj2 __proj2 = {})
const
2189 inline constexpr __partial_sort_copy_fn partial_sort_copy{};
2191 struct __is_sorted_until_fn
2193 template<forward_iterator _Iter, sentinel_for<_Iter> _Sent,
2194 typename _Proj =
identity,
2195 indirect_strict_weak_order<projected<_Iter, _Proj>>
2196 _Comp = ranges::less>
2198 operator()(_Iter __first, _Sent __last,
2199 _Comp __comp = {}, _Proj __proj = {})
const
2201 if (__first == __last)
2204 auto __next = __first;
2205 for (++__next; __next != __last; __first = __next, (void)++__next)
2213 template<forward_range _Range,
typename _Proj = identity,
2214 indirect_strict_weak_order<projected<iterator_t<_Range>, _Proj>>
2215 _Comp = ranges::less>
2216 constexpr borrowed_iterator_t<_Range>
2217 operator()(_Range&& __r, _Comp __comp = {}, _Proj __proj = {})
const
2224 inline constexpr __is_sorted_until_fn is_sorted_until{};
2226 struct __is_sorted_fn
2228 template<forward_iterator _Iter, sentinel_for<_Iter> _Sent,
2229 typename _Proj =
identity,
2230 indirect_strict_weak_order<projected<_Iter, _Proj>>
2231 _Comp = ranges::less>
2233 operator()(_Iter __first, _Sent __last,
2234 _Comp __comp = {}, _Proj __proj = {})
const
2236 if (__first == __last)
2239 auto __next = __first;
2240 for (++__next; __next != __last; __first = __next, (void)++__next)
2248 template<forward_range _Range,
typename _Proj = identity,
2249 indirect_strict_weak_order<projected<iterator_t<_Range>, _Proj>>
2250 _Comp = ranges::less>
2252 operator()(_Range&& __r, _Comp __comp = {}, _Proj __proj = {})
const
2259 inline constexpr __is_sorted_fn is_sorted{};
2261 struct __nth_element_fn
2263 template<random_access_iterator _Iter, sentinel_for<_Iter> _Sent,
2264 typename _Comp = ranges::less,
typename _Proj =
identity>
2265 requires sortable<_Iter, _Comp, _Proj>
2267 operator()(_Iter __first, _Iter __nth, _Sent __last,
2268 _Comp __comp = {}, _Proj __proj = {})
const
2270 auto __lasti = ranges::next(__first, __last);
2272 __detail::__make_comp_proj(__comp, __proj));
2276 template<random_access_range _Range,
2277 typename _Comp = ranges::less,
typename _Proj = identity>
2278 requires sortable<iterator_t<_Range>, _Comp, _Proj>
2279 constexpr borrowed_iterator_t<_Range>
2280 operator()(_Range&& __r, iterator_t<_Range> __nth,
2281 _Comp __comp = {}, _Proj __proj = {})
const
2288 inline constexpr __nth_element_fn nth_element{};
2290 struct __lower_bound_fn
2292 template<forward_iterator _Iter, sentinel_for<_Iter> _Sent,
2293 typename _Tp,
typename _Proj =
identity,
2294 indirect_strict_weak_order<const _Tp*, projected<_Iter, _Proj>>
2295 _Comp = ranges::less>
2297 operator()(_Iter __first, _Sent __last,
2298 const _Tp& __value, _Comp __comp = {}, _Proj __proj = {})
const
2304 auto __half = __len / 2;
2305 auto __middle = __first;
2311 __len = __len - __half - 1;
2319 template<forward_range _Range,
typename _Tp,
typename _Proj = identity,
2320 indirect_strict_weak_order<
const _Tp*,
2321 projected<iterator_t<_Range>, _Proj>>
2322 _Comp = ranges::less>
2323 constexpr borrowed_iterator_t<_Range>
2324 operator()(_Range&& __r,
2325 const _Tp& __value, _Comp __comp = {}, _Proj __proj = {})
const
2332 inline constexpr __lower_bound_fn lower_bound{};
2334 struct __upper_bound_fn
2336 template<forward_iterator _Iter, sentinel_for<_Iter> _Sent,
2337 typename _Tp,
typename _Proj =
identity,
2338 indirect_strict_weak_order<const _Tp*, projected<_Iter, _Proj>>
2339 _Comp = ranges::less>
2341 operator()(_Iter __first, _Sent __last,
2342 const _Tp& __value, _Comp __comp = {}, _Proj __proj = {})
const
2348 auto __half = __len / 2;
2349 auto __middle = __first;
2357 __len = __len - __half - 1;
2363 template<forward_range _Range,
typename _Tp,
typename _Proj = identity,
2364 indirect_strict_weak_order<
const _Tp*,
2365 projected<iterator_t<_Range>, _Proj>>
2366 _Comp = ranges::less>
2367 constexpr borrowed_iterator_t<_Range>
2368 operator()(_Range&& __r,
2369 const _Tp& __value, _Comp __comp = {}, _Proj __proj = {})
const
2376 inline constexpr __upper_bound_fn upper_bound{};
2378 struct __equal_range_fn
2380 template<forward_iterator _Iter, sentinel_for<_Iter> _Sent,
2381 typename _Tp,
typename _Proj =
identity,
2382 indirect_strict_weak_order<const _Tp*, projected<_Iter, _Proj>>
2383 _Comp = ranges::less>
2384 constexpr subrange<_Iter>
2385 operator()(_Iter __first, _Sent __last,
2386 const _Tp& __value, _Comp __comp = {}, _Proj __proj = {})
const
2392 auto __half = __len / 2;
2393 auto __middle = __first;
2401 __len = __len - __half - 1;
2410 = ranges::lower_bound(__first, __middle,
2411 __value, __comp, __proj);
2414 = ranges::upper_bound(++__middle, __first,
2415 __value, __comp, __proj);
2416 return {__left, __right};
2419 return {__first, __first};
2422 template<forward_range _Range,
2423 typename _Tp,
typename _Proj = identity,
2424 indirect_strict_weak_order<
const _Tp*,
2425 projected<iterator_t<_Range>, _Proj>>
2426 _Comp = ranges::less>
2427 constexpr borrowed_subrange_t<_Range>
2428 operator()(_Range&& __r,
const _Tp& __value,
2429 _Comp __comp = {}, _Proj __proj = {})
const
2436 inline constexpr __equal_range_fn equal_range{};
2438 struct __binary_search_fn
2440 template<forward_iterator _Iter, sentinel_for<_Iter> _Sent,
2441 typename _Tp,
typename _Proj =
identity,
2442 indirect_strict_weak_order<const _Tp*, projected<_Iter, _Proj>>
2443 _Comp = ranges::less>
2445 operator()(_Iter __first, _Sent __last,
2446 const _Tp& __value, _Comp __comp = {}, _Proj __proj = {})
const
2448 auto __i = ranges::lower_bound(__first, __last, __value, __comp, __proj);
2455 template<forward_range _Range,
2456 typename _Tp,
typename _Proj = identity,
2457 indirect_strict_weak_order<
const _Tp*,
2458 projected<iterator_t<_Range>, _Proj>>
2459 _Comp = ranges::less>
2461 operator()(_Range&& __r,
const _Tp& __value, _Comp __comp = {},
2462 _Proj __proj = {})
const
2469 inline constexpr __binary_search_fn binary_search{};
2471 struct __is_partitioned_fn
2473 template<input_iterator _Iter, sentinel_for<_Iter> _Sent,
2474 typename _Proj =
identity,
2475 indirect_unary_predicate<projected<_Iter, _Proj>> _Pred>
2477 operator()(_Iter __first, _Sent __last,
2478 _Pred __pred, _Proj __proj = {})
const
2480 __first = ranges::find_if_not(
std::move(__first), __last,
2482 if (__first == __last)
2489 template<input_range _Range,
typename _Proj = identity,
2490 indirect_unary_predicate<projected<iterator_t<_Range>, _Proj>>
2493 operator()(_Range&& __r, _Pred __pred, _Proj __proj = {})
const
2500 inline constexpr __is_partitioned_fn is_partitioned{};
2502 struct __partition_fn
2504 template<permutable _Iter, sentinel_for<_Iter> _Sent,
2505 typename _Proj =
identity,
2506 indirect_unary_predicate<projected<_Iter, _Proj>> _Pred>
2507 constexpr subrange<_Iter>
2508 operator()(_Iter __first, _Sent __last,
2509 _Pred __pred, _Proj __proj = {})
const
2511 if constexpr (bidirectional_iterator<_Iter>)
2513 auto __lasti = ranges::next(__first, __last);
2514 auto __tail = __lasti;
2518 if (__first == __tail)
2527 if (__first == __tail)
2534 ranges::iter_swap(__first, __tail);
2540 if (__first == __last)
2541 return {__first, __first};
2544 if (++__first == __last)
2545 return {__first, __first};
2547 auto __next = __first;
2548 while (++__next != __last)
2551 ranges::iter_swap(__first, __next);
2559 template<forward_range _Range,
typename _Proj = identity,
2560 indirect_unary_predicate<projected<iterator_t<_Range>, _Proj>>
2562 requires permutable<iterator_t<_Range>>
2563 constexpr borrowed_subrange_t<_Range>
2564 operator()(_Range&& __r, _Pred __pred, _Proj __proj = {})
const
2571 inline constexpr __partition_fn partition{};
2573 struct __stable_partition_fn
2575 template<b
idirectional_iterator _Iter, sentinel_for<_Iter> _Sent,
2576 typename _Proj =
identity,
2577 indirect_unary_predicate<projected<_Iter, _Proj>> _Pred>
2578 requires permutable<_Iter>
2580 operator()(_Iter __first, _Sent __last,
2581 _Pred __pred, _Proj __proj = {})
const
2583 auto __lasti = ranges::next(__first, __last);
2585 = std::stable_partition(
std::move(__first), __lasti,
2586 __detail::__make_pred_proj(__pred, __proj));
2590 template<bidirectional_range _Range,
typename _Proj = identity,
2591 indirect_unary_predicate<projected<iterator_t<_Range>, _Proj>>
2593 requires permutable<iterator_t<_Range>>
2594 borrowed_subrange_t<_Range>
2595 operator()(_Range&& __r, _Pred __pred, _Proj __proj = {})
const
2602 inline constexpr __stable_partition_fn stable_partition{};
2604 template<
typename _Iter,
typename _Out1,
typename _Out2>
2605 struct in_out_out_result
2607 [[no_unique_address]] _Iter in;
2608 [[no_unique_address]] _Out1 out1;
2609 [[no_unique_address]] _Out2 out2;
2611 template<
typename _IIter,
typename _OOut1,
typename _OOut2>
2612 requires convertible_to<const _Iter&, _IIter>
2613 && convertible_to<const _Out1&, _OOut1>
2614 && convertible_to<const _Out2&, _OOut2>
2616 operator in_out_out_result<_IIter, _OOut1, _OOut2>() const &
2617 {
return {in, out1, out2}; }
2619 template<
typename _IIter,
typename _OOut1,
typename _OOut2>
2620 requires convertible_to<_Iter, _IIter>
2621 && convertible_to<_Out1, _OOut1>
2622 && convertible_to<_Out2, _OOut2>
2624 operator in_out_out_result<_IIter, _OOut1, _OOut2>() &&
2628 template<
typename _Iter,
typename _Out1,
typename _Out2>
2629 using partition_copy_result = in_out_out_result<_Iter, _Out1, _Out2>;
2631 struct __partition_copy_fn
2633 template<input_iterator _Iter, sentinel_for<_Iter> _Sent,
2634 weakly_incrementable _Out1, weakly_incrementable _Out2,
2635 typename _Proj =
identity,
2636 indirect_unary_predicate<projected<_Iter, _Proj>> _Pred>
2637 requires indirectly_copyable<_Iter, _Out1>
2638 && indirectly_copyable<_Iter, _Out2>
2639 constexpr partition_copy_result<_Iter, _Out1, _Out2>
2640 operator()(_Iter __first, _Sent __last,
2641 _Out1 __out_true, _Out2 __out_false,
2642 _Pred __pred, _Proj __proj = {})
const
2644 for (; __first != __last; ++__first)
2647 *__out_true = *__first;
2652 *__out_false = *__first;
2660 template<input_range _Range, weakly_incrementable _Out1,
2661 weakly_incrementable _Out2,
2662 typename _Proj = identity,
2663 indirect_unary_predicate<projected<iterator_t<_Range>, _Proj>>
2665 requires indirectly_copyable<iterator_t<_Range>, _Out1>
2666 && indirectly_copyable<iterator_t<_Range>, _Out2>
2667 constexpr partition_copy_result<borrowed_iterator_t<_Range>, _Out1, _Out2>
2668 operator()(_Range&& __r, _Out1 __out_true, _Out2 __out_false,
2669 _Pred __pred, _Proj __proj = {})
const
2677 inline constexpr __partition_copy_fn partition_copy{};
2679 struct __partition_point_fn
2681 template<forward_iterator _Iter, sentinel_for<_Iter> _Sent,
2682 typename _Proj =
identity,
2683 indirect_unary_predicate<projected<_Iter, _Proj>> _Pred>
2685 operator()(_Iter __first, _Sent __last,
2686 _Pred __pred, _Proj __proj = {})
const
2692 auto __half = __len / 2;
2693 auto __middle = __first;
2699 __len = __len - __half - 1;
2707 template<forward_range _Range,
typename _Proj = identity,
2708 indirect_unary_predicate<projected<iterator_t<_Range>, _Proj>>
2710 constexpr borrowed_iterator_t<_Range>
2711 operator()(_Range&& __r, _Pred __pred, _Proj __proj = {})
const
2718 inline constexpr __partition_point_fn partition_point{};
2720 template<
typename _Iter1,
typename _Iter2,
typename _Out>
2721 using merge_result = in_in_out_result<_Iter1, _Iter2, _Out>;
2725 template<input_iterator _Iter1, sentinel_for<_Iter1> _Sent1,
2726 input_iterator _Iter2, sentinel_for<_Iter2> _Sent2,
2727 weakly_incrementable _Out,
typename _Comp = ranges::less,
2728 typename _Proj1 =
identity,
typename _Proj2 =
identity>
2729 requires mergeable<_Iter1, _Iter2, _Out, _Comp, _Proj1, _Proj2>
2730 constexpr merge_result<_Iter1, _Iter2, _Out>
2731 operator()(_Iter1 __first1, _Sent1 __last1,
2732 _Iter2 __first2, _Sent2 __last2, _Out __result,
2734 _Proj1 __proj1 = {}, _Proj2 __proj2 = {})
const
2736 while (__first1 != __last1 && __first2 != __last2)
2742 *__result = *__first2;
2747 *__result = *__first1;
2760 template<input_range _Range1, input_range _Range2, weakly_incrementable _Out,
2761 typename _Comp = ranges::less,
2762 typename _Proj1 = identity,
typename _Proj2 = identity>
2763 requires mergeable<iterator_t<_Range1>, iterator_t<_Range2>, _Out,
2764 _Comp, _Proj1, _Proj2>
2765 constexpr merge_result<borrowed_iterator_t<_Range1>,
2766 borrowed_iterator_t<_Range2>,
2768 operator()(_Range1&& __r1, _Range2&& __r2, _Out __result,
2770 _Proj1 __proj1 = {}, _Proj2 __proj2 = {})
const
2779 inline constexpr __merge_fn merge{};
2781 struct __inplace_merge_fn
2783 template<b
idirectional_iterator _Iter, sentinel_for<_Iter> _Sent,
2784 typename _Comp = ranges::less,
2785 typename _Proj =
identity>
2786 requires sortable<_Iter, _Comp, _Proj>
2788 operator()(_Iter __first, _Iter __middle, _Sent __last,
2789 _Comp __comp = {}, _Proj __proj = {})
const
2791 auto __lasti = ranges::next(__first, __last);
2793 __detail::__make_comp_proj(__comp, __proj));
2797 template<bidirectional_range _Range,
2798 typename _Comp = ranges::less,
typename _Proj = identity>
2799 requires sortable<iterator_t<_Range>, _Comp, _Proj>
2800 borrowed_iterator_t<_Range>
2801 operator()(_Range&& __r, iterator_t<_Range> __middle,
2802 _Comp __comp = {}, _Proj __proj = {})
const
2810 inline constexpr __inplace_merge_fn inplace_merge{};
2812 struct __includes_fn
2814 template<input_iterator _Iter1, sentinel_for<_Iter1> _Sent1,
2815 input_iterator _Iter2, sentinel_for<_Iter2> _Sent2,
2816 typename _Proj1 =
identity,
typename _Proj2 =
identity,
2817 indirect_strict_weak_order<projected<_Iter1, _Proj1>,
2818 projected<_Iter2, _Proj2>>
2819 _Comp = ranges::less>
2821 operator()(_Iter1 __first1, _Sent1 __last1,
2822 _Iter2 __first2, _Sent2 __last2,
2824 _Proj1 __proj1 = {}, _Proj2 __proj2 = {})
const
2826 while (__first1 != __last1 && __first2 != __last2)
2841 return __first2 == __last2;
2844 template<input_range _Range1, input_range _Range2,
2845 typename _Proj1 = identity,
typename _Proj2 = identity,
2846 indirect_strict_weak_order<projected<iterator_t<_Range1>, _Proj1>,
2847 projected<iterator_t<_Range2>, _Proj2>>
2848 _Comp = ranges::less>
2850 operator()(_Range1&& __r1, _Range2&& __r2, _Comp __comp = {},
2851 _Proj1 __proj1 = {}, _Proj2 __proj2 = {})
const
2860 inline constexpr __includes_fn includes{};
2862 template<
typename _Iter1,
typename _Iter2,
typename _Out>
2863 using set_union_result = in_in_out_result<_Iter1, _Iter2, _Out>;
2865 struct __set_union_fn
2867 template<input_iterator _Iter1, sentinel_for<_Iter1> _Sent1,
2868 input_iterator _Iter2, sentinel_for<_Iter2> _Sent2,
2869 weakly_incrementable _Out,
typename _Comp = ranges::less,
2870 typename _Proj1 =
identity,
typename _Proj2 =
identity>
2871 requires mergeable<_Iter1, _Iter2, _Out, _Comp, _Proj1, _Proj2>
2872 constexpr set_union_result<_Iter1, _Iter2, _Out>
2873 operator()(_Iter1 __first1, _Sent1 __last1,
2874 _Iter2 __first2, _Sent2 __last2,
2875 _Out __result, _Comp __comp = {},
2876 _Proj1 __proj1 = {}, _Proj2 __proj2 = {})
const
2878 while (__first1 != __last1 && __first2 != __last2)
2884 *__result = *__first1;
2891 *__result = *__first2;
2896 *__result = *__first1;
2910 template<input_range _Range1, input_range _Range2, weakly_incrementable _Out,
2911 typename _Comp = ranges::less,
2912 typename _Proj1 = identity,
typename _Proj2 = identity>
2913 requires mergeable<iterator_t<_Range1>, iterator_t<_Range2>, _Out,
2914 _Comp, _Proj1, _Proj2>
2915 constexpr set_union_result<borrowed_iterator_t<_Range1>,
2916 borrowed_iterator_t<_Range2>, _Out>
2917 operator()(_Range1&& __r1, _Range2&& __r2,
2918 _Out __result, _Comp __comp = {},
2919 _Proj1 __proj1 = {}, _Proj2 __proj2 = {})
const
2928 inline constexpr __set_union_fn set_union{};
2930 template<
typename _Iter1,
typename _Iter2,
typename _Out>
2931 using set_intersection_result = in_in_out_result<_Iter1, _Iter2, _Out>;
2933 struct __set_intersection_fn
2935 template<input_iterator _Iter1, sentinel_for<_Iter1> _Sent1,
2936 input_iterator _Iter2, sentinel_for<_Iter2> _Sent2,
2937 weakly_incrementable _Out,
typename _Comp = ranges::less,
2938 typename _Proj1 =
identity,
typename _Proj2 =
identity>
2939 requires mergeable<_Iter1, _Iter2, _Out, _Comp, _Proj1, _Proj2>
2940 constexpr set_intersection_result<_Iter1, _Iter2, _Out>
2941 operator()(_Iter1 __first1, _Sent1 __last1,
2942 _Iter2 __first2, _Sent2 __last2, _Out __result,
2944 _Proj1 __proj1 = {}, _Proj2 __proj2 = {})
const
2946 while (__first1 != __last1 && __first2 != __last2)
2957 *__result = *__first1;
2968 template<input_range _Range1, input_range _Range2, weakly_incrementable _Out,
2969 typename _Comp = ranges::less,
2970 typename _Proj1 = identity,
typename _Proj2 = identity>
2971 requires mergeable<iterator_t<_Range1>, iterator_t<_Range2>, _Out,
2972 _Comp, _Proj1, _Proj2>
2973 constexpr set_intersection_result<borrowed_iterator_t<_Range1>,
2974 borrowed_iterator_t<_Range2>, _Out>
2975 operator()(_Range1&& __r1, _Range2&& __r2, _Out __result,
2977 _Proj1 __proj1 = {}, _Proj2 __proj2 = {})
const
2986 inline constexpr __set_intersection_fn set_intersection{};
2988 template<
typename _Iter,
typename _Out>
2989 using set_difference_result = in_out_result<_Iter, _Out>;
2991 struct __set_difference_fn
2993 template<input_iterator _Iter1, sentinel_for<_Iter1> _Sent1,
2994 input_iterator _Iter2, sentinel_for<_Iter2> _Sent2,
2995 weakly_incrementable _Out,
typename _Comp = ranges::less,
2996 typename _Proj1 =
identity,
typename _Proj2 =
identity>
2997 requires mergeable<_Iter1, _Iter2, _Out, _Comp, _Proj1, _Proj2>
2998 constexpr set_difference_result<_Iter1, _Out>
2999 operator()(_Iter1 __first1, _Sent1 __last1,
3000 _Iter2 __first2, _Sent2 __last2, _Out __result,
3002 _Proj1 __proj1 = {}, _Proj2 __proj2 = {})
const
3004 while (__first1 != __last1 && __first2 != __last2)
3009 *__result = *__first1;
3026 template<input_range _Range1, input_range _Range2, weakly_incrementable _Out,
3027 typename _Comp = ranges::less,
3028 typename _Proj1 = identity,
typename _Proj2 = identity>
3029 requires mergeable<iterator_t<_Range1>, iterator_t<_Range2>, _Out,
3030 _Comp, _Proj1, _Proj2>
3031 constexpr set_difference_result<borrowed_iterator_t<_Range1>, _Out>
3032 operator()(_Range1&& __r1, _Range2&& __r2, _Out __result,
3034 _Proj1 __proj1 = {}, _Proj2 __proj2 = {})
const
3043 inline constexpr __set_difference_fn set_difference{};
3045 template<
typename _Iter1,
typename _Iter2,
typename _Out>
3046 using set_symmetric_difference_result
3047 = in_in_out_result<_Iter1, _Iter2, _Out>;
3049 struct __set_symmetric_difference_fn
3051 template<input_iterator _Iter1, sentinel_for<_Iter1> _Sent1,
3052 input_iterator _Iter2, sentinel_for<_Iter2> _Sent2,
3053 weakly_incrementable _Out,
typename _Comp = ranges::less,
3054 typename _Proj1 =
identity,
typename _Proj2 =
identity>
3055 requires mergeable<_Iter1, _Iter2, _Out, _Comp, _Proj1, _Proj2>
3056 constexpr set_symmetric_difference_result<_Iter1, _Iter2, _Out>
3057 operator()(_Iter1 __first1, _Sent1 __last1,
3058 _Iter2 __first2, _Sent2 __last2,
3059 _Out __result, _Comp __comp = {},
3060 _Proj1 __proj1 = {}, _Proj2 __proj2 = {})
const
3062 while (__first1 != __last1 && __first2 != __last2)
3067 *__result = *__first1;
3075 *__result = *__first2;
3092 template<input_range _Range1, input_range _Range2, weakly_incrementable _Out,
3093 typename _Comp = ranges::less,
3094 typename _Proj1 = identity,
typename _Proj2 = identity>
3095 requires mergeable<iterator_t<_Range1>, iterator_t<_Range2>, _Out,
3096 _Comp, _Proj1, _Proj2>
3097 constexpr set_symmetric_difference_result<borrowed_iterator_t<_Range1>,
3098 borrowed_iterator_t<_Range2>,
3100 operator()(_Range1&& __r1, _Range2&& __r2, _Out __result,
3102 _Proj1 __proj1 = {}, _Proj2 __proj2 = {})
const
3111 inline constexpr __set_symmetric_difference_fn set_symmetric_difference{};
3115 template<
typename _Tp,
typename _Proj = identity,
3116 indirect_strict_weak_order<projected<const _Tp*, _Proj>>
3117 _Comp = ranges::less>
3118 constexpr
const _Tp&
3119 operator()(
const _Tp& __a,
const _Tp& __b,
3120 _Comp __comp = {}, _Proj __proj = {})
const
3130 template<input_range _Range,
typename _Proj = identity,
3131 indirect_strict_weak_order<projected<iterator_t<_Range>, _Proj>>
3132 _Comp = ranges::less>
3133 requires indirectly_copyable_storable<iterator_t<_Range>,
3134 range_value_t<_Range>*>
3135 constexpr range_value_t<_Range>
3136 operator()(_Range&& __r, _Comp __comp = {}, _Proj __proj = {})
const
3140 __glibcxx_assert(__first != __last);
3141 auto __result = *__first;
3142 while (++__first != __last)
3144 auto __tmp = *__first;
3153 template<copyable _Tp,
typename _Proj = identity,
3154 indirect_strict_weak_order<projected<const _Tp*, _Proj>>
3155 _Comp = ranges::less>
3157 operator()(initializer_list<_Tp> __r,
3158 _Comp __comp = {}, _Proj __proj = {})
const
3160 return (*
this)(ranges::subrange(__r),
3165 inline constexpr __min_fn
min{};
3169 template<
typename _Tp,
typename _Proj = identity,
3170 indirect_strict_weak_order<projected<const _Tp*, _Proj>>
3171 _Comp = ranges::less>
3172 constexpr
const _Tp&
3173 operator()(
const _Tp& __a,
const _Tp& __b,
3174 _Comp __comp = {}, _Proj __proj = {})
const
3184 template<input_range _Range,
typename _Proj = identity,
3185 indirect_strict_weak_order<projected<iterator_t<_Range>, _Proj>>
3186 _Comp = ranges::less>
3187 requires indirectly_copyable_storable<iterator_t<_Range>,
3188 range_value_t<_Range>*>
3189 constexpr range_value_t<_Range>
3190 operator()(_Range&& __r, _Comp __comp = {}, _Proj __proj = {})
const
3194 __glibcxx_assert(__first != __last);
3195 auto __result = *__first;
3196 while (++__first != __last)
3198 auto __tmp = *__first;
3207 template<copyable _Tp,
typename _Proj = identity,
3208 indirect_strict_weak_order<projected<const _Tp*, _Proj>>
3209 _Comp = ranges::less>
3211 operator()(initializer_list<_Tp> __r,
3212 _Comp __comp = {}, _Proj __proj = {})
const
3214 return (*
this)(ranges::subrange(__r),
3219 inline constexpr __max_fn
max{};
3223 template<
typename _Tp,
typename _Proj = identity,
3224 indirect_strict_weak_order<projected<const _Tp*, _Proj>> _Comp
3226 constexpr
const _Tp&
3227 operator()(
const _Tp& __val,
const _Tp& __lo,
const _Tp& __hi,
3228 _Comp __comp = {}, _Proj __proj = {})
const
3243 inline constexpr __clamp_fn clamp{};
3245 template<
typename _Tp>
3246 struct min_max_result
3248 [[no_unique_address]] _Tp
min;
3249 [[no_unique_address]] _Tp
max;
3251 template<
typename _Tp2>
3252 requires convertible_to<const _Tp&, _Tp2>
3254 operator min_max_result<_Tp2>() const &
3257 template<
typename _Tp2>
3258 requires convertible_to<_Tp, _Tp2>
3260 operator min_max_result<_Tp2>() &&
3264 template<
typename _Tp>
3265 using minmax_result = min_max_result<_Tp>;
3269 template<
typename _Tp,
typename _Proj = identity,
3270 indirect_strict_weak_order<projected<const _Tp*, _Proj>>
3271 _Comp = ranges::less>
3272 constexpr minmax_result<const _Tp&>
3273 operator()(
const _Tp& __a,
const _Tp& __b,
3274 _Comp __comp = {}, _Proj __proj = {})
const
3284 template<input_range _Range,
typename _Proj = identity,
3285 indirect_strict_weak_order<projected<iterator_t<_Range>, _Proj>>
3286 _Comp = ranges::less>
3287 requires indirectly_copyable_storable<iterator_t<_Range>, range_value_t<_Range>*>
3288 constexpr minmax_result<range_value_t<_Range>>
3289 operator()(_Range&& __r, _Comp __comp = {}, _Proj __proj = {})
const
3293 __glibcxx_assert(__first != __last);
3294 auto __comp_proj = __detail::__make_comp_proj(__comp, __proj);
3295 minmax_result<range_value_t<_Range>> __result = {*__first, *__first};
3296 if (++__first == __last)
3302 auto&& __val = *__first;
3303 if (__comp_proj(__val, __result.min))
3304 __result.min = std::forward<decltype(__val)>(__val);
3306 __result.max = std::forward<decltype(__val)>(__val);
3308 while (++__first != __last)
3313 range_value_t<_Range> __val1 = *__first;
3314 if (++__first == __last)
3319 if (__comp_proj(__val1, __result.min))
3321 else if (!__comp_proj(__val1, __result.max))
3325 auto&& __val2 = *__first;
3326 if (!__comp_proj(__val2, __val1))
3328 if (__comp_proj(__val1, __result.min))
3330 if (!__comp_proj(__val2, __result.max))
3331 __result.max = std::forward<decltype(__val2)>(__val2);
3335 if (__comp_proj(__val2, __result.min))
3336 __result.min = std::forward<decltype(__val2)>(__val2);
3337 if (!__comp_proj(__val1, __result.max))
3344 template<copyable _Tp,
typename _Proj = identity,
3345 indirect_strict_weak_order<projected<const _Tp*, _Proj>>
3346 _Comp = ranges::less>
3347 constexpr minmax_result<_Tp>
3348 operator()(initializer_list<_Tp> __r,
3349 _Comp __comp = {}, _Proj __proj = {})
const
3351 return (*
this)(ranges::subrange(__r),
3356 inline constexpr __minmax_fn
minmax{};
3358 struct __min_element_fn
3360 template<forward_iterator _Iter, sentinel_for<_Iter> _Sent,
3361 typename _Proj =
identity,
3362 indirect_strict_weak_order<projected<_Iter, _Proj>>
3363 _Comp = ranges::less>
3365 operator()(_Iter __first, _Sent __last,
3366 _Comp __comp = {}, _Proj __proj = {})
const
3368 if (__first == __last)
3372 while (++__i != __last)
3382 template<forward_range _Range,
typename _Proj = identity,
3383 indirect_strict_weak_order<projected<iterator_t<_Range>, _Proj>>
3384 _Comp = ranges::less>
3385 constexpr borrowed_iterator_t<_Range>
3386 operator()(_Range&& __r, _Comp __comp = {}, _Proj __proj = {})
const
3393 inline constexpr __min_element_fn min_element{};
3395 struct __max_element_fn
3397 template<forward_iterator _Iter, sentinel_for<_Iter> _Sent,
3398 typename _Proj =
identity,
3399 indirect_strict_weak_order<projected<_Iter, _Proj>>
3400 _Comp = ranges::less>
3402 operator()(_Iter __first, _Sent __last,
3403 _Comp __comp = {}, _Proj __proj = {})
const
3405 if (__first == __last)
3409 while (++__i != __last)
3419 template<forward_range _Range,
typename _Proj = identity,
3420 indirect_strict_weak_order<projected<iterator_t<_Range>, _Proj>>
3421 _Comp = ranges::less>
3422 constexpr borrowed_iterator_t<_Range>
3423 operator()(_Range&& __r, _Comp __comp = {}, _Proj __proj = {})
const
3430 inline constexpr __max_element_fn max_element{};
3432 template<
typename _Iter>
3433 using minmax_element_result = min_max_result<_Iter>;
3435 struct __minmax_element_fn
3437 template<forward_iterator _Iter, sentinel_for<_Iter> _Sent,
3438 typename _Proj =
identity,
3439 indirect_strict_weak_order<projected<_Iter, _Proj>>
3440 _Comp = ranges::less>
3441 constexpr minmax_element_result<_Iter>
3442 operator()(_Iter __first, _Sent __last,
3443 _Comp __comp = {}, _Proj __proj = {})
const
3445 auto __comp_proj = __detail::__make_comp_proj(__comp, __proj);
3446 minmax_element_result<_Iter> __result = {__first, __first};
3447 if (__first == __last || ++__first == __last)
3453 if (__comp_proj(*__first, *__result.min))
3454 __result.min = __first;
3456 __result.max = __first;
3458 while (++__first != __last)
3463 auto __prev = __first;
3464 if (++__first == __last)
3469 if (__comp_proj(*__prev, *__result.min))
3470 __result.min = __prev;
3471 else if (!__comp_proj(*__prev, *__result.max))
3472 __result.max = __prev;
3475 if (!__comp_proj(*__first, *__prev))
3477 if (__comp_proj(*__prev, *__result.min))
3478 __result.min = __prev;
3479 if (!__comp_proj(*__first, *__result.max))
3480 __result.max = __first;
3484 if (__comp_proj(*__first, *__result.min))
3485 __result.min = __first;
3486 if (!__comp_proj(*__prev, *__result.max))
3487 __result.max = __prev;
3493 template<forward_range _Range,
typename _Proj = identity,
3494 indirect_strict_weak_order<projected<iterator_t<_Range>, _Proj>>
3495 _Comp = ranges::less>
3496 constexpr minmax_element_result<borrowed_iterator_t<_Range>>
3497 operator()(_Range&& __r, _Comp __comp = {}, _Proj __proj = {})
const
3504 inline constexpr __minmax_element_fn minmax_element{};
3506 struct __lexicographical_compare_fn
3508 template<input_iterator _Iter1, sentinel_for<_Iter1> _Sent1,
3509 input_iterator _Iter2, sentinel_for<_Iter2> _Sent2,
3510 typename _Proj1 =
identity,
typename _Proj2 =
identity,
3511 indirect_strict_weak_order<projected<_Iter1, _Proj1>,
3512 projected<_Iter2, _Proj2>>
3513 _Comp = ranges::less>
3515 operator()(_Iter1 __first1, _Sent1 __last1,
3516 _Iter2 __first2, _Sent2 __last2,
3518 _Proj1 __proj1 = {}, _Proj2 __proj2 = {})
const
3520 if constexpr (__detail::__is_normal_iterator<_Iter1>
3521 && same_as<_Iter1, _Sent1>)
3522 return (*
this)(__first1.base(), __last1.base(),
3526 else if constexpr (__detail::__is_normal_iterator<_Iter2>
3527 && same_as<_Iter2, _Sent2>)
3529 __first2.base(), __last2.base(),
3534 constexpr
bool __sized_iters
3535 = (sized_sentinel_for<_Sent1, _Iter1>
3536 && sized_sentinel_for<_Sent2, _Iter2>);
3537 if constexpr (__sized_iters)
3539 using _ValueType1 = iter_value_t<_Iter1>;
3540 using _ValueType2 = iter_value_t<_Iter2>;
3543 constexpr
bool __use_memcmp
3544 = (__is_memcmp_ordered_with<_ValueType1, _ValueType2>::__value
3545 && __ptr_to_nonvolatile<_Iter1>
3546 && __ptr_to_nonvolatile<_Iter2>
3547 && (is_same_v<_Comp, ranges::less>
3548 || is_same_v<_Comp, ranges::greater>)
3549 && is_same_v<_Proj1, identity>
3550 && is_same_v<_Proj2, identity>);
3551 if constexpr (__use_memcmp)
3553 const auto __d1 = __last1 - __first1;
3554 const auto __d2 = __last2 - __first2;
3556 if (
const auto __len =
std::min(__d1, __d2))
3559 = std::__memcmp(__first1, __first2, __len);
3560 if constexpr (is_same_v<_Comp, ranges::less>)
3567 else if constexpr (is_same_v<_Comp, ranges::greater>)
3579 for (; __first1 != __last1 && __first2 != __last2;
3580 ++__first1, (void) ++__first2)
3591 return __first1 == __last1 && __first2 != __last2;
3595 template<input_range _Range1, input_range _Range2,
3596 typename _Proj1 = identity,
typename _Proj2 = identity,
3597 indirect_strict_weak_order<projected<iterator_t<_Range1>, _Proj1>,
3598 projected<iterator_t<_Range2>, _Proj2>>
3599 _Comp = ranges::less>
3601 operator()(_Range1&& __r1, _Range2&& __r2, _Comp __comp = {},
3602 _Proj1 __proj1 = {}, _Proj2 __proj2 = {})
const
3611 template<
typename _Iter,
typename _Ref = iter_reference_t<_Iter>>
3612 static constexpr
bool __ptr_to_nonvolatile
3613 = is_pointer_v<_Iter> && !is_volatile_v<remove_reference_t<_Ref>>;
3616 inline constexpr __lexicographical_compare_fn lexicographical_compare;
3618 template<
typename _Iter>
3619 struct in_found_result
3621 [[no_unique_address]] _Iter in;
3624 template<
typename _Iter2>
3625 requires convertible_to<const _Iter&, _Iter2>
3627 operator in_found_result<_Iter2>() const &
3628 {
return {in, found}; }
3630 template<
typename _Iter2>
3631 requires convertible_to<_Iter, _Iter2>
3633 operator in_found_result<_Iter2>() &&
3637 template<
typename _Iter>
3638 using next_permutation_result = in_found_result<_Iter>;
3640 struct __next_permutation_fn
3642 template<b
idirectional_iterator _Iter, sentinel_for<_Iter> _Sent,
3643 typename _Comp = ranges::less,
typename _Proj =
identity>
3644 requires sortable<_Iter, _Comp, _Proj>
3645 constexpr next_permutation_result<_Iter>
3646 operator()(_Iter __first, _Sent __last,
3647 _Comp __comp = {}, _Proj __proj = {})
const
3649 if (__first == __last)
3657 auto __lasti = ranges::next(__first, __last);
3674 ranges::iter_swap(__i, __j);
3675 ranges::reverse(__ii, __last);
3680 ranges::reverse(__first, __last);
3686 template<bidirectional_range _Range,
typename _Comp = ranges::less,
3687 typename _Proj = identity>
3688 requires sortable<iterator_t<_Range>, _Comp, _Proj>
3689 constexpr next_permutation_result<borrowed_iterator_t<_Range>>
3690 operator()(_Range&& __r, _Comp __comp = {}, _Proj __proj = {})
const
3697 inline constexpr __next_permutation_fn next_permutation{};
3699 template<
typename _Iter>
3700 using prev_permutation_result = in_found_result<_Iter>;
3702 struct __prev_permutation_fn
3704 template<b
idirectional_iterator _Iter, sentinel_for<_Iter> _Sent,
3705 typename _Comp = ranges::less,
typename _Proj =
identity>
3706 requires sortable<_Iter, _Comp, _Proj>
3707 constexpr prev_permutation_result<_Iter>
3708 operator()(_Iter __first, _Sent __last,
3709 _Comp __comp = {}, _Proj __proj = {})
const
3711 if (__first == __last)
3719 auto __lasti = ranges::next(__first, __last);
3736 ranges::iter_swap(__i, __j);
3737 ranges::reverse(__ii, __last);
3742 ranges::reverse(__first, __last);
3748 template<bidirectional_range _Range,
typename _Comp = ranges::less,
3749 typename _Proj = identity>
3750 requires sortable<iterator_t<_Range>, _Comp, _Proj>
3751 constexpr prev_permutation_result<borrowed_iterator_t<_Range>>
3752 operator()(_Range&& __r, _Comp __comp = {}, _Proj __proj = {})
const
3759 inline constexpr __prev_permutation_fn prev_permutation{};
3763 #define __cpp_lib_shift 201806L
3764 template<
typename _ForwardIterator>
3765 constexpr _ForwardIterator
3766 shift_left(_ForwardIterator __first, _ForwardIterator __last,
3767 typename iterator_traits<_ForwardIterator>::difference_type __n)
3769 __glibcxx_assert(__n >= 0);
3773 auto __mid = ranges::next(__first, __n, __last);
3774 if (__mid == __last)
3779 template<
typename _ForwardIterator>
3780 constexpr _ForwardIterator
3781 shift_right(_ForwardIterator __first, _ForwardIterator __last,
3782 typename iterator_traits<_ForwardIterator>::difference_type __n)
3784 __glibcxx_assert(__n >= 0);
3789 =
typename iterator_traits<_ForwardIterator>::iterator_category;
3790 if constexpr (derived_from<_Cat, bidirectional_iterator_tag>)
3792 auto __mid = ranges::next(__last, -__n, __first);
3793 if (__mid == __first)
3801 auto __result = ranges::next(__first, __n, __last);
3802 if (__result == __last)
3805 auto __dest_head = __first, __dest_tail = __result;
3806 while (__dest_head != __result)
3808 if (__dest_tail == __last)
3832 auto __cursor = __first;
3833 while (__cursor != __result)
3835 if (__dest_tail == __last)
3840 __dest_head =
std::move(__cursor, __result,
3846 std::iter_swap(__cursor, __dest_head);
3855 _GLIBCXX_END_NAMESPACE_VERSION
constexpr __invoke_result< _Callable, _Args... >::type __invoke(_Callable &&__fn, _Args &&... __args) noexcept(__is_nothrow_invocable< _Callable, _Args... >::value)
Invoke a callable object.
constexpr std::remove_reference< _Tp >::type && move(_Tp &&__t) noexcept
Convert a value to an rvalue.
_Tp * end(valarray< _Tp > &__va) noexcept
Return an iterator pointing to one past the last element of the valarray.
_Tp * begin(valarray< _Tp > &__va) noexcept
Return an iterator pointing to the first element of the valarray.
constexpr _BI2 move_backward(_BI1 __first, _BI1 __last, _BI2 __result)
Moves the range [first,last) into result.
constexpr const _Tp & max(const _Tp &, const _Tp &)
This does what you think it does.
constexpr pair< const _Tp &, const _Tp & > minmax(const _Tp &, const _Tp &)
Determines min and max at once as an ordered pair.
constexpr const _Tp & min(const _Tp &, const _Tp &)
This does what you think it does.
ISO C++ entities toplevel namespace is std.
constexpr iterator_traits< _InputIterator >::difference_type distance(_InputIterator __first, _InputIterator __last)
A generalization of pointer arithmetic.
constexpr void advance(_InputIterator &__i, _Distance __n)
A generalization of pointer arithmetic.
_SampleIterator sample(_PopulationIterator __first, _PopulationIterator __last, _SampleIterator __out, _Distance __n, _UniformRandomNumberGenerator &&__g)
Take a random sample from a population.