| 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___MEMORY_PSTL_H |
| 10 | #define _LIBCPP___MEMORY_PSTL_H |
| 11 | |
| 12 | #include <__config> |
| 13 | |
| 14 | #if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER) |
| 15 | # pragma GCC system_header |
| 16 | #endif |
| 17 | |
| 18 | _LIBCPP_PUSH_MACROS |
| 19 | #include <__undef_macros> |
| 20 | |
| 21 | #if _LIBCPP_HAS_EXPERIMENTAL_PSTL && _LIBCPP_STD_VER >= 17 |
| 22 | |
| 23 | # include <__iterator/cpp17_iterator_concepts.h> |
| 24 | # include <__iterator/iterator_traits.h> |
| 25 | # include <__pstl/backend.h> |
| 26 | # include <__pstl/dispatch.h> |
| 27 | # include <__pstl/handle_exception.h> |
| 28 | # include <__type_traits/enable_if.h> |
| 29 | # include <__type_traits/is_execution_policy.h> |
| 30 | # include <__type_traits/remove_cvref.h> |
| 31 | # include <__utility/forward.h> |
| 32 | # include <__utility/move.h> |
| 33 | # include <__utility/pair.h> |
| 34 | |
| 35 | _LIBCPP_BEGIN_NAMESPACE_STD |
| 36 | |
| 37 | template <class _ExecutionPolicy, |
| 38 | class _ForwardIterator, |
| 39 | class _RawPolicy = __remove_cvref_t<_ExecutionPolicy>, |
| 40 | enable_if_t<is_execution_policy_v<_RawPolicy>, int> = 0> |
| 41 | _LIBCPP_HIDE_FROM_ABI void destroy(_ExecutionPolicy&& __policy, _ForwardIterator __first, _ForwardIterator __last) { |
| 42 | _LIBCPP_REQUIRE_CPP17_FORWARD_ITERATOR(_ForwardIterator, "destroy requires ForwardIterators" ); |
| 43 | using _Implementation = __pstl::__dispatch<__pstl::__destroy, __pstl::__current_configuration, _RawPolicy>; |
| 44 | __pstl::__handle_exception<_Implementation>( |
| 45 | std::forward<_ExecutionPolicy>(__policy), std::move(__first), std::move(__last)); |
| 46 | } |
| 47 | |
| 48 | template <class _ExecutionPolicy, |
| 49 | class _ForwardIterator, |
| 50 | class _Size, |
| 51 | class _RawPolicy = __remove_cvref_t<_ExecutionPolicy>, |
| 52 | enable_if_t<is_execution_policy_v<_RawPolicy>, int> = 0> |
| 53 | _LIBCPP_HIDE_FROM_ABI void destroy_n(_ExecutionPolicy&& __policy, _ForwardIterator __first, _Size __n) { |
| 54 | _LIBCPP_REQUIRE_CPP17_FORWARD_ITERATOR(_ForwardIterator, "destroy_n requires ForwardIterators" ); |
| 55 | using _Implementation = __pstl::__dispatch<__pstl::__destroy_n, __pstl::__current_configuration, _RawPolicy>; |
| 56 | __pstl::__handle_exception<_Implementation>(std::forward<_ExecutionPolicy>(__policy), std::move(__first), __n); |
| 57 | } |
| 58 | |
| 59 | template <class _ExecutionPolicy, |
| 60 | class _ForwardIterator, |
| 61 | class _RawPolicy = __remove_cvref_t<_ExecutionPolicy>, |
| 62 | enable_if_t<is_execution_policy_v<_RawPolicy>, int> = 0> |
| 63 | _LIBCPP_HIDE_FROM_ABI void |
| 64 | uninitialized_default_construct(_ExecutionPolicy&& __policy, _ForwardIterator __first, _ForwardIterator __last) { |
| 65 | _LIBCPP_REQUIRE_CPP17_FORWARD_ITERATOR(_ForwardIterator, "uninitialized_default_construct requires ForwardIterators" ); |
| 66 | using _Implementation = |
| 67 | __pstl::__dispatch<__pstl::__uninitialized_default_construct, __pstl::__current_configuration, _RawPolicy>; |
| 68 | __pstl::__handle_exception<_Implementation>( |
| 69 | std::forward<_ExecutionPolicy>(__policy), std::move(__first), std::move(__last)); |
| 70 | } |
| 71 | |
| 72 | template <class _ExecutionPolicy, |
| 73 | class _ForwardIterator, |
| 74 | class _Size, |
| 75 | class _RawPolicy = __remove_cvref_t<_ExecutionPolicy>, |
| 76 | enable_if_t<is_execution_policy_v<_RawPolicy>, int> = 0> |
| 77 | _LIBCPP_HIDE_FROM_ABI void |
| 78 | uninitialized_default_construct_n(_ExecutionPolicy&& __policy, _ForwardIterator __first, _Size __n) { |
| 79 | _LIBCPP_REQUIRE_CPP17_FORWARD_ITERATOR( |
| 80 | _ForwardIterator, "uninitialized_default_construct_n requires ForwardIterators" ); |
| 81 | using _Implementation = |
| 82 | __pstl::__dispatch<__pstl::__uninitialized_default_construct_n, __pstl::__current_configuration, _RawPolicy>; |
| 83 | __pstl::__handle_exception<_Implementation>(std::forward<_ExecutionPolicy>(__policy), std::move(__first), __n); |
| 84 | } |
| 85 | |
| 86 | template <class _ExecutionPolicy, |
| 87 | class _InputIterator, |
| 88 | class _ForwardIterator, |
| 89 | class _RawPolicy = __remove_cvref_t<_ExecutionPolicy>, |
| 90 | enable_if_t<is_execution_policy_v<_RawPolicy>, int> = 0> |
| 91 | _LIBCPP_HIDE_FROM_ABI _ForwardIterator uninitialized_copy( |
| 92 | _ExecutionPolicy&& __policy, _InputIterator __first, _InputIterator __last, _ForwardIterator __result) { |
| 93 | _LIBCPP_REQUIRE_CPP17_INPUT_ITERATOR(_InputIterator, "uninitialized_copy requires InputIterators" ); |
| 94 | _LIBCPP_REQUIRE_CPP17_FORWARD_ITERATOR(_ForwardIterator, "uninitialized_copy requires ForwardIterators" ); |
| 95 | using _Implementation = __pstl::__dispatch<__pstl::__uninitialized_copy, __pstl::__current_configuration, _RawPolicy>; |
| 96 | return __pstl::__handle_exception<_Implementation>( |
| 97 | std::forward<_ExecutionPolicy>(__policy), std::move(__first), std::move(__last), std::move(__result)); |
| 98 | } |
| 99 | |
| 100 | template <class _ExecutionPolicy, |
| 101 | class _InputIterator, |
| 102 | class _Size, |
| 103 | class _ForwardIterator, |
| 104 | class _RawPolicy = __remove_cvref_t<_ExecutionPolicy>, |
| 105 | enable_if_t<is_execution_policy_v<_RawPolicy>, int> = 0> |
| 106 | _LIBCPP_HIDE_FROM_ABI _ForwardIterator |
| 107 | uninitialized_copy_n(_ExecutionPolicy&& __policy, _InputIterator __first, _Size __n, _ForwardIterator __result) { |
| 108 | _LIBCPP_REQUIRE_CPP17_INPUT_ITERATOR(_InputIterator, "uninitialized_copy_n requires InputIterators" ); |
| 109 | _LIBCPP_REQUIRE_CPP17_FORWARD_ITERATOR(_ForwardIterator, "uninitialized_copy_n requires ForwardIterators" ); |
| 110 | using _Implementation = |
| 111 | __pstl::__dispatch<__pstl::__uninitialized_copy_n, __pstl::__current_configuration, _RawPolicy>; |
| 112 | return __pstl::__handle_exception<_Implementation>( |
| 113 | std::forward<_ExecutionPolicy>(__policy), std::move(__first), __n, std::move(__result)); |
| 114 | } |
| 115 | |
| 116 | template <class _ExecutionPolicy, |
| 117 | class _ForwardIterator, |
| 118 | class _RawPolicy = __remove_cvref_t<_ExecutionPolicy>, |
| 119 | enable_if_t<is_execution_policy_v<_RawPolicy>, int> = 0> |
| 120 | _LIBCPP_HIDE_FROM_ABI void |
| 121 | uninitialized_value_construct(_ExecutionPolicy&& __policy, _ForwardIterator __first, _ForwardIterator __last) { |
| 122 | _LIBCPP_REQUIRE_CPP17_FORWARD_ITERATOR(_ForwardIterator, "uninitialized_value_construct requires ForwardIterators" ); |
| 123 | using _Implementation = |
| 124 | __pstl::__dispatch<__pstl::__uninitialized_value_construct, __pstl::__current_configuration, _RawPolicy>; |
| 125 | __pstl::__handle_exception<_Implementation>( |
| 126 | std::forward<_ExecutionPolicy>(__policy), std::move(__first), std::move(__last)); |
| 127 | } |
| 128 | |
| 129 | template <class _ExecutionPolicy, |
| 130 | class _ForwardIterator, |
| 131 | class _Size, |
| 132 | class _RawPolicy = __remove_cvref_t<_ExecutionPolicy>, |
| 133 | enable_if_t<is_execution_policy_v<_RawPolicy>, int> = 0> |
| 134 | _LIBCPP_HIDE_FROM_ABI void |
| 135 | uninitialized_value_construct_n(_ExecutionPolicy&& __policy, _ForwardIterator __first, _Size __n) { |
| 136 | _LIBCPP_REQUIRE_CPP17_FORWARD_ITERATOR(_ForwardIterator, "uninitialized_value_construct_n requires ForwardIterators" ); |
| 137 | using _Implementation = |
| 138 | __pstl::__dispatch<__pstl::__uninitialized_value_construct_n, __pstl::__current_configuration, _RawPolicy>; |
| 139 | __pstl::__handle_exception<_Implementation>(std::forward<_ExecutionPolicy>(__policy), std::move(__first), __n); |
| 140 | } |
| 141 | |
| 142 | template <class _ExecutionPolicy, |
| 143 | class _ForwardIterator, |
| 144 | class _Tp, |
| 145 | class _RawPolicy = __remove_cvref_t<_ExecutionPolicy>, |
| 146 | enable_if_t<is_execution_policy_v<_RawPolicy>, int> = 0> |
| 147 | _LIBCPP_HIDE_FROM_ABI void |
| 148 | uninitialized_fill(_ExecutionPolicy&& __policy, _ForwardIterator __first, _ForwardIterator __last, const _Tp& __value) { |
| 149 | _LIBCPP_REQUIRE_CPP17_FORWARD_ITERATOR(_ForwardIterator, "uninitialized_fill requires ForwardIterators" ); |
| 150 | using _Implementation = __pstl::__dispatch<__pstl::__uninitialized_fill, __pstl::__current_configuration, _RawPolicy>; |
| 151 | __pstl::__handle_exception<_Implementation>( |
| 152 | std::forward<_ExecutionPolicy>(__policy), std::move(__first), std::move(__last), __value); |
| 153 | } |
| 154 | |
| 155 | template <class _ExecutionPolicy, |
| 156 | class _ForwardIterator, |
| 157 | class _Size, |
| 158 | class _Tp, |
| 159 | class _RawPolicy = __remove_cvref_t<_ExecutionPolicy>, |
| 160 | enable_if_t<is_execution_policy_v<_RawPolicy>, int> = 0> |
| 161 | _LIBCPP_HIDE_FROM_ABI void |
| 162 | uninitialized_fill_n(_ExecutionPolicy&& __policy, _ForwardIterator __first, _Size __n, const _Tp& __value) { |
| 163 | _LIBCPP_REQUIRE_CPP17_FORWARD_ITERATOR(_ForwardIterator, "uninitialized_fill_n requires ForwardIterators" ); |
| 164 | using _Implementation = |
| 165 | __pstl::__dispatch<__pstl::__uninitialized_fill_n, __pstl::__current_configuration, _RawPolicy>; |
| 166 | __pstl::__handle_exception<_Implementation>( |
| 167 | std::forward<_ExecutionPolicy>(__policy), std::move(__first), __n, __value); |
| 168 | } |
| 169 | |
| 170 | template <class _ExecutionPolicy, |
| 171 | class _InputIterator, |
| 172 | class _ForwardIterator, |
| 173 | class _RawPolicy = __remove_cvref_t<_ExecutionPolicy>, |
| 174 | enable_if_t<is_execution_policy_v<_RawPolicy>, int> = 0> |
| 175 | _LIBCPP_HIDE_FROM_ABI _ForwardIterator uninitialized_move( |
| 176 | _ExecutionPolicy&& __policy, _InputIterator __first, _InputIterator __last, _ForwardIterator __result) { |
| 177 | _LIBCPP_REQUIRE_CPP17_INPUT_ITERATOR(_InputIterator, "uninitialized_move requires InputIterators" ); |
| 178 | _LIBCPP_REQUIRE_CPP17_FORWARD_ITERATOR(_ForwardIterator, "uninitialized_move requires ForwardIterators" ); |
| 179 | using _Implementation = __pstl::__dispatch<__pstl::__uninitialized_move, __pstl::__current_configuration, _RawPolicy>; |
| 180 | return __pstl::__handle_exception<_Implementation>( |
| 181 | std::forward<_ExecutionPolicy>(__policy), std::move(__first), std::move(__last), std::move(__result)); |
| 182 | } |
| 183 | |
| 184 | template <class _ExecutionPolicy, |
| 185 | class _InputIterator, |
| 186 | class _Size, |
| 187 | class _ForwardIterator, |
| 188 | class _RawPolicy = __remove_cvref_t<_ExecutionPolicy>, |
| 189 | enable_if_t<is_execution_policy_v<_RawPolicy>, int> = 0> |
| 190 | _LIBCPP_HIDE_FROM_ABI pair<_InputIterator, _ForwardIterator> |
| 191 | uninitialized_move_n(_ExecutionPolicy&& __policy, _InputIterator __first, _Size __n, _ForwardIterator __result) { |
| 192 | _LIBCPP_REQUIRE_CPP17_INPUT_ITERATOR(_InputIterator, "uninitialized_move_n requires InputIterators" ); |
| 193 | _LIBCPP_REQUIRE_CPP17_FORWARD_ITERATOR(_ForwardIterator, "uninitialized_move_n requires ForwardIterators" ); |
| 194 | using _Implementation = |
| 195 | __pstl::__dispatch<__pstl::__uninitialized_move_n, __pstl::__current_configuration, _RawPolicy>; |
| 196 | return __pstl::__handle_exception<_Implementation>( |
| 197 | std::forward<_ExecutionPolicy>(__policy), std::move(__first), __n, std::move(__result)); |
| 198 | } |
| 199 | |
| 200 | _LIBCPP_END_NAMESPACE_STD |
| 201 | |
| 202 | #endif // _LIBCPP_HAS_EXPERIMENTAL_PSTL && _LIBCPP_STD_VER >= 17 |
| 203 | |
| 204 | _LIBCPP_POP_MACROS |
| 205 | |
| 206 | #endif // _LIBCPP___MEMORY_PSTL_H |
| 207 | |