1 //===----------------------------------------------------------------------===//
2 //
3 // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
4 // See https://llvm.org/LICENSE.txt for license information.
5 // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
6 //
7 //===----------------------------------------------------------------------===//
8
9 #ifndef _LIBCPP___ALGORITHM_PSTL_ROTATE_COPY_H
10 #define _LIBCPP___ALGORITHM_PSTL_ROTATE_COPY_H
11
12 #include <__algorithm/pstl_backend.h>
13 #include <__algorithm/pstl_copy.h>
14 #include <__algorithm/pstl_frontend_dispatch.h>
15 #include <__type_traits/is_execution_policy.h>
16 #include <optional>
17
18 #if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER)
19 # pragma GCC system_header
20 #endif
21
22 #if !defined(_LIBCPP_HAS_NO_INCOMPLETE_PSTL) && _LIBCPP_STD_VER >= 17
23
24 _LIBCPP_BEGIN_NAMESPACE_STD
25
26 template <class>
27 void __pstl_rotate_copy();
28
29 template <class _ExecutionPolicy,
30 class _ForwardIterator,
31 class _ForwardOutIterator,
32 class _RawPolicy = __remove_cvref_t<_ExecutionPolicy>,
33 enable_if_t<is_execution_policy_v<_RawPolicy>, int> = 0>
34 [[nodiscard]] _LIBCPP_HIDE_FROM_ABI optional<_ForwardOutIterator>
__rotate_copy(_ExecutionPolicy && __policy,_ForwardIterator && __first,_ForwardIterator && __middle,_ForwardIterator && __last,_ForwardOutIterator && __result)35 __rotate_copy(_ExecutionPolicy&& __policy,
36 _ForwardIterator&& __first,
37 _ForwardIterator&& __middle,
38 _ForwardIterator&& __last,
39 _ForwardOutIterator&& __result) noexcept {
40 return std::__pstl_frontend_dispatch(
41 _LIBCPP_PSTL_CUSTOMIZATION_POINT(__pstl_rotate_copy, _RawPolicy),
42 [&__policy](_ForwardIterator __g_first,
43 _ForwardIterator __g_middle,
44 _ForwardIterator __g_last,
45 _ForwardOutIterator __g_result) -> optional<_ForwardOutIterator> {
46 auto __result_mid =
47 std::__copy(__policy, _ForwardIterator(__g_middle), std::move(__g_last), std::move(__g_result));
48 if (!__result_mid)
49 return nullopt;
50 return std::__copy(__policy, std::move(__g_first), std::move(__g_middle), *std::move(__result_mid));
51 },
52 std::move(__first),
53 std::move(__middle),
54 std::move(__last),
55 std::move(__result));
56 }
57
58 template <class _ExecutionPolicy,
59 class _ForwardIterator,
60 class _ForwardOutIterator,
61 class _RawPolicy = __remove_cvref_t<_ExecutionPolicy>,
62 enable_if_t<is_execution_policy_v<_RawPolicy>, int> = 0>
rotate_copy(_ExecutionPolicy && __policy,_ForwardIterator __first,_ForwardIterator __middle,_ForwardIterator __last,_ForwardOutIterator __result)63 _LIBCPP_HIDE_FROM_ABI _ForwardOutIterator rotate_copy(
64 _ExecutionPolicy&& __policy,
65 _ForwardIterator __first,
66 _ForwardIterator __middle,
67 _ForwardIterator __last,
68 _ForwardOutIterator __result) {
69 auto __res =
70 std::__rotate_copy(__policy, std::move(__first), std::move(__middle), std::move(__last), std::move(__result));
71 if (!__res)
72 std::__throw_bad_alloc();
73 return *__res;
74 }
75
76 _LIBCPP_END_NAMESPACE_STD
77
78 #endif // !defined(_LIBCPP_HAS_NO_INCOMPLETE_PSTL) && _LIBCPP_STD_VER >= 17
79
80 #endif // _LIBCPP___ALGORITHM_PSTL_ROTATE_COPY_H
81