Run DCE after a LoopFlatten test to reduce spurious output [nfc]
[llvm-project.git] / libcxx / include / __algorithm / pstl_move.h
blob775dc2604931309814c6c052c7e23c6518ab1960
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 //===----------------------------------------------------------------------===//
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>
15 #include <__config>
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>
23 #include <optional>
25 #if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER)
26 # pragma GCC system_header
27 #endif
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.
38 template <class>
39 void __pstl_move();
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); });
56 std::move(__first),
57 std::move(__last),
58 std::move(__result));
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));
69 if (!__res)
70 std::__throw_bad_alloc();
71 return *__res;
74 _LIBCPP_END_NAMESPACE_STD
76 #endif // !defined(_LIBCPP_HAS_NO_INCOMPLETE_PSTL) && _LIBCPP_STD_VER >= 17
78 #endif // _LIBCPP___ALGORITHM_PSTL_MOVE_H