1 //===----------------------------------------------------------------------===//
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
7 //===----------------------------------------------------------------------===//
9 #ifndef _LIBCPP___ALGORITHM_PSTL_MOVE_H
10 #define _LIBCPP___ALGORITHM_PSTL_MOVE_H
12 #include <__algorithm/copy_n.h>
13 #include <__algorithm/pstl_frontend_dispatch.h>
14 #include <__algorithm/pstl_transform.h>
16 #include <__functional/identity.h>
17 #include <__iterator/iterator_traits.h>
18 #include <__type_traits/enable_if.h>
19 #include <__type_traits/is_constant_evaluated.h>
20 #include <__type_traits/is_execution_policy.h>
21 #include <__type_traits/is_trivially_copyable.h>
22 #include <__type_traits/remove_cvref.h>
25 #if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER)
26 # pragma GCC system_header
29 #if !defined(_LIBCPP_HAS_NO_INCOMPLETE_PSTL) && _LIBCPP_STD_VER >= 17
31 _LIBCPP_BEGIN_NAMESPACE_STD
33 // TODO: Use the std::copy/move shenanigans to forward to std::memmove
34 // Investigate whether we want to still forward to std::transform(policy)
35 // in that case for the execution::par part, or whether we actually want
36 // to run everything serially in that case.
41 template <class _ExecutionPolicy
,
42 class _ForwardIterator
,
43 class _ForwardOutIterator
,
44 class _RawPolicy
= __remove_cvref_t
<_ExecutionPolicy
>,
45 enable_if_t
<is_execution_policy_v
<_RawPolicy
>, int> = 0>
46 [[nodiscard
]] _LIBCPP_HIDE_FROM_ABI optional
<_ForwardOutIterator
>
47 __move(_ExecutionPolicy
&& __policy
,
48 _ForwardIterator
&& __first
,
49 _ForwardIterator
&& __last
,
50 _ForwardOutIterator
&& __result
) noexcept
{
51 return std::__pstl_frontend_dispatch(
52 _LIBCPP_PSTL_CUSTOMIZATION_POINT(__pstl_move
, _RawPolicy
),
53 [&__policy
](_ForwardIterator __g_first
, _ForwardIterator __g_last
, _ForwardOutIterator __g_result
) {
54 return std::__transform(__policy
, __g_first
, __g_last
, __g_result
, [](auto&& __v
) { return std::move(__v
); });
61 template <class _ExecutionPolicy
,
62 class _ForwardIterator
,
63 class _ForwardOutIterator
,
64 class _RawPolicy
= __remove_cvref_t
<_ExecutionPolicy
>,
65 enable_if_t
<is_execution_policy_v
<_RawPolicy
>, int> = 0>
66 _LIBCPP_HIDE_FROM_ABI _ForwardOutIterator
67 move(_ExecutionPolicy
&& __policy
, _ForwardIterator __first
, _ForwardIterator __last
, _ForwardOutIterator __result
) {
68 auto __res
= std::__move(__policy
, std::move(__first
), std::move(__last
), std::move(__result
));
70 std::__throw_bad_alloc();
74 _LIBCPP_END_NAMESPACE_STD
76 #endif // !defined(_LIBCPP_HAS_NO_INCOMPLETE_PSTL) && _LIBCPP_STD_VER >= 17
78 #endif // _LIBCPP___ALGORITHM_PSTL_MOVE_H