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) {
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>)
583 auto __tail_size = __last - __first;
584 auto __remainder = __count;
586 while (__remainder <= __tail_size)
588 __first += __remainder;
589 __tail_size -= __remainder;
590 auto __backtrack = __first;
593 if (--__remainder == 0)
594 return {__first - __count, __first};
597 auto __i = __first + __tail_size;
602 __first = ranges::find_if(__first, __last, __value_comp, __proj);
603 while (__first != __last)
608 while (__i != __last && __n != 1
615 return {__first, __i};
618 __first = ranges::find_if(++__i, __last, __value_comp, __proj);
620 return {__first, __first};
624 template<forward_range _Range,
typename _Tp,
625 typename _Pred = ranges::equal_to,
typename _Proj = identity>
626 requires indirectly_comparable<iterator_t<_Range>,
const _Tp*,
628 constexpr borrowed_subrange_t<_Range>
629 operator()(_Range&& __r, range_difference_t<_Range> __count,
630 const _Tp& __value, _Pred __pred = {}, _Proj __proj = {})
const
638 inline constexpr __search_n_fn search_n{};
642 template<forward_iterator _Iter1, sentinel_for<_Iter1> _Sent1,
643 forward_iterator _Iter2, sentinel_for<_Iter2> _Sent2,
644 typename _Pred = ranges::equal_to,
645 typename _Proj1 =
identity,
typename _Proj2 =
identity>
646 requires indirectly_comparable<_Iter1, _Iter2, _Pred, _Proj1, _Proj2>
647 constexpr subrange<_Iter1>
648 operator()(_Iter1 __first1, _Sent1 __last1,
649 _Iter2 __first2, _Sent2 __last2, _Pred __pred = {},
650 _Proj1 __proj1 = {}, _Proj2 __proj2 = {})
const
652 if constexpr (bidirectional_iterator<_Iter1>
653 && bidirectional_iterator<_Iter2>)
655 auto __i1 = ranges::next(__first1, __last1);
656 auto __i2 = ranges::next(__first2, __last2);
658 = ranges::search(reverse_iterator<_Iter1>{__i1},
659 reverse_iterator<_Iter1>{__first1},
660 reverse_iterator<_Iter2>{__i2},
661 reverse_iterator<_Iter2>{__first2},
664 auto __result_first =
ranges::end(__rresult).base();
666 if (__result_last == __first1)
669 return {__result_first, __result_last};
673 auto __i = ranges::next(__first1, __last1);
674 if (__first2 == __last2)
677 auto __result_begin = __i;
678 auto __result_end = __i;
681 auto __new_range = ranges::search(__first1, __last1,
683 __pred, __proj1, __proj2);
686 if (__new_result_begin == __last1)
687 return {__result_begin, __result_end};
690 __result_begin = __new_result_begin;
691 __result_end = __new_result_end;
692 __first1 = __result_begin;
699 template<forward_range _Range1, forward_range _Range2,
700 typename _Pred = ranges::equal_to,
701 typename _Proj1 = identity,
typename _Proj2 = identity>
702 requires indirectly_comparable<iterator_t<_Range1>, iterator_t<_Range2>,
703 _Pred, _Proj1, _Proj2>
704 constexpr borrowed_subrange_t<_Range1>
705 operator()(_Range1&& __r1, _Range2&& __r2, _Pred __pred = {},
706 _Proj1 __proj1 = {}, _Proj2 __proj2 = {})
const
715 inline constexpr __find_end_fn find_end{};
717 struct __adjacent_find_fn
719 template<forward_iterator _Iter, sentinel_for<_Iter> _Sent,
720 typename _Proj =
identity,
721 indirect_binary_predicate<projected<_Iter, _Proj>,
722 projected<_Iter, _Proj>> _Pred
725 operator()(_Iter __first, _Sent __last,
726 _Pred __pred = {}, _Proj __proj = {})
const
728 if (__first == __last)
730 auto __next = __first;
731 for (; ++__next != __last; __first = __next)
741 template<forward_range _Range,
typename _Proj = identity,
742 indirect_binary_predicate<
743 projected<iterator_t<_Range>, _Proj>,
744 projected<iterator_t<_Range>, _Proj>> _Pred = ranges::equal_to>
745 constexpr borrowed_iterator_t<_Range>
746 operator()(_Range&& __r, _Pred __pred = {}, _Proj __proj = {})
const
753 inline constexpr __adjacent_find_fn adjacent_find{};
755 struct __is_permutation_fn
757 template<forward_iterator _Iter1, sentinel_for<_Iter1> _Sent1,
758 forward_iterator _Iter2, sentinel_for<_Iter2> _Sent2,
759 typename _Proj1 =
identity,
typename _Proj2 =
identity,
760 indirect_equivalence_relation<projected<_Iter1, _Proj1>,
761 projected<_Iter2, _Proj2>> _Pred
764 operator()(_Iter1 __first1, _Sent1 __last1,
765 _Iter2 __first2, _Sent2 __last2, _Pred __pred = {},
766 _Proj1 __proj1 = {}, _Proj2 __proj2 = {})
const
768 constexpr
bool __sized_iters
769 = (sized_sentinel_for<_Sent1, _Iter1>
770 && sized_sentinel_for<_Sent2, _Iter2>);
771 if constexpr (__sized_iters)
781 for (; __first1 != __last1 && __first2 != __last2;
782 ++__first1, (void)++__first2)
788 if constexpr (__sized_iters)
790 if (__first1 == __last1)
797 if (__d1 == 0 && __d2 == 0)
803 for (
auto __scan = __first1; __scan != __last1; ++__scan)
806 auto __comp_scan = [&] <
typename _Tp> (_Tp&& __arg) {
808 std::forward<_Tp>(__arg));
810 if (__scan != ranges::find_if(__first1, __scan,
811 __comp_scan, __proj1))
814 auto __matches = ranges::count_if(__first2, __last2,
815 __comp_scan, __proj2);
817 || ranges::count_if(__scan, __last1,
818 __comp_scan, __proj1) != __matches)
824 template<forward_range _Range1, forward_range _Range2,
825 typename _Proj1 = identity,
typename _Proj2 = identity,
826 indirect_equivalence_relation<
827 projected<iterator_t<_Range1>, _Proj1>,
828 projected<iterator_t<_Range2>, _Proj2>> _Pred = ranges::equal_to>
830 operator()(_Range1&& __r1, _Range2&& __r2, _Pred __pred = {},
831 _Proj1 __proj1 = {}, _Proj2 __proj2 = {})
const
840 inline constexpr __is_permutation_fn is_permutation{};
842 template<
typename _Iter,
typename _Out>
843 using copy_if_result = in_out_result<_Iter, _Out>;
847 template<input_iterator _Iter, sentinel_for<_Iter> _Sent,
848 weakly_incrementable _Out,
typename _Proj =
identity,
849 indirect_unary_predicate<projected<_Iter, _Proj>> _Pred>
850 requires indirectly_copyable<_Iter, _Out>
851 constexpr copy_if_result<_Iter, _Out>
852 operator()(_Iter __first, _Sent __last, _Out __result,
853 _Pred __pred, _Proj __proj = {})
const
855 for (; __first != __last; ++__first)
858 *__result = *__first;
864 template<input_range _Range, weakly_incrementable _Out,
865 typename _Proj = identity,
866 indirect_unary_predicate<projected<iterator_t<_Range>, _Proj>>
868 requires indirectly_copyable<iterator_t<_Range>, _Out>
869 constexpr copy_if_result<borrowed_iterator_t<_Range>, _Out>
870 operator()(_Range&& __r, _Out __result,
871 _Pred __pred, _Proj __proj = {})
const
879 inline constexpr __copy_if_fn copy_if{};
881 template<
typename _Iter1,
typename _Iter2>
882 using swap_ranges_result = in_in_result<_Iter1, _Iter2>;
884 struct __swap_ranges_fn
886 template<input_iterator _Iter1, sentinel_for<_Iter1> _Sent1,
887 input_iterator _Iter2, sentinel_for<_Iter2> _Sent2>
888 requires indirectly_swappable<_Iter1, _Iter2>
889 constexpr swap_ranges_result<_Iter1, _Iter2>
890 operator()(_Iter1 __first1, _Sent1 __last1,
891 _Iter2 __first2, _Sent2 __last2)
const
893 for (; __first1 != __last1 && __first2 != __last2;
894 ++__first1, (void)++__first2)
895 ranges::iter_swap(__first1, __first2);
899 template<input_range _Range1, input_range _Range2>
900 requires indirectly_swappable<iterator_t<_Range1>, iterator_t<_Range2>>
901 constexpr swap_ranges_result<borrowed_iterator_t<_Range1>,
902 borrowed_iterator_t<_Range2>>
903 operator()(_Range1&& __r1, _Range2&& __r2)
const
910 inline constexpr __swap_ranges_fn swap_ranges{};
912 template<
typename _Iter,
typename _Out>
913 using unary_transform_result = in_out_result<_Iter, _Out>;
915 template<
typename _Iter1,
typename _Iter2,
typename _Out>
916 struct in_in_out_result
918 [[no_unique_address]] _Iter1 in1;
919 [[no_unique_address]] _Iter2 in2;
920 [[no_unique_address]] _Out out;
922 template<
typename _IIter1,
typename _IIter2,
typename _OOut>
923 requires convertible_to<const _Iter1&, _IIter1>
924 && convertible_to<const _Iter2&, _IIter2>
925 && convertible_to<const _Out&, _OOut>
927 operator in_in_out_result<_IIter1, _IIter2, _OOut>() const &
928 {
return {in1, in2, out}; }
930 template<
typename _IIter1,
typename _IIter2,
typename _OOut>
931 requires convertible_to<_Iter1, _IIter1>
932 && convertible_to<_Iter2, _IIter2>
933 && convertible_to<_Out, _OOut>
935 operator in_in_out_result<_IIter1, _IIter2, _OOut>() &&
939 template<
typename _Iter1,
typename _Iter2,
typename _Out>
940 using binary_transform_result = in_in_out_result<_Iter1, _Iter2, _Out>;
942 struct __transform_fn
944 template<input_iterator _Iter, sentinel_for<_Iter> _Sent,
945 weakly_incrementable _Out,
946 copy_constructible _Fp,
typename _Proj =
identity>
947 requires indirectly_writable<_Out,
948 indirect_result_t<_Fp&,
949 projected<_Iter, _Proj>>>
950 constexpr unary_transform_result<_Iter, _Out>
951 operator()(_Iter __first1, _Sent __last1, _Out __result,
952 _Fp __op, _Proj __proj = {})
const
954 for (; __first1 != __last1; ++__first1, (void)++__result)
959 template<input_range _Range, weakly_incrementable _Out,
960 copy_constructible _Fp,
typename _Proj = identity>
961 requires indirectly_writable<_Out,
962 indirect_result_t<_Fp&,
963 projected<iterator_t<_Range>, _Proj>>>
964 constexpr unary_transform_result<borrowed_iterator_t<_Range>, _Out>
965 operator()(_Range&& __r, _Out __result, _Fp __op, _Proj __proj = {})
const
972 template<input_iterator _Iter1, sentinel_for<_Iter1> _Sent1,
973 input_iterator _Iter2, sentinel_for<_Iter2> _Sent2,
974 weakly_incrementable _Out, copy_constructible _Fp,
975 typename _Proj1 =
identity,
typename _Proj2 =
identity>
976 requires indirectly_writable<_Out,
977 indirect_result_t<_Fp&,
978 projected<_Iter1, _Proj1>,
979 projected<_Iter2, _Proj2>>>
980 constexpr binary_transform_result<_Iter1, _Iter2, _Out>
981 operator()(_Iter1 __first1, _Sent1 __last1,
982 _Iter2 __first2, _Sent2 __last2,
983 _Out __result, _Fp __binary_op,
984 _Proj1 __proj1 = {}, _Proj2 __proj2 = {})
const
986 for (; __first1 != __last1 && __first2 != __last2;
987 ++__first1, (void)++__first2, ++__result)
994 template<input_range _Range1, input_range _Range2,
995 weakly_incrementable _Out, copy_constructible _Fp,
996 typename _Proj1 = identity,
typename _Proj2 = identity>
997 requires indirectly_writable<_Out,
998 indirect_result_t<_Fp&,
999 projected<iterator_t<_Range1>, _Proj1>,
1000 projected<iterator_t<_Range2>, _Proj2>>>
1001 constexpr binary_transform_result<borrowed_iterator_t<_Range1>,
1002 borrowed_iterator_t<_Range2>, _Out>
1003 operator()(_Range1&& __r1, _Range2&& __r2, _Out __result, _Fp __binary_op,
1004 _Proj1 __proj1 = {}, _Proj2 __proj2 = {})
const
1013 inline constexpr __transform_fn transform{};
1017 template<input_iterator _Iter, sentinel_for<_Iter> _Sent,
1018 typename _Tp1,
typename _Tp2,
typename _Proj =
identity>
1019 requires indirectly_writable<_Iter, const _Tp2&>
1020 && indirect_binary_predicate<ranges::equal_to, projected<_Iter, _Proj>,
1023 operator()(_Iter __first, _Sent __last,
1024 const _Tp1& __old_value,
const _Tp2& __new_value,
1025 _Proj __proj = {})
const
1027 for (; __first != __last; ++__first)
1029 *__first = __new_value;
1033 template<input_range _Range,
1034 typename _Tp1,
typename _Tp2,
typename _Proj = identity>
1035 requires indirectly_writable<iterator_t<_Range>,
const _Tp2&>
1036 && indirect_binary_predicate<ranges::equal_to,
1037 projected<iterator_t<_Range>, _Proj>,
1039 constexpr borrowed_iterator_t<_Range>
1040 operator()(_Range&& __r,
1041 const _Tp1& __old_value,
const _Tp2& __new_value,
1042 _Proj __proj = {})
const
1045 __old_value, __new_value,
std::move(__proj));
1049 inline constexpr __replace_fn replace{};
1051 struct __replace_if_fn
1053 template<input_iterator _Iter, sentinel_for<_Iter> _Sent,
1054 typename _Tp,
typename _Proj =
identity,
1055 indirect_unary_predicate<projected<_Iter, _Proj>> _Pred>
1056 requires indirectly_writable<_Iter, const _Tp&>
1058 operator()(_Iter __first, _Sent __last,
1059 _Pred __pred,
const _Tp& __new_value, _Proj __proj = {})
const
1061 for (; __first != __last; ++__first)
1063 *__first = __new_value;
1067 template<input_range _Range,
typename _Tp,
typename _Proj = identity,
1068 indirect_unary_predicate<projected<iterator_t<_Range>, _Proj>>
1070 requires indirectly_writable<iterator_t<_Range>,
const _Tp&>
1071 constexpr borrowed_iterator_t<_Range>
1072 operator()(_Range&& __r,
1073 _Pred __pred,
const _Tp& __new_value, _Proj __proj = {})
const
1080 inline constexpr __replace_if_fn replace_if{};
1082 template<
typename _Iter,
typename _Out>
1083 using replace_copy_result = in_out_result<_Iter, _Out>;
1085 struct __replace_copy_fn
1087 template<input_iterator _Iter, sentinel_for<_Iter> _Sent,
1088 typename _Tp1,
typename _Tp2, output_iterator<const _Tp2&> _Out,
1089 typename _Proj =
identity>
1090 requires indirectly_copyable<_Iter, _Out>
1091 && indirect_binary_predicate<ranges::equal_to,
1092 projected<_Iter, _Proj>,
const _Tp1*>
1093 constexpr replace_copy_result<_Iter, _Out>
1094 operator()(_Iter __first, _Sent __last, _Out __result,
1095 const _Tp1& __old_value,
const _Tp2& __new_value,
1096 _Proj __proj = {})
const
1098 for (; __first != __last; ++__first, (void)++__result)
1100 *__result = __new_value;
1102 *__result = *__first;
1106 template<input_range _Range,
typename _Tp1,
typename _Tp2,
1107 output_iterator<const _Tp2&> _Out,
typename _Proj = identity>
1108 requires indirectly_copyable<iterator_t<_Range>, _Out>
1109 && indirect_binary_predicate<ranges::equal_to,
1110 projected<iterator_t<_Range>, _Proj>,
1112 constexpr replace_copy_result<borrowed_iterator_t<_Range>, _Out>
1113 operator()(_Range&& __r, _Out __result,
1114 const _Tp1& __old_value,
const _Tp2& __new_value,
1115 _Proj __proj = {})
const
1123 inline constexpr __replace_copy_fn replace_copy{};
1125 template<
typename _Iter,
typename _Out>
1126 using replace_copy_if_result = in_out_result<_Iter, _Out>;
1128 struct __replace_copy_if_fn
1130 template<input_iterator _Iter, sentinel_for<_Iter> _Sent,
1131 typename _Tp, output_iterator<const _Tp&> _Out,
1132 typename _Proj =
identity,
1133 indirect_unary_predicate<projected<_Iter, _Proj>> _Pred>
1134 requires indirectly_copyable<_Iter, _Out>
1135 constexpr replace_copy_if_result<_Iter, _Out>
1136 operator()(_Iter __first, _Sent __last, _Out __result,
1137 _Pred __pred,
const _Tp& __new_value, _Proj __proj = {})
const
1139 for (; __first != __last; ++__first, (void)++__result)
1141 *__result = __new_value;
1143 *__result = *__first;
1147 template<input_range _Range,
1148 typename _Tp, output_iterator<const _Tp&> _Out,
1149 typename _Proj = identity,
1150 indirect_unary_predicate<projected<iterator_t<_Range>, _Proj>>
1152 requires indirectly_copyable<iterator_t<_Range>, _Out>
1153 constexpr replace_copy_if_result<borrowed_iterator_t<_Range>, _Out>
1154 operator()(_Range&& __r, _Out __result,
1155 _Pred __pred,
const _Tp& __new_value, _Proj __proj = {})
const
1163 inline constexpr __replace_copy_if_fn replace_copy_if{};
1165 struct __generate_n_fn
1167 template<input_or_output_iterator _Out, copy_constructible _Fp>
1168 requires invocable<_Fp&>
1169 && indirectly_writable<_Out, invoke_result_t<_Fp&>>
1171 operator()(_Out __first, iter_difference_t<_Out> __n, _Fp __gen)
const
1173 for (; __n > 0; --__n, (void)++__first)
1179 inline constexpr __generate_n_fn generate_n{};
1181 struct __generate_fn
1183 template<input_or_output_iterator _Out, sentinel_for<_Out> _Sent,
1184 copy_constructible _Fp>
1185 requires invocable<_Fp&>
1186 && indirectly_writable<_Out, invoke_result_t<_Fp&>>
1188 operator()(_Out __first, _Sent __last, _Fp __gen)
const
1190 for (; __first != __last; ++__first)
1195 template<
typename _Range, copy_constructible _Fp>
1196 requires invocable<_Fp&> && output_range<_Range, invoke_result_t<_Fp&>>
1197 constexpr borrowed_iterator_t<_Range>
1198 operator()(_Range&& __r, _Fp __gen)
const
1204 inline constexpr __generate_fn generate{};
1206 struct __remove_if_fn
1208 template<permutable _Iter, sentinel_for<_Iter> _Sent,
1209 typename _Proj =
identity,
1210 indirect_unary_predicate<projected<_Iter, _Proj>> _Pred>
1211 constexpr subrange<_Iter>
1212 operator()(_Iter __first, _Sent __last,
1213 _Pred __pred, _Proj __proj = {})
const
1215 __first = ranges::find_if(__first, __last, __pred, __proj);
1216 if (__first == __last)
1217 return {__first, __first};
1219 auto __result = __first;
1221 for (; __first != __last; ++__first)
1228 return {__result, __first};
1231 template<forward_range _Range,
typename _Proj = identity,
1232 indirect_unary_predicate<projected<iterator_t<_Range>, _Proj>>
1234 requires permutable<iterator_t<_Range>>
1235 constexpr borrowed_subrange_t<_Range>
1236 operator()(_Range&& __r, _Pred __pred, _Proj __proj = {})
const
1243 inline constexpr __remove_if_fn remove_if{};
1247 template<permutable _Iter, sentinel_for<_Iter> _Sent,
1248 typename _Tp,
typename _Proj =
identity>
1249 requires indirect_binary_predicate<ranges::equal_to,
1250 projected<_Iter, _Proj>,
1252 constexpr subrange<_Iter>
1253 operator()(_Iter __first, _Sent __last,
1254 const _Tp& __value, _Proj __proj = {})
const
1256 auto __pred = [&] (
auto&& __arg) {
1257 return std::forward<decltype(__arg)>(__arg) == __value;
1259 return ranges::remove_if(__first, __last,
1263 template<forward_range _Range,
typename _Tp,
typename _Proj =
identity>
1264 requires permutable<iterator_t<_Range>>
1265 && indirect_binary_predicate<ranges::equal_to,
1266 projected<iterator_t<_Range>, _Proj>,
1268 constexpr borrowed_subrange_t<_Range>
1269 operator()(_Range&& __r,
const _Tp& __value, _Proj __proj = {})
const
1276 inline constexpr __remove_fn remove{};
1278 template<
typename _Iter,
typename _Out>
1279 using remove_copy_if_result = in_out_result<_Iter, _Out>;
1281 struct __remove_copy_if_fn
1283 template<input_iterator _Iter, sentinel_for<_Iter> _Sent,
1284 weakly_incrementable _Out,
typename _Proj =
identity,
1285 indirect_unary_predicate<projected<_Iter, _Proj>> _Pred>
1286 requires indirectly_copyable<_Iter, _Out>
1287 constexpr remove_copy_if_result<_Iter, _Out>
1288 operator()(_Iter __first, _Sent __last, _Out __result,
1289 _Pred __pred, _Proj __proj = {})
const
1291 for (; __first != __last; ++__first)
1294 *__result = *__first;
1300 template<input_range _Range, weakly_incrementable _Out,
1301 typename _Proj = identity,
1302 indirect_unary_predicate<projected<iterator_t<_Range>, _Proj>>
1304 requires indirectly_copyable<iterator_t<_Range>, _Out>
1305 constexpr remove_copy_if_result<borrowed_iterator_t<_Range>, _Out>
1306 operator()(_Range&& __r, _Out __result,
1307 _Pred __pred, _Proj __proj = {})
const
1315 inline constexpr __remove_copy_if_fn remove_copy_if{};
1317 template<
typename _Iter,
typename _Out>
1318 using remove_copy_result = in_out_result<_Iter, _Out>;
1320 struct __remove_copy_fn
1322 template<input_iterator _Iter, sentinel_for<_Iter> _Sent,
1323 weakly_incrementable _Out,
typename _Tp,
typename _Proj =
identity>
1324 requires indirectly_copyable<_Iter, _Out>
1325 && indirect_binary_predicate<ranges::equal_to,
1326 projected<_Iter, _Proj>,
1328 constexpr remove_copy_result<_Iter, _Out>
1329 operator()(_Iter __first, _Sent __last, _Out __result,
1330 const _Tp& __value, _Proj __proj = {})
const
1332 for (; __first != __last; ++__first)
1335 *__result = *__first;
1341 template<input_range _Range, weakly_incrementable _Out,
1342 typename _Tp,
typename _Proj = identity>
1343 requires indirectly_copyable<iterator_t<_Range>, _Out>
1344 && indirect_binary_predicate<ranges::equal_to,
1345 projected<iterator_t<_Range>, _Proj>,
1347 constexpr remove_copy_result<borrowed_iterator_t<_Range>, _Out>
1348 operator()(_Range&& __r, _Out __result,
1349 const _Tp& __value, _Proj __proj = {})
const
1356 inline constexpr __remove_copy_fn remove_copy{};
1360 template<permutable _Iter, sentinel_for<_Iter> _Sent,
1361 typename _Proj =
identity,
1362 indirect_equivalence_relation<
1363 projected<_Iter, _Proj>> _Comp = ranges::equal_to>
1364 constexpr subrange<_Iter>
1365 operator()(_Iter __first, _Sent __last,
1366 _Comp __comp = {}, _Proj __proj = {})
const
1368 __first = ranges::adjacent_find(__first, __last, __comp, __proj);
1369 if (__first == __last)
1370 return {__first, __first};
1372 auto __dest = __first;
1374 while (++__first != __last)
1379 return {++__dest, __first};
1382 template<forward_range _Range,
typename _Proj = identity,
1383 indirect_equivalence_relation<
1384 projected<iterator_t<_Range>, _Proj>> _Comp = ranges::equal_to>
1385 requires permutable<iterator_t<_Range>>
1386 constexpr borrowed_subrange_t<_Range>
1387 operator()(_Range&& __r, _Comp __comp = {}, _Proj __proj = {})
const
1394 inline constexpr __unique_fn unique{};
1396 template<
typename _Iter,
typename _Out>
1397 using unique_copy_result = in_out_result<_Iter, _Out>;
1399 struct __unique_copy_fn
1401 template<input_iterator _Iter, sentinel_for<_Iter> _Sent,
1402 weakly_incrementable _Out,
typename _Proj =
identity,
1403 indirect_equivalence_relation<
1404 projected<_Iter, _Proj>> _Comp = ranges::equal_to>
1405 requires indirectly_copyable<_Iter, _Out>
1406 && (forward_iterator<_Iter>
1407 || (input_iterator<_Out>
1408 && same_as<iter_value_t<_Iter>, iter_value_t<_Out>>)
1409 || indirectly_copyable_storable<_Iter, _Out>)
1410 constexpr unique_copy_result<_Iter, _Out>
1411 operator()(_Iter __first, _Sent __last, _Out __result,
1412 _Comp __comp = {}, _Proj __proj = {})
const
1414 if (__first == __last)
1418 if constexpr (forward_iterator<_Iter>)
1420 auto __next = __first;
1421 *__result = *__next;
1422 while (++__next != __last)
1428 *++__result = *__first;
1432 else if constexpr (input_iterator<_Out>
1433 && same_as<iter_value_t<_Iter>, iter_value_t<_Out>>)
1435 *__result = *__first;
1436 while (++__first != __last)
1440 *++__result = *__first;
1445 auto __value = *__first;
1446 *__result = __value;
1447 while (++__first != __last)
1454 *++__result = __value;
1461 template<input_range _Range,
1462 weakly_incrementable _Out,
typename _Proj = identity,
1463 indirect_equivalence_relation<
1464 projected<iterator_t<_Range>, _Proj>> _Comp = ranges::equal_to>
1465 requires indirectly_copyable<iterator_t<_Range>, _Out>
1466 && (forward_iterator<iterator_t<_Range>>
1467 || (input_iterator<_Out>
1468 && same_as<range_value_t<_Range>, iter_value_t<_Out>>)
1469 || indirectly_copyable_storable<iterator_t<_Range>, _Out>)
1470 constexpr unique_copy_result<borrowed_iterator_t<_Range>, _Out>
1471 operator()(_Range&& __r, _Out __result,
1472 _Comp __comp = {}, _Proj __proj = {})
const
1480 inline constexpr __unique_copy_fn unique_copy{};
1484 template<b
idirectional_iterator _Iter, sentinel_for<_Iter> _Sent>
1485 requires permutable<_Iter>
1487 operator()(_Iter __first, _Sent __last)
const
1489 auto __i = ranges::next(__first, __last);
1492 if constexpr (random_access_iterator<_Iter>)
1494 if (__first != __last)
1497 while (__first < __tail)
1499 ranges::iter_swap(__first, __tail);
1509 if (__first == __tail || __first == --__tail)
1513 ranges::iter_swap(__first, __tail);
1520 template<b
idirectional_range _Range>
1521 requires permutable<iterator_t<_Range>>
1522 constexpr borrowed_iterator_t<_Range>
1523 operator()(_Range&& __r)
const
1529 inline constexpr __reverse_fn reverse{};
1531 template<
typename _Iter,
typename _Out>
1532 using reverse_copy_result = in_out_result<_Iter, _Out>;
1534 struct __reverse_copy_fn
1536 template<b
idirectional_iterator _Iter, sentinel_for<_Iter> _Sent,
1537 weakly_incrementable _Out>
1538 requires indirectly_copyable<_Iter, _Out>
1539 constexpr reverse_copy_result<_Iter, _Out>
1540 operator()(_Iter __first, _Sent __last, _Out __result)
const
1542 auto __i = ranges::next(__first, __last);
1544 while (__first != __tail)
1547 *__result = *__tail;
1550 return {__i, __result};
1553 template<b
idirectional_range _Range, weakly_incrementable _Out>
1554 requires indirectly_copyable<iterator_t<_Range>, _Out>
1555 constexpr reverse_copy_result<borrowed_iterator_t<_Range>, _Out>
1556 operator()(_Range&& __r, _Out __result)
const
1563 inline constexpr __reverse_copy_fn reverse_copy{};
1567 template<permutable _Iter, sentinel_for<_Iter> _Sent>
1568 constexpr subrange<_Iter>
1569 operator()(_Iter __first, _Iter __middle, _Sent __last)
const
1571 auto __lasti = ranges::next(__first, __last);
1572 if (__first == __middle)
1573 return {__lasti, __lasti};
1574 if (__last == __middle)
1577 if constexpr (random_access_iterator<_Iter>)
1579 auto __n = __lasti - __first;
1580 auto __k = __middle - __first;
1582 if (__k == __n - __k)
1584 ranges::swap_ranges(__first, __middle, __middle, __middle + __k);
1589 auto __ret = __first + (__lasti - __middle);
1593 if (__k < __n - __k)
1597 if constexpr (__is_pod(iter_value_t<_Iter>))
1605 auto __q = __p + __k;
1606 for (decltype(__n) __i = 0; __i < __n - __k; ++ __i)
1608 ranges::iter_swap(__p, __q);
1615 ranges::swap(__n, __k);
1623 if constexpr (__is_pod(iter_value_t<_Iter>))
1631 auto __q = __p + __n;
1633 for (decltype(__n) __i = 0; __i < __n - __k; ++ __i)
1637 ranges::iter_swap(__p, __q);
1642 std::swap(__n, __k);
1646 else if constexpr (bidirectional_iterator<_Iter>)
1648 auto __tail = __lasti;
1650 ranges::reverse(__first, __middle);
1651 ranges::reverse(__middle, __tail);
1653 while (__first != __middle && __middle != __tail)
1655 ranges::iter_swap(__first, --__tail);
1659 if (__first == __middle)
1661 ranges::reverse(__middle, __tail);
1666 ranges::reverse(__first, __middle);
1672 auto __first2 = __middle;
1675 ranges::iter_swap(__first, __first2);
1678 if (__first == __middle)
1679 __middle = __first2;
1680 }
while (__first2 != __last);
1682 auto __ret = __first;
1684 __first2 = __middle;
1686 while (__first2 != __last)
1688 ranges::iter_swap(__first, __first2);
1691 if (__first == __middle)
1692 __middle = __first2;
1693 else if (__first2 == __last)
1694 __first2 = __middle;
1700 template<forward_range _Range>
1701 requires permutable<iterator_t<_Range>>
1702 constexpr borrowed_subrange_t<_Range>
1703 operator()(_Range&& __r, iterator_t<_Range> __middle)
const
1710 inline constexpr __rotate_fn rotate{};
1712 template<
typename _Iter,
typename _Out>
1713 using rotate_copy_result = in_out_result<_Iter, _Out>;
1715 struct __rotate_copy_fn
1717 template<forward_iterator _Iter, sentinel_for<_Iter> _Sent,
1718 weakly_incrementable _Out>
1719 requires indirectly_copyable<_Iter, _Out>
1720 constexpr rotate_copy_result<_Iter, _Out>
1721 operator()(_Iter __first, _Iter __middle, _Sent __last,
1722 _Out __result)
const
1724 auto __copy1 = ranges::copy(__middle,
1727 auto __copy2 = ranges::copy(
std::move(__first),
1733 template<forward_range _Range, weakly_incrementable _Out>
1734 requires indirectly_copyable<iterator_t<_Range>, _Out>
1735 constexpr rotate_copy_result<borrowed_iterator_t<_Range>, _Out>
1736 operator()(_Range&& __r, iterator_t<_Range> __middle, _Out __result)
const
1743 inline constexpr __rotate_copy_fn rotate_copy{};
1747 template<input_iterator _Iter, sentinel_for<_Iter> _Sent,
1748 weakly_incrementable _Out,
typename _Gen>
1749 requires (forward_iterator<_Iter> || random_access_iterator<_Out>)
1750 && indirectly_copyable<_Iter, _Out>
1751 && uniform_random_bit_generator<remove_reference_t<_Gen>>
1753 operator()(_Iter __first, _Sent __last, _Out __out,
1754 iter_difference_t<_Iter> __n, _Gen&& __g)
const
1756 if constexpr (forward_iterator<_Iter>)
1760 auto __lasti = ranges::next(__first, __last);
1762 std::move(__out), __n, std::forward<_Gen>(__g));
1766 using __distrib_type
1767 = uniform_int_distribution<iter_difference_t<_Iter>>;
1768 using __param_type =
typename __distrib_type::param_type;
1769 __distrib_type __d{};
1770 iter_difference_t<_Iter> __sample_sz = 0;
1771 while (__first != __last && __sample_sz != __n)
1773 __out[__sample_sz++] = *__first;
1776 for (
auto __pop_sz = __sample_sz; __first != __last;
1777 ++__first, (void) ++__pop_sz)
1779 const auto __k = __d(__g, __param_type{0, __pop_sz});
1781 __out[__k] = *__first;
1783 return __out + __sample_sz;
1787 template<input_range _Range, weakly_incrementable _Out,
typename _Gen>
1788 requires (forward_range<_Range> || random_access_iterator<_Out>)
1789 && indirectly_copyable<iterator_t<_Range>, _Out>
1790 && uniform_random_bit_generator<remove_reference_t<_Gen>>
1792 operator()(_Range&& __r, _Out __out,
1793 range_difference_t<_Range> __n, _Gen&& __g)
const
1797 std::forward<_Gen>(__g));
1801 inline constexpr __sample_fn
sample{};
1803 #ifdef _GLIBCXX_USE_C99_STDINT_TR1
1806 template<random_access_iterator _Iter, sentinel_for<_Iter> _Sent,
1808 requires permutable<_Iter>
1809 && uniform_random_bit_generator<remove_reference_t<_Gen>>
1811 operator()(_Iter __first, _Sent __last, _Gen&& __g)
const
1813 auto __lasti = ranges::next(__first, __last);
1818 template<random_access_range _Range,
typename _Gen>
1819 requires permutable<iterator_t<_Range>>
1820 && uniform_random_bit_generator<remove_reference_t<_Gen>>
1821 borrowed_iterator_t<_Range>
1822 operator()(_Range&& __r, _Gen&& __g)
const
1825 std::forward<_Gen>(__g));
1829 inline constexpr __shuffle_fn shuffle{};
1832 struct __push_heap_fn
1834 template<random_access_iterator _Iter, sentinel_for<_Iter> _Sent,
1835 typename _Comp = ranges::less,
typename _Proj =
identity>
1836 requires sortable<_Iter, _Comp, _Proj>
1838 operator()(_Iter __first, _Sent __last,
1839 _Comp __comp = {}, _Proj __proj = {})
const
1841 auto __lasti = ranges::next(__first, __last);
1843 __detail::__make_comp_proj(__comp, __proj));
1847 template<random_access_range _Range,
1848 typename _Comp = ranges::less,
typename _Proj = identity>
1849 requires sortable<iterator_t<_Range>, _Comp, _Proj>
1850 constexpr borrowed_iterator_t<_Range>
1851 operator()(_Range&& __r, _Comp __comp = {}, _Proj __proj = {})
const
1858 inline constexpr __push_heap_fn push_heap{};
1860 struct __pop_heap_fn
1862 template<random_access_iterator _Iter, sentinel_for<_Iter> _Sent,
1863 typename _Comp = ranges::less,
typename _Proj =
identity>
1864 requires sortable<_Iter, _Comp, _Proj>
1866 operator()(_Iter __first, _Sent __last,
1867 _Comp __comp = {}, _Proj __proj = {})
const
1869 auto __lasti = ranges::next(__first, __last);
1871 __detail::__make_comp_proj(__comp, __proj));
1875 template<random_access_range _Range,
1876 typename _Comp = ranges::less,
typename _Proj = identity>
1877 requires sortable<iterator_t<_Range>, _Comp, _Proj>
1878 constexpr borrowed_iterator_t<_Range>
1879 operator()(_Range&& __r, _Comp __comp = {}, _Proj __proj = {})
const
1886 inline constexpr __pop_heap_fn pop_heap{};
1888 struct __make_heap_fn
1890 template<random_access_iterator _Iter, sentinel_for<_Iter> _Sent,
1891 typename _Comp = ranges::less,
typename _Proj =
identity>
1892 requires sortable<_Iter, _Comp, _Proj>
1894 operator()(_Iter __first, _Sent __last,
1895 _Comp __comp = {}, _Proj __proj = {})
const
1897 auto __lasti = ranges::next(__first, __last);
1899 __detail::__make_comp_proj(__comp, __proj));
1903 template<random_access_range _Range,
1904 typename _Comp = ranges::less,
typename _Proj = identity>
1905 requires sortable<iterator_t<_Range>, _Comp, _Proj>
1906 constexpr borrowed_iterator_t<_Range>
1907 operator()(_Range&& __r, _Comp __comp = {}, _Proj __proj = {})
const
1914 inline constexpr __make_heap_fn make_heap{};
1916 struct __sort_heap_fn
1918 template<random_access_iterator _Iter, sentinel_for<_Iter> _Sent,
1919 typename _Comp = ranges::less,
typename _Proj =
identity>
1920 requires sortable<_Iter, _Comp, _Proj>
1922 operator()(_Iter __first, _Sent __last,
1923 _Comp __comp = {}, _Proj __proj = {})
const
1925 auto __lasti = ranges::next(__first, __last);
1927 __detail::__make_comp_proj(__comp, __proj));
1931 template<random_access_range _Range,
1932 typename _Comp = ranges::less,
typename _Proj = identity>
1933 requires sortable<iterator_t<_Range>, _Comp, _Proj>
1934 constexpr borrowed_iterator_t<_Range>
1935 operator()(_Range&& __r, _Comp __comp = {}, _Proj __proj = {})
const
1942 inline constexpr __sort_heap_fn sort_heap{};
1944 struct __is_heap_until_fn
1946 template<random_access_iterator _Iter, sentinel_for<_Iter> _Sent,
1947 typename _Proj =
identity,
1948 indirect_strict_weak_order<projected<_Iter, _Proj>>
1949 _Comp = ranges::less>
1951 operator()(_Iter __first, _Sent __last,
1952 _Comp __comp = {}, _Proj __proj = {})
const
1955 iter_difference_t<_Iter> __parent = 0, __child = 1;
1956 for (; __child < __n; ++__child)
1960 return __first + __child;
1961 else if ((__child & 1) == 0)
1964 return __first + __n;
1967 template<random_access_range _Range,
1968 typename _Proj = identity,
1969 indirect_strict_weak_order<projected<iterator_t<_Range>, _Proj>>
1970 _Comp = ranges::less>
1971 constexpr borrowed_iterator_t<_Range>
1972 operator()(_Range&& __r, _Comp __comp = {}, _Proj __proj = {})
const
1979 inline constexpr __is_heap_until_fn is_heap_until{};
1983 template<random_access_iterator _Iter, sentinel_for<_Iter> _Sent,
1984 typename _Proj =
identity,
1985 indirect_strict_weak_order<projected<_Iter, _Proj>>
1986 _Comp = ranges::less>
1988 operator()(_Iter __first, _Sent __last,
1989 _Comp __comp = {}, _Proj __proj = {})
const
1992 == ranges::is_heap_until(__first, __last,
1997 template<random_access_range _Range,
1998 typename _Proj = identity,
1999 indirect_strict_weak_order<projected<iterator_t<_Range>, _Proj>>
2000 _Comp = ranges::less>
2002 operator()(_Range&& __r, _Comp __comp = {}, _Proj __proj = {})
const
2009 inline constexpr __is_heap_fn is_heap{};
2013 template<random_access_iterator _Iter, sentinel_for<_Iter> _Sent,
2014 typename _Comp = ranges::less,
typename _Proj =
identity>
2015 requires sortable<_Iter, _Comp, _Proj>
2017 operator()(_Iter __first, _Sent __last,
2018 _Comp __comp = {}, _Proj __proj = {})
const
2020 auto __lasti = ranges::next(__first, __last);
2022 __detail::__make_comp_proj(__comp, __proj));
2026 template<random_access_range _Range,
2027 typename _Comp = ranges::less,
typename _Proj = identity>
2028 requires sortable<iterator_t<_Range>, _Comp, _Proj>
2029 constexpr borrowed_iterator_t<_Range>
2030 operator()(_Range&& __r, _Comp __comp = {}, _Proj __proj = {})
const
2037 inline constexpr __sort_fn sort{};
2039 struct __stable_sort_fn
2041 template<random_access_iterator _Iter, sentinel_for<_Iter> _Sent,
2042 typename _Comp = ranges::less,
typename _Proj =
identity>
2043 requires sortable<_Iter, _Comp, _Proj>
2045 operator()(_Iter __first, _Sent __last,
2046 _Comp __comp = {}, _Proj __proj = {})
const
2048 auto __lasti = ranges::next(__first, __last);
2050 __detail::__make_comp_proj(__comp, __proj));
2054 template<random_access_range _Range,
2055 typename _Comp = ranges::less,
typename _Proj = identity>
2056 requires sortable<iterator_t<_Range>, _Comp, _Proj>
2057 borrowed_iterator_t<_Range>
2058 operator()(_Range&& __r, _Comp __comp = {}, _Proj __proj = {})
const
2065 inline constexpr __stable_sort_fn stable_sort{};
2067 struct __partial_sort_fn
2069 template<random_access_iterator _Iter, sentinel_for<_Iter> _Sent,
2070 typename _Comp = ranges::less,
typename _Proj =
identity>
2071 requires sortable<_Iter, _Comp, _Proj>
2073 operator()(_Iter __first, _Iter __middle, _Sent __last,
2074 _Comp __comp = {}, _Proj __proj = {})
const
2076 if (__first == __middle)
2077 return ranges::next(__first, __last);
2079 ranges::make_heap(__first, __middle, __comp, __proj);
2080 auto __i = __middle;
2081 for (; __i != __last; ++__i)
2086 ranges::pop_heap(__first, __middle, __comp, __proj);
2087 ranges::iter_swap(__middle-1, __i);
2088 ranges::push_heap(__first, __middle, __comp, __proj);
2090 ranges::sort_heap(__first, __middle, __comp, __proj);
2095 template<random_access_range _Range,
2096 typename _Comp = ranges::less,
typename _Proj = identity>
2097 requires sortable<iterator_t<_Range>, _Comp, _Proj>
2098 constexpr borrowed_iterator_t<_Range>
2099 operator()(_Range&& __r, iterator_t<_Range> __middle,
2100 _Comp __comp = {}, _Proj __proj = {})
const
2108 inline constexpr __partial_sort_fn partial_sort{};
2110 template<
typename _Iter,
typename _Out>
2111 using partial_sort_copy_result = in_out_result<_Iter, _Out>;
2113 struct __partial_sort_copy_fn
2115 template<input_iterator _Iter1, sentinel_for<_Iter1> _Sent1,
2116 random_access_iterator _Iter2, sentinel_for<_Iter2> _Sent2,
2117 typename _Comp = ranges::less,
2118 typename _Proj1 =
identity,
typename _Proj2 =
identity>
2119 requires indirectly_copyable<_Iter1, _Iter2>
2120 && sortable<_Iter2, _Comp, _Proj2>
2121 && indirect_strict_weak_order<_Comp,
2122 projected<_Iter1, _Proj1>,
2123 projected<_Iter2, _Proj2>>
2124 constexpr partial_sort_copy_result<_Iter1, _Iter2>
2125 operator()(_Iter1 __first, _Sent1 __last,
2126 _Iter2 __result_first, _Sent2 __result_last,
2128 _Proj1 __proj1 = {}, _Proj2 __proj2 = {})
const
2130 if (__result_first == __result_last)
2133 auto __lasti = ranges::next(
std::move(__first),
2138 auto __result_real_last = __result_first;
2139 while (__first != __last && __result_real_last != __result_last)
2141 *__result_real_last = *__first;
2142 ++__result_real_last;
2146 ranges::make_heap(__result_first, __result_real_last, __comp, __proj2);
2147 for (; __first != __last; ++__first)
2152 ranges::pop_heap(__result_first, __result_real_last,
2154 *(__result_real_last-1) = *__first;
2155 ranges::push_heap(__result_first, __result_real_last,
2158 ranges::sort_heap(__result_first, __result_real_last, __comp, __proj2);
2163 template<input_range _Range1, random_access_range _Range2,
2164 typename _Comp = ranges::less,
2165 typename _Proj1 = identity,
typename _Proj2 = identity>
2166 requires indirectly_copyable<iterator_t<_Range1>, iterator_t<_Range2>>
2167 && sortable<iterator_t<_Range2>, _Comp, _Proj2>
2168 && indirect_strict_weak_order<_Comp,
2169 projected<iterator_t<_Range1>, _Proj1>,
2170 projected<iterator_t<_Range2>, _Proj2>>
2171 constexpr partial_sort_copy_result<borrowed_iterator_t<_Range1>,
2172 borrowed_iterator_t<_Range2>>
2173 operator()(_Range1&& __r, _Range2&& __out, _Comp __comp = {},
2174 _Proj1 __proj1 = {}, _Proj2 __proj2 = {})
const
2183 inline constexpr __partial_sort_copy_fn partial_sort_copy{};
2185 struct __is_sorted_until_fn
2187 template<forward_iterator _Iter, sentinel_for<_Iter> _Sent,
2188 typename _Proj =
identity,
2189 indirect_strict_weak_order<projected<_Iter, _Proj>>
2190 _Comp = ranges::less>
2192 operator()(_Iter __first, _Sent __last,
2193 _Comp __comp = {}, _Proj __proj = {})
const
2195 if (__first == __last)
2198 auto __next = __first;
2199 for (++__next; __next != __last; __first = __next, (void)++__next)
2207 template<forward_range _Range,
typename _Proj = identity,
2208 indirect_strict_weak_order<projected<iterator_t<_Range>, _Proj>>
2209 _Comp = ranges::less>
2210 constexpr borrowed_iterator_t<_Range>
2211 operator()(_Range&& __r, _Comp __comp = {}, _Proj __proj = {})
const
2218 inline constexpr __is_sorted_until_fn is_sorted_until{};
2220 struct __is_sorted_fn
2222 template<forward_iterator _Iter, sentinel_for<_Iter> _Sent,
2223 typename _Proj =
identity,
2224 indirect_strict_weak_order<projected<_Iter, _Proj>>
2225 _Comp = ranges::less>
2227 operator()(_Iter __first, _Sent __last,
2228 _Comp __comp = {}, _Proj __proj = {})
const
2230 if (__first == __last)
2233 auto __next = __first;
2234 for (++__next; __next != __last; __first = __next, (void)++__next)
2242 template<forward_range _Range,
typename _Proj = identity,
2243 indirect_strict_weak_order<projected<iterator_t<_Range>, _Proj>>
2244 _Comp = ranges::less>
2246 operator()(_Range&& __r, _Comp __comp = {}, _Proj __proj = {})
const
2253 inline constexpr __is_sorted_fn is_sorted{};
2255 struct __nth_element_fn
2257 template<random_access_iterator _Iter, sentinel_for<_Iter> _Sent,
2258 typename _Comp = ranges::less,
typename _Proj =
identity>
2259 requires sortable<_Iter, _Comp, _Proj>
2261 operator()(_Iter __first, _Iter __nth, _Sent __last,
2262 _Comp __comp = {}, _Proj __proj = {})
const
2264 auto __lasti = ranges::next(__first, __last);
2266 __detail::__make_comp_proj(__comp, __proj));
2270 template<random_access_range _Range,
2271 typename _Comp = ranges::less,
typename _Proj = identity>
2272 requires sortable<iterator_t<_Range>, _Comp, _Proj>
2273 constexpr borrowed_iterator_t<_Range>
2274 operator()(_Range&& __r, iterator_t<_Range> __nth,
2275 _Comp __comp = {}, _Proj __proj = {})
const
2282 inline constexpr __nth_element_fn nth_element{};
2284 struct __lower_bound_fn
2286 template<forward_iterator _Iter, sentinel_for<_Iter> _Sent,
2287 typename _Tp,
typename _Proj =
identity,
2288 indirect_strict_weak_order<const _Tp*, projected<_Iter, _Proj>>
2289 _Comp = ranges::less>
2291 operator()(_Iter __first, _Sent __last,
2292 const _Tp& __value, _Comp __comp = {}, _Proj __proj = {})
const
2298 auto __half = __len / 2;
2299 auto __middle = __first;
2305 __len = __len - __half - 1;
2313 template<forward_range _Range,
typename _Tp,
typename _Proj = identity,
2314 indirect_strict_weak_order<
const _Tp*,
2315 projected<iterator_t<_Range>, _Proj>>
2316 _Comp = ranges::less>
2317 constexpr borrowed_iterator_t<_Range>
2318 operator()(_Range&& __r,
2319 const _Tp& __value, _Comp __comp = {}, _Proj __proj = {})
const
2326 inline constexpr __lower_bound_fn lower_bound{};
2328 struct __upper_bound_fn
2330 template<forward_iterator _Iter, sentinel_for<_Iter> _Sent,
2331 typename _Tp,
typename _Proj =
identity,
2332 indirect_strict_weak_order<const _Tp*, projected<_Iter, _Proj>>
2333 _Comp = ranges::less>
2335 operator()(_Iter __first, _Sent __last,
2336 const _Tp& __value, _Comp __comp = {}, _Proj __proj = {})
const
2342 auto __half = __len / 2;
2343 auto __middle = __first;
2351 __len = __len - __half - 1;
2357 template<forward_range _Range,
typename _Tp,
typename _Proj = identity,
2358 indirect_strict_weak_order<
const _Tp*,
2359 projected<iterator_t<_Range>, _Proj>>
2360 _Comp = ranges::less>
2361 constexpr borrowed_iterator_t<_Range>
2362 operator()(_Range&& __r,
2363 const _Tp& __value, _Comp __comp = {}, _Proj __proj = {})
const
2370 inline constexpr __upper_bound_fn upper_bound{};
2372 struct __equal_range_fn
2374 template<forward_iterator _Iter, sentinel_for<_Iter> _Sent,
2375 typename _Tp,
typename _Proj =
identity,
2376 indirect_strict_weak_order<const _Tp*, projected<_Iter, _Proj>>
2377 _Comp = ranges::less>
2378 constexpr subrange<_Iter>
2379 operator()(_Iter __first, _Sent __last,
2380 const _Tp& __value, _Comp __comp = {}, _Proj __proj = {})
const
2386 auto __half = __len / 2;
2387 auto __middle = __first;
2395 __len = __len - __half - 1;
2404 = ranges::lower_bound(__first, __middle,
2405 __value, __comp, __proj);
2408 = ranges::upper_bound(++__middle, __first,
2409 __value, __comp, __proj);
2410 return {__left, __right};
2413 return {__first, __first};
2416 template<forward_range _Range,
2417 typename _Tp,
typename _Proj = identity,
2418 indirect_strict_weak_order<
const _Tp*,
2419 projected<iterator_t<_Range>, _Proj>>
2420 _Comp = ranges::less>
2421 constexpr borrowed_subrange_t<_Range>
2422 operator()(_Range&& __r,
const _Tp& __value,
2423 _Comp __comp = {}, _Proj __proj = {})
const
2430 inline constexpr __equal_range_fn equal_range{};
2432 struct __binary_search_fn
2434 template<forward_iterator _Iter, sentinel_for<_Iter> _Sent,
2435 typename _Tp,
typename _Proj =
identity,
2436 indirect_strict_weak_order<const _Tp*, projected<_Iter, _Proj>>
2437 _Comp = ranges::less>
2439 operator()(_Iter __first, _Sent __last,
2440 const _Tp& __value, _Comp __comp = {}, _Proj __proj = {})
const
2442 auto __i = ranges::lower_bound(__first, __last, __value, __comp, __proj);
2449 template<forward_range _Range,
2450 typename _Tp,
typename _Proj = identity,
2451 indirect_strict_weak_order<
const _Tp*,
2452 projected<iterator_t<_Range>, _Proj>>
2453 _Comp = ranges::less>
2455 operator()(_Range&& __r,
const _Tp& __value, _Comp __comp = {},
2456 _Proj __proj = {})
const
2463 inline constexpr __binary_search_fn binary_search{};
2465 struct __is_partitioned_fn
2467 template<input_iterator _Iter, sentinel_for<_Iter> _Sent,
2468 typename _Proj =
identity,
2469 indirect_unary_predicate<projected<_Iter, _Proj>> _Pred>
2471 operator()(_Iter __first, _Sent __last,
2472 _Pred __pred, _Proj __proj = {})
const
2474 __first = ranges::find_if_not(
std::move(__first), __last,
2476 if (__first == __last)
2483 template<input_range _Range,
typename _Proj = identity,
2484 indirect_unary_predicate<projected<iterator_t<_Range>, _Proj>>
2487 operator()(_Range&& __r, _Pred __pred, _Proj __proj = {})
const
2494 inline constexpr __is_partitioned_fn is_partitioned{};
2496 struct __partition_fn
2498 template<permutable _Iter, sentinel_for<_Iter> _Sent,
2499 typename _Proj =
identity,
2500 indirect_unary_predicate<projected<_Iter, _Proj>> _Pred>
2501 constexpr subrange<_Iter>
2502 operator()(_Iter __first, _Sent __last,
2503 _Pred __pred, _Proj __proj = {})
const
2505 if constexpr (bidirectional_iterator<_Iter>)
2507 auto __lasti = ranges::next(__first, __last);
2508 auto __tail = __lasti;
2512 if (__first == __tail)
2521 if (__first == __tail)
2528 ranges::iter_swap(__first, __tail);
2534 if (__first == __last)
2538 if (++__first == __last)
2541 auto __next = __first;
2542 while (++__next != __last)
2545 ranges::iter_swap(__first, __next);
2553 template<forward_range _Range,
typename _Proj = identity,
2554 indirect_unary_predicate<projected<iterator_t<_Range>, _Proj>>
2556 requires permutable<iterator_t<_Range>>
2557 constexpr borrowed_subrange_t<_Range>
2558 operator()(_Range&& __r, _Pred __pred, _Proj __proj = {})
const
2565 inline constexpr __partition_fn partition{};
2567 struct __stable_partition_fn
2569 template<b
idirectional_iterator _Iter, sentinel_for<_Iter> _Sent,
2570 typename _Proj =
identity,
2571 indirect_unary_predicate<projected<_Iter, _Proj>> _Pred>
2572 requires permutable<_Iter>
2574 operator()(_Iter __first, _Sent __last,
2575 _Pred __pred, _Proj __proj = {})
const
2577 auto __lasti = ranges::next(__first, __last);
2580 __detail::__make_pred_proj(__pred, __proj));
2584 template<bidirectional_range _Range,
typename _Proj = identity,
2585 indirect_unary_predicate<projected<iterator_t<_Range>, _Proj>>
2587 requires permutable<iterator_t<_Range>>
2588 borrowed_subrange_t<_Range>
2589 operator()(_Range&& __r, _Pred __pred, _Proj __proj = {})
const
2596 inline constexpr __stable_partition_fn stable_partition{};
2598 template<
typename _Iter,
typename _Out1,
typename _Out2>
2599 struct in_out_out_result
2601 [[no_unique_address]] _Iter in;
2602 [[no_unique_address]] _Out1 out1;
2603 [[no_unique_address]] _Out2 out2;
2605 template<
typename _IIter,
typename _OOut1,
typename _OOut2>
2606 requires convertible_to<const _Iter&, _IIter>
2607 && convertible_to<const _Out1&, _OOut1>
2608 && convertible_to<const _Out2&, _OOut2>
2610 operator in_out_out_result<_IIter, _OOut1, _OOut2>() const &
2611 {
return {in, out1, out2}; }
2613 template<
typename _IIter,
typename _OOut1,
typename _OOut2>
2614 requires convertible_to<_Iter, _IIter>
2615 && convertible_to<_Out1, _OOut1>
2616 && convertible_to<_Out2, _OOut2>
2618 operator in_out_out_result<_IIter, _OOut1, _OOut2>() &&
2622 template<
typename _Iter,
typename _Out1,
typename _Out2>
2623 using partition_copy_result = in_out_out_result<_Iter, _Out1, _Out2>;
2625 struct __partition_copy_fn
2627 template<input_iterator _Iter, sentinel_for<_Iter> _Sent,
2628 weakly_incrementable _Out1, weakly_incrementable _O2,
2629 typename _Proj =
identity,
2630 indirect_unary_predicate<projected<_Iter, _Proj>> _Pred>
2631 requires indirectly_copyable<_Iter, _Out1>
2632 && indirectly_copyable<_Iter, _O2>
2633 constexpr partition_copy_result<_Iter, _Out1, _O2>
2634 operator()(_Iter __first, _Sent __last,
2635 _Out1 __out_true, _O2 __out_false,
2636 _Pred __pred, _Proj __proj = {})
const
2638 for (; __first != __last; ++__first)
2641 *__out_true = *__first;
2646 *__out_false = *__first;
2654 template<input_range _Range, weakly_incrementable _Out1,
2655 weakly_incrementable _O2,
2656 typename _Proj = identity,
2657 indirect_unary_predicate<projected<iterator_t<_Range>, _Proj>>
2659 requires indirectly_copyable<iterator_t<_Range>, _Out1>
2660 && indirectly_copyable<iterator_t<_Range>, _O2>
2661 constexpr partition_copy_result<borrowed_iterator_t<_Range>, _Out1, _O2>
2662 operator()(_Range&& __r, _Out1 out_true, _O2 out_false,
2663 _Pred __pred, _Proj __proj = {})
const
2671 inline constexpr __partition_copy_fn partition_copy{};
2673 struct __partition_point_fn
2675 template<forward_iterator _Iter, sentinel_for<_Iter> _Sent,
2676 typename _Proj =
identity,
2677 indirect_unary_predicate<projected<_Iter, _Proj>> _Pred>
2679 operator()(_Iter __first, _Sent __last,
2680 _Pred __pred, _Proj __proj = {})
const
2686 auto __half = __len / 2;
2687 auto __middle = __first;
2693 __len = __len - __half - 1;
2701 template<forward_range _Range,
typename _Proj = identity,
2702 indirect_unary_predicate<projected<iterator_t<_Range>, _Proj>>
2704 constexpr borrowed_iterator_t<_Range>
2705 operator()(_Range&& __r, _Pred __pred, _Proj __proj = {})
const
2712 inline constexpr __partition_point_fn partition_point{};
2714 template<
typename _Iter1,
typename _Iter2,
typename _Out>
2715 using merge_result = in_in_out_result<_Iter1, _Iter2, _Out>;
2719 template<input_iterator _Iter1, sentinel_for<_Iter1> _Sent1,
2720 input_iterator _Iter2, sentinel_for<_Iter2> _Sent2,
2721 weakly_incrementable _Out,
typename _Comp = ranges::less,
2722 typename _Proj1 =
identity,
typename _Proj2 =
identity>
2723 requires mergeable<_Iter1, _Iter2, _Out, _Comp, _Proj1, _Proj2>
2724 constexpr merge_result<_Iter1, _Iter2, _Out>
2725 operator()(_Iter1 __first1, _Sent1 __last1,
2726 _Iter2 __first2, _Sent2 __last2, _Out __result,
2728 _Proj1 __proj1 = {}, _Proj2 __proj2 = {})
const
2730 while (__first1 != __last1 && __first2 != __last2)
2736 *__result = *__first2;
2741 *__result = *__first1;
2754 template<input_range _Range1, input_range _Range2, weakly_incrementable _Out,
2755 typename _Comp = ranges::less,
2756 typename _Proj1 = identity,
typename _Proj2 = identity>
2757 requires mergeable<iterator_t<_Range1>, iterator_t<_Range2>, _Out,
2758 _Comp, _Proj1, _Proj2>
2759 constexpr merge_result<borrowed_iterator_t<_Range1>,
2760 borrowed_iterator_t<_Range2>,
2762 operator()(_Range1&& __r1, _Range2&& __r2, _Out __result,
2764 _Proj1 __proj1 = {}, _Proj2 __proj2 = {})
const
2773 inline constexpr __merge_fn merge{};
2775 struct __inplace_merge_fn
2777 template<b
idirectional_iterator _Iter, sentinel_for<_Iter> _Sent,
2778 typename _Comp = ranges::less,
2779 typename _Proj =
identity>
2780 requires sortable<_Iter, _Comp, _Proj>
2782 operator()(_Iter __first, _Iter __middle, _Sent __last,
2783 _Comp __comp = {}, _Proj __proj = {})
const
2785 auto __lasti = ranges::next(__first, __last);
2787 __detail::__make_comp_proj(__comp, __proj));
2791 template<bidirectional_range _Range,
2792 typename _Comp = ranges::less,
typename _Proj = identity>
2793 requires sortable<iterator_t<_Range>, _Comp, _Proj>
2794 borrowed_iterator_t<_Range>
2795 operator()(_Range&& __r, iterator_t<_Range> __middle,
2796 _Comp __comp = {}, _Proj __proj = {})
const
2804 inline constexpr __inplace_merge_fn inplace_merge{};
2806 struct __includes_fn
2808 template<input_iterator _Iter1, sentinel_for<_Iter1> _Sent1,
2809 input_iterator _Iter2, sentinel_for<_Iter2> _Sent2,
2810 typename _Proj1 =
identity,
typename _Proj2 =
identity,
2811 indirect_strict_weak_order<projected<_Iter1, _Proj1>,
2812 projected<_Iter2, _Proj2>>
2813 _Comp = ranges::less>
2815 operator()(_Iter1 __first1, _Sent1 __last1,
2816 _Iter2 __first2, _Sent2 __last2,
2818 _Proj1 __proj1 = {}, _Proj2 __proj2 = {})
const
2820 while (__first1 != __last1 && __first2 != __last2)
2835 return __first2 == __last2;
2838 template<input_range _Range1, input_range _Range2,
2839 typename _Proj1 = identity,
typename _Proj2 = identity,
2840 indirect_strict_weak_order<projected<iterator_t<_Range1>, _Proj1>,
2841 projected<iterator_t<_Range2>, _Proj2>>
2842 _Comp = ranges::less>
2844 operator()(_Range1&& __r1, _Range2&& __r2, _Comp __comp = {},
2845 _Proj1 __proj1 = {}, _Proj2 __proj2 = {})
const
2854 inline constexpr __includes_fn includes{};
2856 template<
typename _Iter1,
typename _Iter2,
typename _Out>
2857 using set_union_result = in_in_out_result<_Iter1, _Iter2, _Out>;
2859 struct __set_union_fn
2861 template<input_iterator _Iter1, sentinel_for<_Iter1> _Sent1,
2862 input_iterator _Iter2, sentinel_for<_Iter2> _Sent2,
2863 weakly_incrementable _Out,
typename _Comp = ranges::less,
2864 typename _Proj1 =
identity,
typename _Proj2 =
identity>
2865 requires mergeable<_Iter1, _Iter2, _Out, _Comp, _Proj1, _Proj2>
2866 constexpr set_union_result<_Iter1, _Iter2, _Out>
2867 operator()(_Iter1 __first1, _Sent1 __last1,
2868 _Iter2 __first2, _Sent2 __last2,
2869 _Out __result, _Comp __comp = {},
2870 _Proj1 __proj1 = {}, _Proj2 __proj2 = {})
const
2872 while (__first1 != __last1 && __first2 != __last2)
2878 *__result = *__first1;
2885 *__result = *__first2;
2890 *__result = *__first1;
2904 template<input_range _Range1, input_range _Range2, weakly_incrementable _Out,
2905 typename _Comp = ranges::less,
2906 typename _Proj1 = identity,
typename _Proj2 = identity>
2907 requires mergeable<iterator_t<_Range1>, iterator_t<_Range2>, _Out,
2908 _Comp, _Proj1, _Proj2>
2909 constexpr set_union_result<borrowed_iterator_t<_Range1>,
2910 borrowed_iterator_t<_Range2>, _Out>
2911 operator()(_Range1&& __r1, _Range2&& __r2,
2912 _Out __result, _Comp __comp = {},
2913 _Proj1 __proj1 = {}, _Proj2 __proj2 = {})
const
2922 inline constexpr __set_union_fn set_union{};
2924 template<
typename _Iter1,
typename _Iter2,
typename _Out>
2925 using set_intersection_result = in_in_out_result<_Iter1, _Iter2, _Out>;
2927 struct __set_intersection_fn
2929 template<input_iterator _Iter1, sentinel_for<_Iter1> _Sent1,
2930 input_iterator _Iter2, sentinel_for<_Iter2> _Sent2,
2931 weakly_incrementable _Out,
typename _Comp = ranges::less,
2932 typename _Proj1 =
identity,
typename _Proj2 =
identity>
2933 requires mergeable<_Iter1, _Iter2, _Out, _Comp, _Proj1, _Proj2>
2934 constexpr set_intersection_result<_Iter1, _Iter2, _Out>
2935 operator()(_Iter1 __first1, _Sent1 __last1,
2936 _Iter2 __first2, _Sent2 __last2, _Out __result,
2938 _Proj1 __proj1 = {}, _Proj2 __proj2 = {})
const
2940 while (__first1 != __last1 && __first2 != __last2)
2951 *__result = *__first1;
2962 template<input_range _Range1, input_range _Range2, weakly_incrementable _Out,
2963 typename _Comp = ranges::less,
2964 typename _Proj1 = identity,
typename _Proj2 = identity>
2965 requires mergeable<iterator_t<_Range1>, iterator_t<_Range2>, _Out,
2966 _Comp, _Proj1, _Proj2>
2967 constexpr set_intersection_result<borrowed_iterator_t<_Range1>,
2968 borrowed_iterator_t<_Range2>, _Out>
2969 operator()(_Range1&& __r1, _Range2&& __r2, _Out __result,
2971 _Proj1 __proj1 = {}, _Proj2 __proj2 = {})
const
2980 inline constexpr __set_intersection_fn set_intersection{};
2982 template<
typename _Iter,
typename _Out>
2983 using set_difference_result = in_out_result<_Iter, _Out>;
2985 struct __set_difference_fn
2987 template<input_iterator _Iter1, sentinel_for<_Iter1> _Sent1,
2988 input_iterator _Iter2, sentinel_for<_Iter2> _Sent2,
2989 weakly_incrementable _Out,
typename _Comp = ranges::less,
2990 typename _Proj1 =
identity,
typename _Proj2 =
identity>
2991 requires mergeable<_Iter1, _Iter2, _Out, _Comp, _Proj1, _Proj2>
2992 constexpr set_difference_result<_Iter1, _Out>
2993 operator()(_Iter1 __first1, _Sent1 __last1,
2994 _Iter2 __first2, _Sent2 __last2, _Out __result,
2996 _Proj1 __proj1 = {}, _Proj2 __proj2 = {})
const
2998 while (__first1 != __last1 && __first2 != __last2)
3003 *__result = *__first1;
3020 template<input_range _Range1, input_range _Range2, weakly_incrementable _Out,
3021 typename _Comp = ranges::less,
3022 typename _Proj1 = identity,
typename _Proj2 = identity>
3023 requires mergeable<iterator_t<_Range1>, iterator_t<_Range2>, _Out,
3024 _Comp, _Proj1, _Proj2>
3025 constexpr set_difference_result<borrowed_iterator_t<_Range1>, _Out>
3026 operator()(_Range1&& __r1, _Range2&& __r2, _Out __result,
3028 _Proj1 __proj1 = {}, _Proj2 __proj2 = {})
const
3037 inline constexpr __set_difference_fn set_difference{};
3039 template<
typename _Iter1,
typename _Iter2,
typename _Out>
3040 using set_symmetric_difference_result
3041 = in_in_out_result<_Iter1, _Iter2, _Out>;
3043 struct __set_symmetric_difference_fn
3045 template<input_iterator _Iter1, sentinel_for<_Iter1> _Sent1,
3046 input_iterator _Iter2, sentinel_for<_Iter2> _Sent2,
3047 weakly_incrementable _Out,
typename _Comp = ranges::less,
3048 typename _Proj1 =
identity,
typename _Proj2 =
identity>
3049 requires mergeable<_Iter1, _Iter2, _Out, _Comp, _Proj1, _Proj2>
3050 constexpr set_symmetric_difference_result<_Iter1, _Iter2, _Out>
3051 operator()(_Iter1 __first1, _Sent1 __last1,
3052 _Iter2 __first2, _Sent2 __last2,
3053 _Out __result, _Comp __comp = {},
3054 _Proj1 __proj1 = {}, _Proj2 __proj2 = {})
const
3056 while (__first1 != __last1 && __first2 != __last2)
3061 *__result = *__first1;
3069 *__result = *__first2;
3086 template<input_range _Range1, input_range _Range2, weakly_incrementable _Out,
3087 typename _Comp = ranges::less,
3088 typename _Proj1 = identity,
typename _Proj2 = identity>
3089 requires mergeable<iterator_t<_Range1>, iterator_t<_Range2>, _Out,
3090 _Comp, _Proj1, _Proj2>
3091 constexpr set_symmetric_difference_result<borrowed_iterator_t<_Range1>,
3092 borrowed_iterator_t<_Range2>,
3094 operator()(_Range1&& __r1, _Range2&& __r2, _Out __result,
3096 _Proj1 __proj1 = {}, _Proj2 __proj2 = {})
const
3105 inline constexpr __set_symmetric_difference_fn set_symmetric_difference{};
3109 template<
typename _Tp,
typename _Proj = identity,
3110 indirect_strict_weak_order<projected<const _Tp*, _Proj>>
3111 _Comp = ranges::less>
3112 constexpr
const _Tp&
3113 operator()(
const _Tp& __a,
const _Tp& __b,
3114 _Comp __comp = {}, _Proj __proj = {})
const
3124 template<input_range _Range,
typename _Proj = identity,
3125 indirect_strict_weak_order<projected<iterator_t<_Range>, _Proj>>
3126 _Comp = ranges::less>
3127 requires indirectly_copyable_storable<iterator_t<_Range>,
3128 range_value_t<_Range>*>
3129 constexpr range_value_t<_Range>
3130 operator()(_Range&& __r, _Comp __comp = {}, _Proj __proj = {})
const
3134 __glibcxx_assert(__first != __last);
3135 auto __result = *__first;
3136 while (++__first != __last)
3138 auto __tmp = *__first;
3147 template<copyable _Tp,
typename _Proj = identity,
3148 indirect_strict_weak_order<projected<const _Tp*, _Proj>>
3149 _Comp = ranges::less>
3151 operator()(initializer_list<_Tp> __r,
3152 _Comp __comp = {}, _Proj __proj = {})
const
3154 return (*
this)(ranges::subrange(__r),
3159 inline constexpr __min_fn
min{};
3163 template<
typename _Tp,
typename _Proj = identity,
3164 indirect_strict_weak_order<projected<const _Tp*, _Proj>>
3165 _Comp = ranges::less>
3166 constexpr
const _Tp&
3167 operator()(
const _Tp& __a,
const _Tp& __b,
3168 _Comp __comp = {}, _Proj __proj = {})
const
3178 template<input_range _Range,
typename _Proj = identity,
3179 indirect_strict_weak_order<projected<iterator_t<_Range>, _Proj>>
3180 _Comp = ranges::less>
3181 requires indirectly_copyable_storable<iterator_t<_Range>,
3182 range_value_t<_Range>*>
3183 constexpr range_value_t<_Range>
3184 operator()(_Range&& __r, _Comp __comp = {}, _Proj __proj = {})
const
3188 __glibcxx_assert(__first != __last);
3189 auto __result = *__first;
3190 while (++__first != __last)
3192 auto __tmp = *__first;
3201 template<copyable _Tp,
typename _Proj = identity,
3202 indirect_strict_weak_order<projected<const _Tp*, _Proj>>
3203 _Comp = ranges::less>
3205 operator()(initializer_list<_Tp> __r,
3206 _Comp __comp = {}, _Proj __proj = {})
const
3208 return (*
this)(ranges::subrange(__r),
3213 inline constexpr __max_fn
max{};
3217 template<
typename _Tp,
typename _Proj = identity,
3218 indirect_strict_weak_order<projected<const _Tp*, _Proj>> _Comp
3220 constexpr
const _Tp&
3221 operator()(
const _Tp& __val,
const _Tp& __lo,
const _Tp& __hi,
3222 _Comp __comp = {}, _Proj __proj = {})
const
3237 inline constexpr __clamp_fn clamp{};
3239 template<
typename _Tp>
3240 struct min_max_result
3242 [[no_unique_address]] _Tp
min;
3243 [[no_unique_address]] _Tp
max;
3245 template<
typename _Tp2>
3246 requires convertible_to<const _Tp&, _Tp2>
3248 operator min_max_result<_Tp2>() const &
3251 template<
typename _Tp2>
3252 requires convertible_to<_Tp, _Tp2>
3254 operator min_max_result<_Tp2>() &&
3258 template<
typename _Tp>
3259 using minmax_result = min_max_result<_Tp>;
3263 template<
typename _Tp,
typename _Proj = identity,
3264 indirect_strict_weak_order<projected<const _Tp*, _Proj>>
3265 _Comp = ranges::less>
3266 constexpr minmax_result<const _Tp&>
3267 operator()(
const _Tp& __a,
const _Tp& __b,
3268 _Comp __comp = {}, _Proj __proj = {})
const
3278 template<input_range _Range,
typename _Proj = identity,
3279 indirect_strict_weak_order<projected<iterator_t<_Range>, _Proj>>
3280 _Comp = ranges::less>
3281 requires indirectly_copyable_storable<iterator_t<_Range>,
3282 range_value_t<_Range>*>
3283 constexpr minmax_result<range_value_t<_Range>>
3284 operator()(_Range&& __r, _Comp __comp = {}, _Proj __proj = {})
const
3288 __glibcxx_assert(__first != __last);
3289 minmax_result<range_value_t<_Range>> __result = {*__first, *__first};
3290 while (++__first != __last)
3292 auto __tmp = *__first;
3305 template<copyable _Tp,
typename _Proj = identity,
3306 indirect_strict_weak_order<projected<const _Tp*, _Proj>>
3307 _Comp = ranges::less>
3308 constexpr minmax_result<_Tp>
3309 operator()(initializer_list<_Tp> __r,
3310 _Comp __comp = {}, _Proj __proj = {})
const
3312 return (*
this)(ranges::subrange(__r),
3317 inline constexpr __minmax_fn
minmax{};
3319 struct __min_element_fn
3321 template<forward_iterator _Iter, sentinel_for<_Iter> _Sent,
3322 typename _Proj =
identity,
3323 indirect_strict_weak_order<projected<_Iter, _Proj>>
3324 _Comp = ranges::less>
3326 operator()(_Iter __first, _Sent __last,
3327 _Comp __comp = {}, _Proj __proj = {})
const
3329 if (__first == __last)
3333 while (++__i != __last)
3343 template<forward_range _Range,
typename _Proj = identity,
3344 indirect_strict_weak_order<projected<iterator_t<_Range>, _Proj>>
3345 _Comp = ranges::less>
3346 constexpr borrowed_iterator_t<_Range>
3347 operator()(_Range&& __r, _Comp __comp = {}, _Proj __proj = {})
const
3354 inline constexpr __min_element_fn min_element{};
3356 struct __max_element_fn
3358 template<forward_iterator _Iter, sentinel_for<_Iter> _Sent,
3359 typename _Proj =
identity,
3360 indirect_strict_weak_order<projected<_Iter, _Proj>>
3361 _Comp = ranges::less>
3363 operator()(_Iter __first, _Sent __last,
3364 _Comp __comp = {}, _Proj __proj = {})
const
3366 if (__first == __last)
3370 while (++__i != __last)
3380 template<forward_range _Range,
typename _Proj = identity,
3381 indirect_strict_weak_order<projected<iterator_t<_Range>, _Proj>>
3382 _Comp = ranges::less>
3383 constexpr borrowed_iterator_t<_Range>
3384 operator()(_Range&& __r, _Comp __comp = {}, _Proj __proj = {})
const
3391 inline constexpr __max_element_fn max_element{};
3393 template<
typename _Iter>
3394 using minmax_element_result = min_max_result<_Iter>;
3396 struct __minmax_element_fn
3398 template<forward_iterator _Iter, sentinel_for<_Iter> _Sent,
3399 typename _Proj =
identity,
3400 indirect_strict_weak_order<projected<_Iter, _Proj>>
3401 _Comp = ranges::less>
3402 constexpr minmax_element_result<_Iter>
3403 operator()(_Iter __first, _Sent __last,
3404 _Comp __comp = {}, _Proj __proj = {})
const
3406 if (__first == __last)
3407 return {__first, __first};
3409 minmax_element_result<_Iter> __result = {__first, __first};
3411 while (++__i != __last)
3425 template<forward_range _Range,
typename _Proj = identity,
3426 indirect_strict_weak_order<projected<iterator_t<_Range>, _Proj>>
3427 _Comp = ranges::less>
3428 constexpr minmax_element_result<borrowed_iterator_t<_Range>>
3429 operator()(_Range&& __r, _Comp __comp = {}, _Proj __proj = {})
const
3436 inline constexpr __minmax_element_fn minmax_element{};
3438 struct __lexicographical_compare_fn
3440 template<input_iterator _Iter1, sentinel_for<_Iter1> _Sent1,
3441 input_iterator _Iter2, sentinel_for<_Iter2> _Sent2,
3442 typename _Proj1 =
identity,
typename _Proj2 =
identity,
3443 indirect_strict_weak_order<projected<_Iter1, _Proj1>,
3444 projected<_Iter2, _Proj2>>
3445 _Comp = ranges::less>
3447 operator()(_Iter1 __first1, _Sent1 __last1,
3448 _Iter2 __first2, _Sent2 __last2,
3450 _Proj1 __proj1 = {}, _Proj2 __proj2 = {})
const
3452 if constexpr (__detail::__is_normal_iterator<_Iter1>
3453 || __detail::__is_normal_iterator<_Iter2>)
3454 return (*
this)(std::__niter_base(
std::move(__first1)),
3462 constexpr
bool __sized_iters
3463 = (sized_sentinel_for<_Sent1, _Iter1>
3464 && sized_sentinel_for<_Sent2, _Iter2>);
3465 if constexpr (__sized_iters)
3467 using _ValueType1 = iter_value_t<_Iter1>;
3468 using _ValueType2 = iter_value_t<_Iter2>;
3471 constexpr
bool __use_memcmp
3472 = (__is_byte<_ValueType1>::__value
3473 && __is_byte<_ValueType2>::__value
3474 && !__gnu_cxx::__numeric_traits<_ValueType1>::__is_signed
3475 && !__gnu_cxx::__numeric_traits<_ValueType2>::__is_signed
3476 && __ptr_to_nonvolatile<_Iter1>
3477 && __ptr_to_nonvolatile<_Iter2>
3478 && (is_same_v<_Comp, ranges::less>
3479 || is_same_v<_Comp, ranges::greater>)
3480 && is_same_v<_Proj1, identity>
3481 && is_same_v<_Proj2, identity>);
3482 if constexpr (__use_memcmp)
3484 const auto __d1 = __last1 - __first1;
3485 const auto __d2 = __last2 - __first2;
3487 if (
const auto __len =
std::min(__d1, __d2))
3490 = std::__memcmp(__first1, __first2, __len);
3491 if constexpr (is_same_v<_Comp, ranges::less>)
3498 else if constexpr (is_same_v<_Comp, ranges::greater>)
3510 for (; __first1 != __last1 && __first2 != __last2;
3511 ++__first1, (void) ++__first2)
3522 return __first1 == __last1 && __first2 != __last2;
3526 template<input_range _Range1, input_range _Range2,
3527 typename _Proj1 = identity,
typename _Proj2 = identity,
3528 indirect_strict_weak_order<projected<iterator_t<_Range1>, _Proj1>,
3529 projected<iterator_t<_Range2>, _Proj2>>
3530 _Comp = ranges::less>
3532 operator()(_Range1&& __r1, _Range2&& __r2, _Comp __comp = {},
3533 _Proj1 __proj1 = {}, _Proj2 __proj2 = {})
const
3542 template<
typename _Iter,
typename _Ref = iter_reference_t<_Iter>>
3543 static constexpr
bool __ptr_to_nonvolatile
3544 = is_pointer_v<_Iter> && !is_volatile_v<remove_reference_t<_Ref>>;
3547 inline constexpr __lexicographical_compare_fn lexicographical_compare;
3549 template<
typename _Iter>
3550 struct in_found_result
3552 [[no_unique_address]] _Iter in;
3555 template<
typename _Iter2>
3556 requires convertible_to<const _Iter&, _Iter2>
3558 operator in_found_result<_Iter2>() const &
3559 {
return {in, found}; }
3561 template<
typename _Iter2>
3562 requires convertible_to<_Iter, _Iter2>
3564 operator in_found_result<_Iter2>() &&
3568 template<
typename _Iter>
3569 using next_permutation_result = in_found_result<_Iter>;
3571 struct __next_permutation_fn
3573 template<b
idirectional_iterator _Iter, sentinel_for<_Iter> _Sent,
3574 typename _Comp = ranges::less,
typename _Proj =
identity>
3575 requires sortable<_Iter, _Comp, _Proj>
3576 constexpr next_permutation_result<_Iter>
3577 operator()(_Iter __first, _Sent __last,
3578 _Comp __comp = {}, _Proj __proj = {})
const
3580 if (__first == __last)
3588 auto __lasti = ranges::next(__first, __last);
3605 ranges::iter_swap(__i, __j);
3606 ranges::reverse(__ii, __last);
3611 ranges::reverse(__first, __last);
3617 template<bidirectional_range _Range,
typename _Comp = ranges::less,
3618 typename _Proj = identity>
3619 requires sortable<iterator_t<_Range>, _Comp, _Proj>
3620 constexpr next_permutation_result<borrowed_iterator_t<_Range>>
3621 operator()(_Range&& __r, _Comp __comp = {}, _Proj __proj = {})
const
3628 inline constexpr __next_permutation_fn next_permutation{};
3630 template<
typename _Iter>
3631 using prev_permutation_result = in_found_result<_Iter>;
3633 struct __prev_permutation_fn
3635 template<b
idirectional_iterator _Iter, sentinel_for<_Iter> _Sent,
3636 typename _Comp = ranges::less,
typename _Proj =
identity>
3637 requires sortable<_Iter, _Comp, _Proj>
3638 constexpr prev_permutation_result<_Iter>
3639 operator()(_Iter __first, _Sent __last,
3640 _Comp __comp = {}, _Proj __proj = {})
const
3642 if (__first == __last)
3650 auto __lasti = ranges::next(__first, __last);
3667 ranges::iter_swap(__i, __j);
3668 ranges::reverse(__ii, __last);
3673 ranges::reverse(__first, __last);
3679 template<bidirectional_range _Range,
typename _Comp = ranges::less,
3680 typename _Proj = identity>
3681 requires sortable<iterator_t<_Range>, _Comp, _Proj>
3682 constexpr prev_permutation_result<borrowed_iterator_t<_Range>>
3683 operator()(_Range&& __r, _Comp __comp = {}, _Proj __proj = {})
const
3690 inline constexpr __prev_permutation_fn prev_permutation{};
3694 template<
class ForwardIterator>
3695 constexpr ForwardIterator
3696 shift_left(ForwardIterator __first, ForwardIterator __last,
3697 typename iterator_traits<ForwardIterator>::difference_type __n)
3699 __glibcxx_assert(__n >= 0);
3703 auto __mid = ranges::next(__first, __n, __last);
3704 if (__mid == __last)
3709 template<
class ForwardIterator>
3710 constexpr ForwardIterator
3711 shift_right(ForwardIterator __first, ForwardIterator __last,
3712 typename iterator_traits<ForwardIterator>::difference_type __n)
3714 __glibcxx_assert(__n >= 0);
3718 using _Cat =
typename iterator_traits<ForwardIterator>::iterator_category;
3719 if constexpr (derived_from<_Cat, bidirectional_iterator_tag>)
3721 auto __mid = ranges::next(__last, -__n, __first);
3722 if (__mid == __first)
3730 auto __result = ranges::next(__first, __n, __last);
3731 if (__result == __last)
3734 auto __dest_head = __first, __dest_tail = __result;
3735 while (__dest_head != __result)
3737 if (__dest_tail == __last)
3762 auto __cursor = __first;
3763 while (__cursor != __result)
3765 if (__dest_tail == __last)
3770 __dest_head =
std::move(__cursor, __result,
3785 _GLIBCXX_END_NAMESPACE_VERSION
3789 #endif // _RANGES_ALGO_H