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___PSTL_BACKEND_FWD_H |
10 | #define _LIBCPP___PSTL_BACKEND_FWD_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 | // |
22 | // This header declares available PSTL backends and the functions that must be implemented in order for the |
23 | // PSTL algorithms to be provided. |
24 | // |
25 | // Backends often do not implement the full set of functions themselves -- a configuration of the PSTL is |
26 | // usually a set of backends "stacked" together which each implement some algorithms under some execution |
27 | // policies. It is only necessary for the "stack" of backends to implement all algorithms under all execution |
28 | // policies, but a single backend is not required to implement everything on its own. |
29 | // |
30 | // The signatures used by each backend function are documented below. |
31 | // |
32 | // Exception handling |
33 | // ================== |
34 | // |
35 | // PSTL backends are expected to report errors (i.e. failure to allocate) by returning a disengaged `optional` from |
36 | // their implementation. Exceptions shouldn't be used to report an internal failure-to-allocate, since all exceptions |
37 | // are turned into a program termination at the front-end level. When a backend returns a disengaged `optional` to the |
38 | // frontend, the frontend will turn that into a call to `std::__throw_bad_alloc();` to report the internal failure to |
39 | // the user. |
40 | // |
41 | |
42 | #if _LIBCPP_STD_VER >= 17 |
43 | |
44 | _LIBCPP_BEGIN_NAMESPACE_STD |
45 | namespace __pstl { |
46 | |
47 | template <class... _Backends> |
48 | struct __backend_configuration; |
49 | |
50 | struct __default_backend_tag; |
51 | struct __libdispatch_backend_tag; |
52 | struct __serial_backend_tag; |
53 | struct __std_thread_backend_tag; |
54 | |
55 | # if defined(_LIBCPP_PSTL_BACKEND_SERIAL) |
56 | using __current_configuration _LIBCPP_NODEBUG = __backend_configuration<__serial_backend_tag, __default_backend_tag>; |
57 | # elif defined(_LIBCPP_PSTL_BACKEND_STD_THREAD) |
58 | using __current_configuration _LIBCPP_NODEBUG = |
59 | __backend_configuration<__std_thread_backend_tag, __default_backend_tag>; |
60 | # elif defined(_LIBCPP_PSTL_BACKEND_LIBDISPATCH) |
61 | using __current_configuration _LIBCPP_NODEBUG = |
62 | __backend_configuration<__libdispatch_backend_tag, __default_backend_tag>; |
63 | # else |
64 | |
65 | // ...New vendors can add parallel backends here... |
66 | |
67 | # error "Invalid PSTL backend configuration" |
68 | # endif |
69 | |
70 | template <class _Backend, class _ExecutionPolicy> |
71 | struct __find_if; |
72 | // template <class _Policy, class _ForwardIterator, class _Predicate> |
73 | // optional<_ForwardIterator> |
74 | // operator()(_Policy&&, _ForwardIterator __first, _ForwardIterator __last, _Predicate __pred) const noexcept; |
75 | |
76 | template <class _Backend, class _ExecutionPolicy> |
77 | struct __find_if_not; |
78 | // template <class _Policy, class _ForwardIterator, class _Predicate> |
79 | // optional<_ForwardIterator> |
80 | // operator()(_Policy&&, _ForwardIterator __first, _ForwardIterator __last, _Predicate __pred) const noexcept; |
81 | |
82 | template <class _Backend, class _ExecutionPolicy> |
83 | struct __find; |
84 | // template <class _Policy, class _ForwardIterator, class _Tp> |
85 | // optional<_ForwardIterator> |
86 | // operator()(_Policy&&, _ForwardIterator __first, _ForwardIterator __last, const _Tp& __value) const noexcept; |
87 | |
88 | template <class _Backend, class _ExecutionPolicy> |
89 | struct __any_of; |
90 | // template <class _Policy, class _ForwardIterator, class _Predicate> |
91 | // optional<bool> |
92 | // operator()(_Policy&&, _ForwardIterator __first, _ForwardIterator __last, _Predicate __pred) const noexcept; |
93 | |
94 | template <class _Backend, class _ExecutionPolicy> |
95 | struct __all_of; |
96 | // template <class _Policy, class _ForwardIterator, class _Predicate> |
97 | // optional<bool> |
98 | // operator()(_Policy&&, _ForwardIterator __first, _ForwardIterator __last, _Predicate __pred) const noexcept; |
99 | |
100 | template <class _Backend, class _ExecutionPolicy> |
101 | struct __none_of; |
102 | // template <class _Policy, class _ForwardIterator, class _Predicate> |
103 | // optional<bool> |
104 | // operator()(_Policy&&, _ForwardIterator __first, _ForwardIterator __last, _Predicate __pred) const noexcept; |
105 | |
106 | template <class _Backend, class _ExecutionPolicy> |
107 | struct __is_partitioned; |
108 | // template <class _Policy, class _ForwardIterator, class _Predicate> |
109 | // optional<bool> |
110 | // operator()(_Policy&&, _ForwardIterator __first, _ForwardIterator __last, _Predicate __pred) const noexcept; |
111 | |
112 | template <class _Backend, class _ExecutionPolicy> |
113 | struct __for_each; |
114 | // template <class _Policy, class _ForwardIterator, class _Function> |
115 | // optional<__empty> |
116 | // operator()(_Policy&&, _ForwardIterator __first, _ForwardIterator __last, _Function __func) const noexcept; |
117 | |
118 | template <class _Backend, class _ExecutionPolicy> |
119 | struct __for_each_n; |
120 | // template <class _Policy, class _ForwardIterator, class _Size, class _Function> |
121 | // optional<__empty> |
122 | // operator()(_Policy&&, _ForwardIterator __first, _Size __size, _Function __func) const noexcept; |
123 | |
124 | template <class _Backend, class _ExecutionPolicy> |
125 | struct __fill; |
126 | // template <class _Policy, class _ForwardIterator, class _Tp> |
127 | // optional<__empty> |
128 | // operator()(_Policy&&, _ForwardIterator __first, _ForwardIterator __last, _Tp const& __value) const noexcept; |
129 | |
130 | template <class _Backend, class _ExecutionPolicy> |
131 | struct __fill_n; |
132 | // template <class _Policy, class _ForwardIterator, class _Size, class _Tp> |
133 | // optional<__empty> |
134 | // operator()(_Policy&&, _ForwardIterator __first, _Size __n, _Tp const& __value) const noexcept; |
135 | |
136 | template <class _Backend, class _ExecutionPolicy> |
137 | struct __replace; |
138 | // template <class _Policy, class _ForwardIterator, class _Tp> |
139 | // optional<__empty> |
140 | // operator()(_Policy&&, _ForwardIterator __first, _ForwardIterator __last, |
141 | // _Tp const& __old, _Tp const& __new) const noexcept; |
142 | |
143 | template <class _Backend, class _ExecutionPolicy> |
144 | struct __replace_if; |
145 | // template <class _Policy, class _ForwardIterator, class _Predicate, class _Tp> |
146 | // optional<__empty> |
147 | // operator()(_Policy&&, _ForwardIterator __first, _ForwardIterator __last, |
148 | // _Predicate __pred, _Tp const& __new_value) const noexcept; |
149 | |
150 | template <class _Backend, class _ExecutionPolicy> |
151 | struct __generate; |
152 | // template <class _Policy, class _ForwardIterator, class _Generator> |
153 | // optional<__empty> |
154 | // operator()(_Policy&&, _ForwardIterator __first, _ForwardIterator __last, _Generator __gen) const noexcept; |
155 | |
156 | template <class _Backend, class _ExecutionPolicy> |
157 | struct __generate_n; |
158 | // template <class _Policy, class _ForwardIterator, class _Size, class _Generator> |
159 | // optional<__empty> |
160 | // operator()(_Policy&&, _ForwardIterator __first, _Size __n, _Generator __gen) const noexcept; |
161 | |
162 | template <class _Backend, class _ExecutionPolicy> |
163 | struct __merge; |
164 | // template <class _Policy, class _ForwardIterator1, class _ForwardIterator2, class _ForwardOutIterator, class _Comp> |
165 | // optional<_ForwardOutIterator> |
166 | // operator()(_Policy&&, _ForwardIterator1 __first1, _ForwardIterator1 __last1, |
167 | // _ForwardIterator2 __first2, _ForwardIterator2 __last2, |
168 | // _ForwardOutIterator __result, _Comp __comp) const noexcept; |
169 | |
170 | template <class _Backend, class _ExecutionPolicy> |
171 | struct __stable_sort; |
172 | // template <class _Policy, class _RandomAccessIterator, class _Comp> |
173 | // optional<__empty> |
174 | // operator()(_Policy&&, _RandomAccessIterator __first, _RandomAccessIterator __last, _Comp __comp) const noexcept; |
175 | |
176 | template <class _Backend, class _ExecutionPolicy> |
177 | struct __sort; |
178 | // template <class _Policy, class _RandomAccessIterator, class _Comp> |
179 | // optional<__empty> |
180 | // operator()(_Policy&&, _RandomAccessIterator __first, _RandomAccessIterator __last, _Comp __comp) const noexcept; |
181 | |
182 | template <class _Backend, class _ExecutionPolicy> |
183 | struct __transform; |
184 | // template <class _Policy, class _ForwardIterator, class _ForwardOutIterator, class _UnaryOperation> |
185 | // optional<_ForwardOutIterator> |
186 | // operator()(_Policy&&, _ForwardIterator __first, _ForwardIterator __last, |
187 | // _ForwardOutIterator __result, |
188 | // _UnaryOperation __op) const noexcept; |
189 | |
190 | template <class _Backend, class _ExecutionPolicy> |
191 | struct __transform_binary; |
192 | // template <class _Policy, class _ForwardIterator1, class _ForwardIterator2, |
193 | // class _ForwardOutIterator, |
194 | // class _BinaryOperation> |
195 | // optional<_ForwardOutIterator> |
196 | // operator()(_Policy&&, _ForwardIterator1 __first1, _ForwardIterator1 __last1, |
197 | // _ForwardIterator2 __first2, |
198 | // _ForwardOutIterator __result, |
199 | // _BinaryOperation __op) const noexcept; |
200 | |
201 | template <class _Backend, class _ExecutionPolicy> |
202 | struct __replace_copy_if; |
203 | // template <class _Policy, class _ForwardIterator, class _ForwardOutIterator, class _Predicate, class _Tp> |
204 | // optional<__empty> |
205 | // operator()(_Policy&&, _ForwardIterator __first, _ForwardIterator __last, |
206 | // _ForwardOutIterator __out_it, |
207 | // _Predicate __pred, |
208 | // _Tp const& __new_value) const noexcept; |
209 | |
210 | template <class _Backend, class _ExecutionPolicy> |
211 | struct __replace_copy; |
212 | // template <class _Policy, class _ForwardIterator, class _ForwardOutIterator, class _Tp> |
213 | // optional<__empty> |
214 | // operator()(_Policy&&, _ForwardIterator __first, _ForwardIterator __last, |
215 | // _ForwardOutIterator __out_it, |
216 | // _Tp const& __old_value, |
217 | // _Tp const& __new_value) const noexcept; |
218 | |
219 | template <class _Backend, class _ExecutionPolicy> |
220 | struct __move; |
221 | // template <class _Policy, class _ForwardIterator, class _ForwardOutIterator> |
222 | // optional<_ForwardOutIterator> |
223 | // operator()(_Policy&&, _ForwardIterator __first, _ForwardIterator __last, |
224 | // _ForwardOutIterator __out_it) const noexcept; |
225 | |
226 | template <class _Backend, class _ExecutionPolicy> |
227 | struct __copy; |
228 | // template <class _Policy, class _ForwardIterator, class _ForwardOutIterator> |
229 | // optional<_ForwardOutIterator> |
230 | // operator()(_Policy&&, _ForwardIterator __first, _ForwardIterator __last, |
231 | // _ForwardOutIterator __out_it) const noexcept; |
232 | |
233 | template <class _Backend, class _ExecutionPolicy> |
234 | struct __copy_n; |
235 | // template <class _Policy, class _ForwardIterator, class _Size, class _ForwardOutIterator> |
236 | // optional<_ForwardOutIterator> |
237 | // operator()(_Policy&&, _ForwardIterator __first, _Size __n, _ForwardOutIterator __out_it) const noexcept; |
238 | |
239 | template <class _Backend, class _ExecutionPolicy> |
240 | struct __rotate_copy; |
241 | // template <class _Policy, class _ForwardIterator, class _ForwardOutIterator> |
242 | // optional<_ForwardOutIterator> |
243 | // operator()(_Policy&&, _ForwardIterator __first, _ForwardIterator __middle, _ForwardIterator __last, |
244 | // _ForwardOutIterator __out_it) const noexcept; |
245 | |
246 | template <class _Backend, class _ExecutionPolicy> |
247 | struct __transform_reduce; |
248 | // template <class _Policy, class _ForwardIterator, class _Tp, class _BinaryOperation, class _UnaryOperation> |
249 | // optional<_Tp> |
250 | // operator()(_Policy&&, _ForwardIterator __first, _ForwardIterator __last, |
251 | // _Tp __init, |
252 | // _BinaryOperation __reduce, |
253 | // _UnaryOperation __transform) const noexcept; |
254 | |
255 | template <class _Backend, class _ExecutionPolicy> |
256 | struct __transform_reduce_binary; |
257 | // template <class _Policy, class _ForwardIterator1, class _ForwardIterator2, |
258 | // class _Tp, class _BinaryOperation1, class _BinaryOperation2> |
259 | // optional<_Tp> operator()(_Policy&&, _ForwardIterator1 __first1, _ForwardIterator1 __last1, |
260 | // _ForwardIterator2 __first2, |
261 | // _Tp __init, |
262 | // _BinaryOperation1 __reduce, |
263 | // _BinaryOperation2 __transform) const noexcept; |
264 | |
265 | template <class _Backend, class _ExecutionPolicy> |
266 | struct __count_if; |
267 | // template <class _Policy, class _ForwardIterator, class _Predicate> |
268 | // optional<__iter_diff_t<_ForwardIterator>> |
269 | // operator()(_Policy&&, _ForwardIterator __first, _ForwardIterator __last, _Predicate __pred) const noexcept; |
270 | |
271 | template <class _Backend, class _ExecutionPolicy> |
272 | struct __count; |
273 | // template <class _Policy, class _ForwardIterator, class _Tp> |
274 | // optional<__iter_diff_t<_ForwardIterator>> |
275 | // operator()(_Policy&&, _ForwardIterator __first, _ForwardIterator __last, _Tp const& __value) const noexcept; |
276 | |
277 | template <class _Backend, class _ExecutionPolicy> |
278 | struct __equal_3leg; |
279 | // template <class _Policy, class _ForwardIterator1, class _ForwardIterator2, class _Predicate> |
280 | // optional<bool> |
281 | // operator()(_Policy&&, _ForwardIterator1 __first1, _ForwardIterator1 __last1, |
282 | // _ForwardIterator2 __first2, |
283 | // _Predicate __pred) const noexcept; |
284 | |
285 | template <class _Backend, class _ExecutionPolicy> |
286 | struct __equal; |
287 | // template <class _Policy, class _ForwardIterator1, class _ForwardIterator2, class _Predicate> |
288 | // optional<bool> |
289 | // operator()(_Policy&&, _ForwardIterator1 __first1, _ForwardIterator1 __last1, |
290 | // _ForwardIterator2 __first2, _ForwardIterator2 __last2, |
291 | // _Predicate __pred) const noexcept; |
292 | |
293 | template <class _Backend, class _ExecutionPolicy> |
294 | struct __reduce; |
295 | // template <class _Policy, class _ForwardIterator, class _Tp, class _BinaryOperation> |
296 | // optional<_Tp> |
297 | // operator()(_Policy&&, _ForwardIterator __first, _ForwardIterator __last, |
298 | // _Tp __init, _BinaryOperation __op) const noexcept; |
299 | |
300 | } // namespace __pstl |
301 | _LIBCPP_END_NAMESPACE_STD |
302 | |
303 | #endif // _LIBCPP_STD_VER >= 17 |
304 | |
305 | _LIBCPP_POP_MACROS |
306 | |
307 | #endif // _LIBCPP___PSTL_BACKEND_FWD_H |
308 | |