Back to home page

EIC code displayed by LXR

 
 

    


File indexing completed on 2026-05-03 08:13:58

0001 //===----------------------------------------------------------------------===//
0002 //
0003 // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
0004 // See https://llvm.org/LICENSE.txt for license information.
0005 // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
0006 //
0007 //===----------------------------------------------------------------------===//
0008 
0009 #ifndef _LIBCPP___PSTL_BACKENDS_DEFAULT_H
0010 #define _LIBCPP___PSTL_BACKENDS_DEFAULT_H
0011 
0012 #include <__algorithm/copy_n.h>
0013 #include <__algorithm/equal.h>
0014 #include <__algorithm/fill_n.h>
0015 #include <__algorithm/for_each_n.h>
0016 #include <__config>
0017 #include <__functional/identity.h>
0018 #include <__functional/not_fn.h>
0019 #include <__functional/operations.h>
0020 #include <__iterator/concepts.h>
0021 #include <__iterator/iterator_traits.h>
0022 #include <__pstl/backend_fwd.h>
0023 #include <__pstl/dispatch.h>
0024 #include <__utility/empty.h>
0025 #include <__utility/forward.h>
0026 #include <__utility/move.h>
0027 #include <optional>
0028 
0029 #if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER)
0030 #  pragma GCC system_header
0031 #endif
0032 
0033 _LIBCPP_PUSH_MACROS
0034 #include <__undef_macros>
0035 
0036 #if _LIBCPP_STD_VER >= 17
0037 
0038 _LIBCPP_BEGIN_NAMESPACE_STD
0039 namespace __pstl {
0040 
0041 //
0042 // This file provides an incomplete PSTL backend that implements all of the PSTL algorithms
0043 // based on a smaller set of basis operations.
0044 //
0045 // It is intended as a building block for other PSTL backends that implement some operations more
0046 // efficiently but may not want to define the full set of PSTL algorithms.
0047 //
0048 // This backend implements all the PSTL algorithms based on the following basis operations:
0049 //
0050 // find_if family
0051 // --------------
0052 // - find
0053 // - find_if_not
0054 // - any_of
0055 // - all_of
0056 // - none_of
0057 // - is_partitioned
0058 //
0059 // for_each family
0060 // ---------------
0061 // - for_each_n
0062 // - fill
0063 // - fill_n
0064 // - replace
0065 // - replace_if
0066 // - generate
0067 // - generate_n
0068 //
0069 // merge family
0070 // ------------
0071 // No other algorithms based on merge
0072 //
0073 // stable_sort family
0074 // ------------------
0075 // - sort
0076 //
0077 // transform_reduce and transform_reduce_binary family
0078 // ---------------------------------------------------
0079 // - count_if
0080 // - count
0081 // - equal(3 legs)
0082 // - equal
0083 // - reduce
0084 //
0085 // transform and transform_binary family
0086 // -------------------------------------
0087 // - replace_copy_if
0088 // - replace_copy
0089 // - move
0090 // - copy
0091 // - copy_n
0092 // - rotate_copy
0093 //
0094 
0095 //////////////////////////////////////////////////////////////
0096 // find_if family
0097 //////////////////////////////////////////////////////////////
0098 template <class _ExecutionPolicy>
0099 struct __find<__default_backend_tag, _ExecutionPolicy> {
0100   template <class _Policy, class _ForwardIterator, class _Tp>
0101   [[nodiscard]] _LIBCPP_HIDE_FROM_ABI optional<_ForwardIterator>
0102   operator()(_Policy&& __policy, _ForwardIterator __first, _ForwardIterator __last, const _Tp& __value) const noexcept {
0103     using _FindIf = __dispatch<__find_if, __current_configuration, _ExecutionPolicy>;
0104     return _FindIf()(
0105         __policy, std::move(__first), std::move(__last), [&](__iter_reference<_ForwardIterator> __element) {
0106           return __element == __value;
0107         });
0108   }
0109 };
0110 
0111 template <class _ExecutionPolicy>
0112 struct __find_if_not<__default_backend_tag, _ExecutionPolicy> {
0113   template <class _Policy, class _ForwardIterator, class _Pred>
0114   [[nodiscard]] _LIBCPP_HIDE_FROM_ABI optional<_ForwardIterator>
0115   operator()(_Policy&& __policy, _ForwardIterator __first, _ForwardIterator __last, _Pred&& __pred) const noexcept {
0116     using _FindIf = __dispatch<__find_if, __current_configuration, _ExecutionPolicy>;
0117     return _FindIf()(__policy, __first, __last, std::not_fn(std::forward<_Pred>(__pred)));
0118   }
0119 };
0120 
0121 template <class _ExecutionPolicy>
0122 struct __any_of<__default_backend_tag, _ExecutionPolicy> {
0123   template <class _Policy, class _ForwardIterator, class _Pred>
0124   [[nodiscard]] _LIBCPP_HIDE_FROM_ABI optional<bool>
0125   operator()(_Policy&& __policy, _ForwardIterator __first, _ForwardIterator __last, _Pred&& __pred) const noexcept {
0126     using _FindIf = __dispatch<__find_if, __current_configuration, _ExecutionPolicy>;
0127     auto __res    = _FindIf()(__policy, __first, __last, std::forward<_Pred>(__pred));
0128     if (!__res)
0129       return nullopt;
0130     return *__res != __last;
0131   }
0132 };
0133 
0134 template <class _ExecutionPolicy>
0135 struct __all_of<__default_backend_tag, _ExecutionPolicy> {
0136   template <class _Policy, class _ForwardIterator, class _Pred>
0137   [[nodiscard]] _LIBCPP_HIDE_FROM_ABI optional<bool>
0138   operator()(_Policy&& __policy, _ForwardIterator __first, _ForwardIterator __last, _Pred&& __pred) const noexcept {
0139     using _AnyOf = __dispatch<__any_of, __current_configuration, _ExecutionPolicy>;
0140     auto __res   = _AnyOf()(__policy, __first, __last, [&](__iter_reference<_ForwardIterator> __value) {
0141       return !__pred(__value);
0142     });
0143     if (!__res)
0144       return nullopt;
0145     return !*__res;
0146   }
0147 };
0148 
0149 template <class _ExecutionPolicy>
0150 struct __none_of<__default_backend_tag, _ExecutionPolicy> {
0151   template <class _Policy, class _ForwardIterator, class _Pred>
0152   [[nodiscard]] _LIBCPP_HIDE_FROM_ABI optional<bool>
0153   operator()(_Policy&& __policy, _ForwardIterator __first, _ForwardIterator __last, _Pred&& __pred) const noexcept {
0154     using _AnyOf = __dispatch<__any_of, __current_configuration, _ExecutionPolicy>;
0155     auto __res   = _AnyOf()(__policy, __first, __last, std::forward<_Pred>(__pred));
0156     if (!__res)
0157       return nullopt;
0158     return !*__res;
0159   }
0160 };
0161 
0162 template <class _ExecutionPolicy>
0163 struct __is_partitioned<__default_backend_tag, _ExecutionPolicy> {
0164   template <class _Policy, class _ForwardIterator, class _Pred>
0165   [[nodiscard]] _LIBCPP_HIDE_FROM_ABI optional<bool>
0166   operator()(_Policy&& __policy, _ForwardIterator __first, _ForwardIterator __last, _Pred&& __pred) const noexcept {
0167     using _FindIfNot   = __dispatch<__find_if_not, __current_configuration, _ExecutionPolicy>;
0168     auto __maybe_first = _FindIfNot()(__policy, std::move(__first), __last, __pred);
0169     if (__maybe_first == nullopt)
0170       return nullopt;
0171 
0172     __first = *__maybe_first;
0173     if (__first == __last)
0174       return true;
0175     ++__first;
0176     using _NoneOf = __dispatch<__none_of, __current_configuration, _ExecutionPolicy>;
0177     return _NoneOf()(__policy, std::move(__first), std::move(__last), __pred);
0178   }
0179 };
0180 
0181 //////////////////////////////////////////////////////////////
0182 // for_each family
0183 //////////////////////////////////////////////////////////////
0184 template <class _ExecutionPolicy>
0185 struct __for_each_n<__default_backend_tag, _ExecutionPolicy> {
0186   template <class _Policy, class _ForwardIterator, class _Size, class _Function>
0187   [[nodiscard]] _LIBCPP_HIDE_FROM_ABI optional<__empty>
0188   operator()(_Policy&& __policy, _ForwardIterator __first, _Size __size, _Function __func) const noexcept {
0189     if constexpr (__has_random_access_iterator_category_or_concept<_ForwardIterator>::value) {
0190       using _ForEach          = __dispatch<__for_each, __current_configuration, _ExecutionPolicy>;
0191       _ForwardIterator __last = __first + __size;
0192       return _ForEach()(__policy, std::move(__first), std::move(__last), std::move(__func));
0193     } else {
0194       // Otherwise, use the serial algorithm to avoid doing two passes over the input
0195       std::for_each_n(std::move(__first), __size, std::move(__func));
0196       return __empty{};
0197     }
0198   }
0199 };
0200 
0201 template <class _ExecutionPolicy>
0202 struct __fill<__default_backend_tag, _ExecutionPolicy> {
0203   template <class _Policy, class _ForwardIterator, class _Tp>
0204   [[nodiscard]] _LIBCPP_HIDE_FROM_ABI optional<__empty>
0205   operator()(_Policy&& __policy, _ForwardIterator __first, _ForwardIterator __last, _Tp const& __value) const noexcept {
0206     using _ForEach = __dispatch<__for_each, __current_configuration, _ExecutionPolicy>;
0207     using _Ref     = __iter_reference<_ForwardIterator>;
0208     return _ForEach()(__policy, std::move(__first), std::move(__last), [&](_Ref __element) { __element = __value; });
0209   }
0210 };
0211 
0212 template <class _ExecutionPolicy>
0213 struct __fill_n<__default_backend_tag, _ExecutionPolicy> {
0214   template <class _Policy, class _ForwardIterator, class _Size, class _Tp>
0215   [[nodiscard]] _LIBCPP_HIDE_FROM_ABI optional<__empty>
0216   operator()(_Policy&& __policy, _ForwardIterator __first, _Size __n, _Tp const& __value) const noexcept {
0217     if constexpr (__has_random_access_iterator_category_or_concept<_ForwardIterator>::value) {
0218       using _Fill             = __dispatch<__fill, __current_configuration, _ExecutionPolicy>;
0219       _ForwardIterator __last = __first + __n;
0220       return _Fill()(__policy, std::move(__first), std::move(__last), __value);
0221     } else {
0222       // Otherwise, use the serial algorithm to avoid doing two passes over the input
0223       std::fill_n(std::move(__first), __n, __value);
0224       return optional<__empty>{__empty{}};
0225     }
0226   }
0227 };
0228 
0229 template <class _ExecutionPolicy>
0230 struct __replace<__default_backend_tag, _ExecutionPolicy> {
0231   template <class _Policy, class _ForwardIterator, class _Tp>
0232   [[nodiscard]] _LIBCPP_HIDE_FROM_ABI optional<__empty>
0233   operator()(_Policy&& __policy, _ForwardIterator __first, _ForwardIterator __last, _Tp const& __old, _Tp const& __new)
0234       const noexcept {
0235     using _ReplaceIf = __dispatch<__replace_if, __current_configuration, _ExecutionPolicy>;
0236     using _Ref       = __iter_reference<_ForwardIterator>;
0237     return _ReplaceIf()(
0238         __policy, std::move(__first), std::move(__last), [&](_Ref __element) { return __element == __old; }, __new);
0239   }
0240 };
0241 
0242 template <class _ExecutionPolicy>
0243 struct __replace_if<__default_backend_tag, _ExecutionPolicy> {
0244   template <class _Policy, class _ForwardIterator, class _Pred, class _Tp>
0245   [[nodiscard]] _LIBCPP_HIDE_FROM_ABI optional<__empty> operator()(
0246       _Policy&& __policy, _ForwardIterator __first, _ForwardIterator __last, _Pred&& __pred, _Tp const& __new_value)
0247       const noexcept {
0248     using _ForEach = __dispatch<__for_each, __current_configuration, _ExecutionPolicy>;
0249     using _Ref     = __iter_reference<_ForwardIterator>;
0250     return _ForEach()(__policy, std::move(__first), std::move(__last), [&](_Ref __element) {
0251       if (__pred(__element))
0252         __element = __new_value;
0253     });
0254   }
0255 };
0256 
0257 template <class _ExecutionPolicy>
0258 struct __generate<__default_backend_tag, _ExecutionPolicy> {
0259   template <class _Policy, class _ForwardIterator, class _Generator>
0260   [[nodiscard]] _LIBCPP_HIDE_FROM_ABI optional<__empty>
0261   operator()(_Policy&& __policy, _ForwardIterator __first, _ForwardIterator __last, _Generator&& __gen) const noexcept {
0262     using _ForEach = __dispatch<__for_each, __current_configuration, _ExecutionPolicy>;
0263     using _Ref     = __iter_reference<_ForwardIterator>;
0264     return _ForEach()(__policy, std::move(__first), std::move(__last), [&](_Ref __element) { __element = __gen(); });
0265   }
0266 };
0267 
0268 template <class _ExecutionPolicy>
0269 struct __generate_n<__default_backend_tag, _ExecutionPolicy> {
0270   template <class _Policy, class _ForwardIterator, class _Size, class _Generator>
0271   [[nodiscard]] _LIBCPP_HIDE_FROM_ABI optional<__empty>
0272   operator()(_Policy&& __policy, _ForwardIterator __first, _Size __n, _Generator&& __gen) const noexcept {
0273     using _ForEachN = __dispatch<__for_each_n, __current_configuration, _ExecutionPolicy>;
0274     using _Ref      = __iter_reference<_ForwardIterator>;
0275     return _ForEachN()(__policy, std::move(__first), __n, [&](_Ref __element) { __element = __gen(); });
0276   }
0277 };
0278 
0279 //////////////////////////////////////////////////////////////
0280 // stable_sort family
0281 //////////////////////////////////////////////////////////////
0282 template <class _ExecutionPolicy>
0283 struct __sort<__default_backend_tag, _ExecutionPolicy> {
0284   template <class _Policy, class _RandomAccessIterator, class _Comp>
0285   _LIBCPP_HIDE_FROM_ABI optional<__empty> operator()(
0286       _Policy&& __policy, _RandomAccessIterator __first, _RandomAccessIterator __last, _Comp&& __comp) const noexcept {
0287     using _StableSort = __dispatch<__stable_sort, __current_configuration, _ExecutionPolicy>;
0288     return _StableSort()(__policy, std::move(__first), std::move(__last), std::forward<_Comp>(__comp));
0289   }
0290 };
0291 
0292 //////////////////////////////////////////////////////////////
0293 // transform_reduce family
0294 //////////////////////////////////////////////////////////////
0295 template <class _ExecutionPolicy>
0296 struct __count_if<__default_backend_tag, _ExecutionPolicy> {
0297   template <class _Policy, class _ForwardIterator, class _Predicate>
0298   [[nodiscard]] _LIBCPP_HIDE_FROM_ABI optional<__iter_diff_t<_ForwardIterator>> operator()(
0299       _Policy&& __policy, _ForwardIterator __first, _ForwardIterator __last, _Predicate&& __pred) const noexcept {
0300     using _TransformReduce = __dispatch<__transform_reduce, __current_configuration, _ExecutionPolicy>;
0301     using _DiffT           = __iter_diff_t<_ForwardIterator>;
0302     using _Ref             = __iter_reference<_ForwardIterator>;
0303     return _TransformReduce()(
0304         __policy, std::move(__first), std::move(__last), _DiffT{}, std::plus{}, [&](_Ref __element) -> _DiffT {
0305           return __pred(__element) ? _DiffT(1) : _DiffT(0);
0306         });
0307   }
0308 };
0309 
0310 template <class _ExecutionPolicy>
0311 struct __count<__default_backend_tag, _ExecutionPolicy> {
0312   template <class _Policy, class _ForwardIterator, class _Tp>
0313   [[nodiscard]] _LIBCPP_HIDE_FROM_ABI optional<__iter_diff_t<_ForwardIterator>>
0314   operator()(_Policy&& __policy, _ForwardIterator __first, _ForwardIterator __last, _Tp const& __value) const noexcept {
0315     using _CountIf = __dispatch<__count_if, __current_configuration, _ExecutionPolicy>;
0316     using _Ref     = __iter_reference<_ForwardIterator>;
0317     return _CountIf()(__policy, std::move(__first), std::move(__last), [&](_Ref __element) -> bool {
0318       return __element == __value;
0319     });
0320   }
0321 };
0322 
0323 template <class _ExecutionPolicy>
0324 struct __equal_3leg<__default_backend_tag, _ExecutionPolicy> {
0325   template <class _Policy, class _ForwardIterator1, class _ForwardIterator2, class _Predicate>
0326   [[nodiscard]] _LIBCPP_HIDE_FROM_ABI optional<bool>
0327   operator()(_Policy&& __policy,
0328              _ForwardIterator1 __first1,
0329              _ForwardIterator1 __last1,
0330              _ForwardIterator2 __first2,
0331              _Predicate&& __pred) const noexcept {
0332     using _TransformReduce = __dispatch<__transform_reduce_binary, __current_configuration, _ExecutionPolicy>;
0333     return _TransformReduce()(
0334         __policy,
0335         std::move(__first1),
0336         std::move(__last1),
0337         std::move(__first2),
0338         true,
0339         std::logical_and{},
0340         std::forward<_Predicate>(__pred));
0341   }
0342 };
0343 
0344 template <class _ExecutionPolicy>
0345 struct __equal<__default_backend_tag, _ExecutionPolicy> {
0346   template <class _Policy, class _ForwardIterator1, class _ForwardIterator2, class _Predicate>
0347   [[nodiscard]] _LIBCPP_HIDE_FROM_ABI optional<bool>
0348   operator()(_Policy&& __policy,
0349              _ForwardIterator1 __first1,
0350              _ForwardIterator1 __last1,
0351              _ForwardIterator2 __first2,
0352              _ForwardIterator2 __last2,
0353              _Predicate&& __pred) const noexcept {
0354     if constexpr (__has_random_access_iterator_category<_ForwardIterator1>::value &&
0355                   __has_random_access_iterator_category<_ForwardIterator2>::value) {
0356       if (__last1 - __first1 != __last2 - __first2)
0357         return false;
0358       // Fall back to the 3 legged algorithm
0359       using _Equal3Leg = __dispatch<__equal_3leg, __current_configuration, _ExecutionPolicy>;
0360       return _Equal3Leg()(
0361           __policy, std::move(__first1), std::move(__last1), std::move(__first2), std::forward<_Predicate>(__pred));
0362     } else {
0363       // If we don't have random access, fall back to the serial algorithm cause we can't do much
0364       return std::equal(
0365           std::move(__first1),
0366           std::move(__last1),
0367           std::move(__first2),
0368           std::move(__last2),
0369           std::forward<_Predicate>(__pred));
0370     }
0371   }
0372 };
0373 
0374 template <class _ExecutionPolicy>
0375 struct __reduce<__default_backend_tag, _ExecutionPolicy> {
0376   template <class _Policy, class _ForwardIterator, class _Tp, class _BinaryOperation>
0377   [[nodiscard]] _LIBCPP_HIDE_FROM_ABI optional<_Tp>
0378   operator()(_Policy&& __policy, _ForwardIterator __first, _ForwardIterator __last, _Tp __init, _BinaryOperation&& __op)
0379       const noexcept {
0380     using _TransformReduce = __dispatch<__transform_reduce, __current_configuration, _ExecutionPolicy>;
0381     return _TransformReduce()(
0382         __policy,
0383         std::move(__first),
0384         std::move(__last),
0385         std::move(__init),
0386         std::forward<_BinaryOperation>(__op),
0387         __identity{});
0388   }
0389 };
0390 
0391 //////////////////////////////////////////////////////////////
0392 // transform family
0393 //////////////////////////////////////////////////////////////
0394 template <class _ExecutionPolicy>
0395 struct __replace_copy_if<__default_backend_tag, _ExecutionPolicy> {
0396   template <class _Policy, class _ForwardIterator, class _ForwardOutIterator, class _Pred, class _Tp>
0397   [[nodiscard]] _LIBCPP_HIDE_FROM_ABI optional<__empty>
0398   operator()(_Policy&& __policy,
0399              _ForwardIterator __first,
0400              _ForwardIterator __last,
0401              _ForwardOutIterator __out_it,
0402              _Pred&& __pred,
0403              _Tp const& __new_value) const noexcept {
0404     using _Transform = __dispatch<__transform, __current_configuration, _ExecutionPolicy>;
0405     using _Ref       = __iter_reference<_ForwardIterator>;
0406     auto __res =
0407         _Transform()(__policy, std::move(__first), std::move(__last), std::move(__out_it), [&](_Ref __element) {
0408           return __pred(__element) ? __new_value : __element;
0409         });
0410     if (__res == nullopt)
0411       return nullopt;
0412     return __empty{};
0413   }
0414 };
0415 
0416 template <class _ExecutionPolicy>
0417 struct __replace_copy<__default_backend_tag, _ExecutionPolicy> {
0418   template <class _Policy, class _ForwardIterator, class _ForwardOutIterator, class _Tp>
0419   [[nodiscard]] _LIBCPP_HIDE_FROM_ABI optional<__empty>
0420   operator()(_Policy&& __policy,
0421              _ForwardIterator __first,
0422              _ForwardIterator __last,
0423              _ForwardOutIterator __out_it,
0424              _Tp const& __old_value,
0425              _Tp const& __new_value) const noexcept {
0426     using _ReplaceCopyIf = __dispatch<__replace_copy_if, __current_configuration, _ExecutionPolicy>;
0427     using _Ref           = __iter_reference<_ForwardIterator>;
0428     return _ReplaceCopyIf()(
0429         __policy,
0430         std::move(__first),
0431         std::move(__last),
0432         std::move(__out_it),
0433         [&](_Ref __element) { return __element == __old_value; },
0434         __new_value);
0435   }
0436 };
0437 
0438 // TODO: Use the std::copy/move shenanigans to forward to std::memmove
0439 //       Investigate whether we want to still forward to std::transform(policy)
0440 //       in that case for the execution::par part, or whether we actually want
0441 //       to run everything serially in that case.
0442 template <class _ExecutionPolicy>
0443 struct __move<__default_backend_tag, _ExecutionPolicy> {
0444   template <class _Policy, class _ForwardIterator, class _ForwardOutIterator>
0445   [[nodiscard]] _LIBCPP_HIDE_FROM_ABI optional<_ForwardOutIterator>
0446   operator()(_Policy&& __policy, _ForwardIterator __first, _ForwardIterator __last, _ForwardOutIterator __out_it)
0447       const noexcept {
0448     using _Transform = __dispatch<__transform, __current_configuration, _ExecutionPolicy>;
0449     return _Transform()(__policy, std::move(__first), std::move(__last), std::move(__out_it), [&](auto&& __element) {
0450       return std::move(__element);
0451     });
0452   }
0453 };
0454 
0455 // TODO: Use the std::copy/move shenanigans to forward to std::memmove
0456 template <class _ExecutionPolicy>
0457 struct __copy<__default_backend_tag, _ExecutionPolicy> {
0458   template <class _Policy, class _ForwardIterator, class _ForwardOutIterator>
0459   [[nodiscard]] _LIBCPP_HIDE_FROM_ABI optional<_ForwardOutIterator>
0460   operator()(_Policy&& __policy, _ForwardIterator __first, _ForwardIterator __last, _ForwardOutIterator __out_it)
0461       const noexcept {
0462     using _Transform = __dispatch<__transform, __current_configuration, _ExecutionPolicy>;
0463     return _Transform()(__policy, std::move(__first), std::move(__last), std::move(__out_it), __identity());
0464   }
0465 };
0466 
0467 template <class _ExecutionPolicy>
0468 struct __copy_n<__default_backend_tag, _ExecutionPolicy> {
0469   template <class _Policy, class _ForwardIterator, class _Size, class _ForwardOutIterator>
0470   [[nodiscard]] _LIBCPP_HIDE_FROM_ABI optional<_ForwardOutIterator>
0471   operator()(_Policy&& __policy, _ForwardIterator __first, _Size __n, _ForwardOutIterator __out_it) const noexcept {
0472     if constexpr (__has_random_access_iterator_category_or_concept<_ForwardIterator>::value) {
0473       using _Copy             = __dispatch<__copy, __current_configuration, _ExecutionPolicy>;
0474       _ForwardIterator __last = __first + __n;
0475       return _Copy()(__policy, std::move(__first), std::move(__last), std::move(__out_it));
0476     } else {
0477       // Otherwise, use the serial algorithm to avoid doing two passes over the input
0478       return std::copy_n(std::move(__first), __n, std::move(__out_it));
0479     }
0480   }
0481 };
0482 
0483 template <class _ExecutionPolicy>
0484 struct __rotate_copy<__default_backend_tag, _ExecutionPolicy> {
0485   template <class _Policy, class _ForwardIterator, class _ForwardOutIterator>
0486   [[nodiscard]] _LIBCPP_HIDE_FROM_ABI optional<_ForwardOutIterator>
0487   operator()(_Policy&& __policy,
0488              _ForwardIterator __first,
0489              _ForwardIterator __middle,
0490              _ForwardIterator __last,
0491              _ForwardOutIterator __out_it) const noexcept {
0492     using _Copy       = __dispatch<__copy, __current_configuration, _ExecutionPolicy>;
0493     auto __result_mid = _Copy()(__policy, __middle, std::move(__last), std::move(__out_it));
0494     if (__result_mid == nullopt)
0495       return nullopt;
0496     return _Copy()(__policy, std::move(__first), std::move(__middle), *std::move(__result_mid));
0497   }
0498 };
0499 
0500 } // namespace __pstl
0501 _LIBCPP_END_NAMESPACE_STD
0502 
0503 #endif // _LIBCPP_STD_VER >= 17
0504 
0505 _LIBCPP_POP_MACROS
0506 
0507 #endif // _LIBCPP___PSTL_BACKENDS_DEFAULT_H