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_MOVE_H 10#define _LIBCPP___ALGORITHM_PSTL_MOVE_H 11 12#include <__algorithm/copy_n.h> 13#include <__algorithm/pstl_backend.h> 14#include <__algorithm/pstl_frontend_dispatch.h> 15#include <__algorithm/pstl_transform.h> 16#include <__config> 17#include <__functional/identity.h> 18#include <__iterator/iterator_traits.h> 19#include <__type_traits/enable_if.h> 20#include <__type_traits/is_constant_evaluated.h> 21#include <__type_traits/is_execution_policy.h> 22#include <__type_traits/is_trivially_copyable.h> 23#include <__type_traits/remove_cvref.h> 24#include <optional> 25 26#if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER) 27# pragma GCC system_header 28#endif 29 30_LIBCPP_PUSH_MACROS 31#include <__undef_macros> 32 33#if !defined(_LIBCPP_HAS_NO_INCOMPLETE_PSTL) && _LIBCPP_STD_VER >= 17 34 35_LIBCPP_BEGIN_NAMESPACE_STD 36 37// TODO: Use the std::copy/move shenanigans to forward to std::memmove 38// Investigate whether we want to still forward to std::transform(policy) 39// in that case for the execution::par part, or whether we actually want 40// to run everything serially in that case. 41 42template <class> 43void __pstl_move(); 44 45template <class _ExecutionPolicy, 46 class _ForwardIterator, 47 class _ForwardOutIterator, 48 class _RawPolicy = __remove_cvref_t<_ExecutionPolicy>, 49 enable_if_t<is_execution_policy_v<_RawPolicy>, int> = 0> 50[[nodiscard]] _LIBCPP_HIDE_FROM_ABI optional<_ForwardOutIterator> 51__move(_ExecutionPolicy&& __policy, 52 _ForwardIterator&& __first, 53 _ForwardIterator&& __last, 54 _ForwardOutIterator&& __result) noexcept { 55 return std::__pstl_frontend_dispatch( 56 _LIBCPP_PSTL_CUSTOMIZATION_POINT(__pstl_move, _RawPolicy), 57 [&__policy](_ForwardIterator __g_first, _ForwardIterator __g_last, _ForwardOutIterator __g_result) { 58 return std::__transform(__policy, __g_first, __g_last, __g_result, [](auto&& __v) { return std::move(__v); }); 59 }, 60 std::move(__first), 61 std::move(__last), 62 std::move(__result)); 63} 64 65template <class _ExecutionPolicy, 66 class _ForwardIterator, 67 class _ForwardOutIterator, 68 class _RawPolicy = __remove_cvref_t<_ExecutionPolicy>, 69 enable_if_t<is_execution_policy_v<_RawPolicy>, int> = 0> 70_LIBCPP_HIDE_FROM_ABI _ForwardOutIterator 71move(_ExecutionPolicy&& __policy, _ForwardIterator __first, _ForwardIterator __last, _ForwardOutIterator __result) { 72 auto __res = std::__move(__policy, std::move(__first), std::move(__last), std::move(__result)); 73 if (!__res) 74 std::__throw_bad_alloc(); 75 return *__res; 76} 77 78_LIBCPP_END_NAMESPACE_STD 79 80#endif // !defined(_LIBCPP_HAS_NO_INCOMPLETE_PSTL) && _LIBCPP_STD_VER >= 17 81 82_LIBCPP_POP_MACROS 83 84#endif // _LIBCPP___ALGORITHM_PSTL_MOVE_H 85