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
45namespace __pstl {
46
47template <class... _Backends>
48struct __backend_configuration;
49
50struct __default_backend_tag;
51struct __libdispatch_backend_tag;
52struct __serial_backend_tag;
53struct __std_thread_backend_tag;
54
55# if defined(_LIBCPP_PSTL_BACKEND_SERIAL)
56using __current_configuration _LIBCPP_NODEBUG = __backend_configuration<__serial_backend_tag, __default_backend_tag>;
57# elif defined(_LIBCPP_PSTL_BACKEND_STD_THREAD)
58using __current_configuration _LIBCPP_NODEBUG =
59 __backend_configuration<__std_thread_backend_tag, __default_backend_tag>;
60# elif defined(_LIBCPP_PSTL_BACKEND_LIBDISPATCH)
61using __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
70template <class _Backend, class _ExecutionPolicy>
71struct __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
76template <class _Backend, class _ExecutionPolicy>
77struct __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
82template <class _Backend, class _ExecutionPolicy>
83struct __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
88template <class _Backend, class _ExecutionPolicy>
89struct __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
94template <class _Backend, class _ExecutionPolicy>
95struct __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
100template <class _Backend, class _ExecutionPolicy>
101struct __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
106template <class _Backend, class _ExecutionPolicy>
107struct __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
112template <class _Backend, class _ExecutionPolicy>
113struct __find_first_of;
114// template <class _Policy, class _ForwardIterator1, class _ForwardIterator2, class _Predicate>
115// optional<_ForwardIterator1>
116// operator()(_Policy&&, _ForwardIterator1 __first1, _ForwardIterator1 __last1,
117// _ForwardIterator2 __first2, _ForwardIterator2 __last2, _Predicate __pred) const noexcept;
118
119template <class _Backend, class _ExecutionPolicy>
120struct __for_each;
121// template <class _Policy, class _ForwardIterator, class _Function>
122// optional<__empty>
123// operator()(_Policy&&, _ForwardIterator __first, _ForwardIterator __last, _Function __func) const noexcept;
124
125template <class _Backend, class _ExecutionPolicy>
126struct __for_each_n;
127// template <class _Policy, class _ForwardIterator, class _Size, class _Function>
128// optional<__empty>
129// operator()(_Policy&&, _ForwardIterator __first, _Size __size, _Function __func) const noexcept;
130
131template <class _Backend, class _ExecutionPolicy>
132struct __fill;
133// template <class _Policy, class _ForwardIterator, class _Tp>
134// optional<__empty>
135// operator()(_Policy&&, _ForwardIterator __first, _ForwardIterator __last, _Tp const& __value) const noexcept;
136
137template <class _Backend, class _ExecutionPolicy>
138struct __fill_n;
139// template <class _Policy, class _ForwardIterator, class _Size, class _Tp>
140// optional<__empty>
141// operator()(_Policy&&, _ForwardIterator __first, _Size __n, _Tp const& __value) const noexcept;
142
143template <class _Backend, class _ExecutionPolicy>
144struct __replace;
145// template <class _Policy, class _ForwardIterator, class _Tp>
146// optional<__empty>
147// operator()(_Policy&&, _ForwardIterator __first, _ForwardIterator __last,
148// _Tp const& __old, _Tp const& __new) const noexcept;
149
150template <class _Backend, class _ExecutionPolicy>
151struct __replace_if;
152// template <class _Policy, class _ForwardIterator, class _Predicate, class _Tp>
153// optional<__empty>
154// operator()(_Policy&&, _ForwardIterator __first, _ForwardIterator __last,
155// _Predicate __pred, _Tp const& __new_value) const noexcept;
156
157template <class _Backend, class _ExecutionPolicy>
158struct __generate;
159// template <class _Policy, class _ForwardIterator, class _Generator>
160// optional<__empty>
161// operator()(_Policy&&, _ForwardIterator __first, _ForwardIterator __last, _Generator __gen) const noexcept;
162
163template <class _Backend, class _ExecutionPolicy>
164struct __generate_n;
165// template <class _Policy, class _ForwardIterator, class _Size, class _Generator>
166// optional<__empty>
167// operator()(_Policy&&, _ForwardIterator __first, _Size __n, _Generator __gen) const noexcept;
168
169template <class _Backend, class _ExecutionPolicy>
170struct __reverse_copy;
171// template <class _Policy, class _BidirectionalIterator, class _ForwardIterator>
172// optional<_ForwardIterator>
173// operator()(_Policy&&, _BidirectionalIterator __first, _BidirectionalIterator __last,
174// _ForwardIterator __result) const noexcept;
175
176template <class _Backend, class _ExecutionPolicy>
177struct __merge;
178// template <class _Policy, class _ForwardIterator1, class _ForwardIterator2, class _ForwardOutIterator, class _Comp>
179// optional<_ForwardOutIterator>
180// operator()(_Policy&&, _ForwardIterator1 __first1, _ForwardIterator1 __last1,
181// _ForwardIterator2 __first2, _ForwardIterator2 __last2,
182// _ForwardOutIterator __result, _Comp __comp) const noexcept;
183
184template <class _Backend, class _ExecutionPolicy>
185struct __stable_sort;
186// template <class _Policy, class _RandomAccessIterator, class _Comp>
187// optional<__empty>
188// operator()(_Policy&&, _RandomAccessIterator __first, _RandomAccessIterator __last, _Comp __comp) const noexcept;
189
190template <class _Backend, class _ExecutionPolicy>
191struct __sort;
192// template <class _Policy, class _RandomAccessIterator, class _Comp>
193// optional<__empty>
194// operator()(_Policy&&, _RandomAccessIterator __first, _RandomAccessIterator __last, _Comp __comp) const noexcept;
195
196template <class _Backend, class _ExecutionPolicy>
197struct __transform;
198// template <class _Policy, class _ForwardIterator, class _ForwardOutIterator, class _UnaryOperation>
199// optional<_ForwardOutIterator>
200// operator()(_Policy&&, _ForwardIterator __first, _ForwardIterator __last,
201// _ForwardOutIterator __result,
202// _UnaryOperation __op) const noexcept;
203
204template <class _Backend, class _ExecutionPolicy>
205struct __transform_binary;
206// template <class _Policy, class _ForwardIterator1, class _ForwardIterator2,
207// class _ForwardOutIterator,
208// class _BinaryOperation>
209// optional<_ForwardOutIterator>
210// operator()(_Policy&&, _ForwardIterator1 __first1, _ForwardIterator1 __last1,
211// _ForwardIterator2 __first2,
212// _ForwardOutIterator __result,
213// _BinaryOperation __op) const noexcept;
214
215template <class _Backend, class _ExecutionPolicy>
216struct __replace_copy_if;
217// template <class _Policy, class _ForwardIterator, class _ForwardOutIterator, class _Predicate, class _Tp>
218// optional<__empty>
219// operator()(_Policy&&, _ForwardIterator __first, _ForwardIterator __last,
220// _ForwardOutIterator __out_it,
221// _Predicate __pred,
222// _Tp const& __new_value) const noexcept;
223
224template <class _Backend, class _ExecutionPolicy>
225struct __replace_copy;
226// template <class _Policy, class _ForwardIterator, class _ForwardOutIterator, class _Tp>
227// optional<__empty>
228// operator()(_Policy&&, _ForwardIterator __first, _ForwardIterator __last,
229// _ForwardOutIterator __out_it,
230// _Tp const& __old_value,
231// _Tp const& __new_value) const noexcept;
232
233template <class _Backend, class _ExecutionPolicy>
234struct __move;
235// template <class _Policy, class _ForwardIterator, class _ForwardOutIterator>
236// optional<_ForwardOutIterator>
237// operator()(_Policy&&, _ForwardIterator __first, _ForwardIterator __last,
238// _ForwardOutIterator __out_it) const noexcept;
239
240template <class _Backend, class _ExecutionPolicy>
241struct __copy;
242// template <class _Policy, class _ForwardIterator, class _ForwardOutIterator>
243// optional<_ForwardOutIterator>
244// operator()(_Policy&&, _ForwardIterator __first, _ForwardIterator __last,
245// _ForwardOutIterator __out_it) const noexcept;
246
247template <class _Backend, class _ExecutionPolicy>
248struct __copy_n;
249// template <class _Policy, class _ForwardIterator, class _Size, class _ForwardOutIterator>
250// optional<_ForwardOutIterator>
251// operator()(_Policy&&, _ForwardIterator __first, _Size __n, _ForwardOutIterator __out_it) const noexcept;
252
253template <class _Backend, class _ExecutionPolicy>
254struct __rotate_copy;
255// template <class _Policy, class _ForwardIterator, class _ForwardOutIterator>
256// optional<_ForwardOutIterator>
257// operator()(_Policy&&, _ForwardIterator __first, _ForwardIterator __middle, _ForwardIterator __last,
258// _ForwardOutIterator __out_it) const noexcept;
259
260template <class _Backend, class _ExecutionPolicy>
261struct __transform_reduce;
262// template <class _Policy, class _ForwardIterator, class _Tp, class _BinaryOperation, class _UnaryOperation>
263// optional<_Tp>
264// operator()(_Policy&&, _ForwardIterator __first, _ForwardIterator __last,
265// _Tp __init,
266// _BinaryOperation __reduce,
267// _UnaryOperation __transform) const noexcept;
268
269template <class _Backend, class _ExecutionPolicy>
270struct __transform_reduce_binary;
271// template <class _Policy, class _ForwardIterator1, class _ForwardIterator2,
272// class _Tp, class _BinaryOperation1, class _BinaryOperation2>
273// optional<_Tp> operator()(_Policy&&, _ForwardIterator1 __first1, _ForwardIterator1 __last1,
274// _ForwardIterator2 __first2,
275// _Tp __init,
276// _BinaryOperation1 __reduce,
277// _BinaryOperation2 __transform) const noexcept;
278
279template <class _Backend, class _ExecutionPolicy>
280struct __count_if;
281// template <class _Policy, class _ForwardIterator, class _Predicate>
282// optional<__iter_diff_t<_ForwardIterator>>
283// operator()(_Policy&&, _ForwardIterator __first, _ForwardIterator __last, _Predicate __pred) const noexcept;
284
285template <class _Backend, class _ExecutionPolicy>
286struct __count;
287// template <class _Policy, class _ForwardIterator, class _Tp>
288// optional<__iter_diff_t<_ForwardIterator>>
289// operator()(_Policy&&, _ForwardIterator __first, _ForwardIterator __last, _Tp const& __value) const noexcept;
290
291template <class _Backend, class _ExecutionPolicy>
292struct __equal_3leg;
293// template <class _Policy, class _ForwardIterator1, class _ForwardIterator2, class _Predicate>
294// optional<bool>
295// operator()(_Policy&&, _ForwardIterator1 __first1, _ForwardIterator1 __last1,
296// _ForwardIterator2 __first2,
297// _Predicate __pred) const noexcept;
298
299template <class _Backend, class _ExecutionPolicy>
300struct __equal;
301// template <class _Policy, class _ForwardIterator1, class _ForwardIterator2, class _Predicate>
302// optional<bool>
303// operator()(_Policy&&, _ForwardIterator1 __first1, _ForwardIterator1 __last1,
304// _ForwardIterator2 __first2, _ForwardIterator2 __last2,
305// _Predicate __pred) const noexcept;
306
307template <class _Backend, class _ExecutionPolicy>
308struct __reduce;
309// template <class _Policy, class _ForwardIterator, class _Tp, class _BinaryOperation>
310// optional<_Tp>
311// operator()(_Policy&&, _ForwardIterator __first, _ForwardIterator __last,
312// _Tp __init, _BinaryOperation __op) const noexcept;
313
314template <class _Backend, class _ExecutionPolicy>
315struct __is_sorted;
316// template <class _Policy, class _ForwardIterator, class _Comp>
317// optional<bool>
318// operator()(_Policy&& __policy, _ForwardIterator __first, _ForwardIterator __last, _Comp&& __comp) const noexcept;
319
320template <class _Backend, class _ExecutionPolicy>
321struct __adjacent_difference;
322// template <class _Policy, class _ForwardIterator1, class _ForwardIterator2, class _BinaryOperation>
323// optional<_ForwardIterator2>
324// operator()(_Policy&& __policy, _ForwardIterator1 __first1, _ForwardIterator1 __last1,
325// _ForwardIterator2 __first2, _BinaryOperation &&__op) const noexcept;
326
327} // namespace __pstl
328_LIBCPP_END_NAMESPACE_STD
329
330#endif // _LIBCPP_STD_VER >= 17
331
332_LIBCPP_POP_MACROS
333
334#endif // _LIBCPP___PSTL_BACKEND_FWD_H
335