1 //===----------------------------------------------------------------------===//
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
7 //===----------------------------------------------------------------------===//
9 #ifndef _LIBCPP___PSTL_BACKEND_FWD_H
10 #define _LIBCPP___PSTL_BACKEND_FWD_H
14 #if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER)
15 # pragma GCC system_header
19 #include <__undef_macros>
22 // This header declares available PSTL backends and the functions that must be implemented in order for the
23 // PSTL algorithms to be provided.
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.
30 // The signatures used by each backend function are documented below.
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
42 #if _LIBCPP_STD_VER >= 17
44 _LIBCPP_BEGIN_NAMESPACE_STD
47 template <class... _Backends
>
48 struct __backend_configuration
;
50 struct __default_backend_tag
;
51 struct __libdispatch_backend_tag
;
52 struct __serial_backend_tag
;
53 struct __std_thread_backend_tag
;
55 # if defined(_LIBCPP_PSTL_BACKEND_SERIAL)
56 using __current_configuration
= __backend_configuration
<__serial_backend_tag
, __default_backend_tag
>;
57 # elif defined(_LIBCPP_PSTL_BACKEND_STD_THREAD)
58 using __current_configuration
= __backend_configuration
<__std_thread_backend_tag
, __default_backend_tag
>;
59 # elif defined(_LIBCPP_PSTL_BACKEND_LIBDISPATCH)
60 using __current_configuration
= __backend_configuration
<__libdispatch_backend_tag
, __default_backend_tag
>;
63 // ...New vendors can add parallel backends here...
65 # error "Invalid PSTL backend configuration"
68 template <class _Backend
, class _ExecutionPolicy
>
70 // template <class _Policy, class _ForwardIterator, class _Predicate>
71 // optional<_ForwardIterator>
72 // operator()(_Policy&&, _ForwardIterator __first, _ForwardIterator __last, _Predicate __pred) const noexcept;
74 template <class _Backend
, class _ExecutionPolicy
>
76 // template <class _Policy, class _ForwardIterator, class _Predicate>
77 // optional<_ForwardIterator>
78 // operator()(_Policy&&, _ForwardIterator __first, _ForwardIterator __last, _Predicate __pred) const noexcept;
80 template <class _Backend
, class _ExecutionPolicy
>
82 // template <class _Policy, class _ForwardIterator, class _Tp>
83 // optional<_ForwardIterator>
84 // operator()(_Policy&&, _ForwardIterator __first, _ForwardIterator __last, const _Tp& __value) const noexcept;
86 template <class _Backend
, class _ExecutionPolicy
>
88 // template <class _Policy, class _ForwardIterator, class _Predicate>
90 // operator()(_Policy&&, _ForwardIterator __first, _ForwardIterator __last, _Predicate __pred) const noexcept;
92 template <class _Backend
, class _ExecutionPolicy
>
94 // template <class _Policy, class _ForwardIterator, class _Predicate>
96 // operator()(_Policy&&, _ForwardIterator __first, _ForwardIterator __last, _Predicate __pred) const noexcept;
98 template <class _Backend
, class _ExecutionPolicy
>
100 // template <class _Policy, class _ForwardIterator, class _Predicate>
102 // operator()(_Policy&&, _ForwardIterator __first, _ForwardIterator __last, _Predicate __pred) const noexcept;
104 template <class _Backend
, class _ExecutionPolicy
>
105 struct __is_partitioned
;
106 // template <class _Policy, class _ForwardIterator, class _Predicate>
108 // operator()(_Policy&&, _ForwardIterator __first, _ForwardIterator __last, _Predicate __pred) const noexcept;
110 template <class _Backend
, class _ExecutionPolicy
>
112 // template <class _Policy, class _ForwardIterator, class _Function>
114 // operator()(_Policy&&, _ForwardIterator __first, _ForwardIterator __last, _Function __func) const noexcept;
116 template <class _Backend
, class _ExecutionPolicy
>
118 // template <class _Policy, class _ForwardIterator, class _Size, class _Function>
120 // operator()(_Policy&&, _ForwardIterator __first, _Size __size, _Function __func) const noexcept;
122 template <class _Backend
, class _ExecutionPolicy
>
124 // template <class _Policy, class _ForwardIterator, class _Tp>
126 // operator()(_Policy&&, _ForwardIterator __first, _ForwardIterator __last, _Tp const& __value) const noexcept;
128 template <class _Backend
, class _ExecutionPolicy
>
130 // template <class _Policy, class _ForwardIterator, class _Size, class _Tp>
132 // operator()(_Policy&&, _ForwardIterator __first, _Size __n, _Tp const& __value) const noexcept;
134 template <class _Backend
, class _ExecutionPolicy
>
136 // template <class _Policy, class _ForwardIterator, class _Tp>
138 // operator()(_Policy&&, _ForwardIterator __first, _ForwardIterator __last,
139 // _Tp const& __old, _Tp const& __new) const noexcept;
141 template <class _Backend
, class _ExecutionPolicy
>
143 // template <class _Policy, class _ForwardIterator, class _Predicate, class _Tp>
145 // operator()(_Policy&&, _ForwardIterator __first, _ForwardIterator __last,
146 // _Predicate __pred, _Tp const& __new_value) const noexcept;
148 template <class _Backend
, class _ExecutionPolicy
>
150 // template <class _Policy, class _ForwardIterator, class _Generator>
152 // operator()(_Policy&&, _ForwardIterator __first, _ForwardIterator __last, _Generator __gen) const noexcept;
154 template <class _Backend
, class _ExecutionPolicy
>
156 // template <class _Policy, class _ForwardIterator, class _Size, class _Generator>
158 // operator()(_Policy&&, _ForwardIterator __first, _Size __n, _Generator __gen) const noexcept;
160 template <class _Backend
, class _ExecutionPolicy
>
162 // template <class _Policy, class _ForwardIterator1, class _ForwardIterator2, class _ForwardOutIterator, class _Comp>
163 // optional<_ForwardOutIterator>
164 // operator()(_Policy&&, _ForwardIterator1 __first1, _ForwardIterator1 __last1,
165 // _ForwardIterator2 __first2, _ForwardIterator2 __last2,
166 // _ForwardOutIterator __result, _Comp __comp) const noexcept;
168 template <class _Backend
, class _ExecutionPolicy
>
169 struct __stable_sort
;
170 // template <class _Policy, class _RandomAccessIterator, class _Comp>
172 // operator()(_Policy&&, _RandomAccessIterator __first, _RandomAccessIterator __last, _Comp __comp) const noexcept;
174 template <class _Backend
, class _ExecutionPolicy
>
176 // template <class _Policy, class _RandomAccessIterator, class _Comp>
178 // operator()(_Policy&&, _RandomAccessIterator __first, _RandomAccessIterator __last, _Comp __comp) const noexcept;
180 template <class _Backend
, class _ExecutionPolicy
>
182 // template <class _Policy, class _ForwardIterator, class _ForwardOutIterator, class _UnaryOperation>
183 // optional<_ForwardOutIterator>
184 // operator()(_Policy&&, _ForwardIterator __first, _ForwardIterator __last,
185 // _ForwardOutIterator __result,
186 // _UnaryOperation __op) const noexcept;
188 template <class _Backend
, class _ExecutionPolicy
>
189 struct __transform_binary
;
190 // template <class _Policy, class _ForwardIterator1, class _ForwardIterator2,
191 // class _ForwardOutIterator,
192 // class _BinaryOperation>
193 // optional<_ForwardOutIterator>
194 // operator()(_Policy&&, _ForwardIterator1 __first1, _ForwardIterator1 __last1,
195 // _ForwardIterator2 __first2,
196 // _ForwardOutIterator __result,
197 // _BinaryOperation __op) const noexcept;
199 template <class _Backend
, class _ExecutionPolicy
>
200 struct __replace_copy_if
;
201 // template <class _Policy, class _ForwardIterator, class _ForwardOutIterator, class _Predicate, class _Tp>
203 // operator()(_Policy&&, _ForwardIterator __first, _ForwardIterator __last,
204 // _ForwardOutIterator __out_it,
205 // _Predicate __pred,
206 // _Tp const& __new_value) const noexcept;
208 template <class _Backend
, class _ExecutionPolicy
>
209 struct __replace_copy
;
210 // template <class _Policy, class _ForwardIterator, class _ForwardOutIterator, class _Tp>
212 // operator()(_Policy&&, _ForwardIterator __first, _ForwardIterator __last,
213 // _ForwardOutIterator __out_it,
214 // _Tp const& __old_value,
215 // _Tp const& __new_value) const noexcept;
217 template <class _Backend
, class _ExecutionPolicy
>
219 // template <class _Policy, class _ForwardIterator, class _ForwardOutIterator>
220 // optional<_ForwardOutIterator>
221 // operator()(_Policy&&, _ForwardIterator __first, _ForwardIterator __last,
222 // _ForwardOutIterator __out_it) const noexcept;
224 template <class _Backend
, class _ExecutionPolicy
>
226 // template <class _Policy, class _ForwardIterator, class _ForwardOutIterator>
227 // optional<_ForwardOutIterator>
228 // operator()(_Policy&&, _ForwardIterator __first, _ForwardIterator __last,
229 // _ForwardOutIterator __out_it) const noexcept;
231 template <class _Backend
, class _ExecutionPolicy
>
233 // template <class _Policy, class _ForwardIterator, class _Size, class _ForwardOutIterator>
234 // optional<_ForwardOutIterator>
235 // operator()(_Policy&&, _ForwardIterator __first, _Size __n, _ForwardOutIterator __out_it) const noexcept;
237 template <class _Backend
, class _ExecutionPolicy
>
238 struct __rotate_copy
;
239 // template <class _Policy, class _ForwardIterator, class _ForwardOutIterator>
240 // optional<_ForwardOutIterator>
241 // operator()(_Policy&&, _ForwardIterator __first, _ForwardIterator __middle, _ForwardIterator __last,
242 // _ForwardOutIterator __out_it) const noexcept;
244 template <class _Backend
, class _ExecutionPolicy
>
245 struct __transform_reduce
;
246 // template <class _Policy, class _ForwardIterator, class _Tp, class _BinaryOperation, class _UnaryOperation>
248 // operator()(_Policy&&, _ForwardIterator __first, _ForwardIterator __last,
250 // _BinaryOperation __reduce,
251 // _UnaryOperation __transform) const noexcept;
253 template <class _Backend
, class _ExecutionPolicy
>
254 struct __transform_reduce_binary
;
255 // template <class _Policy, class _ForwardIterator1, class _ForwardIterator2,
256 // class _Tp, class _BinaryOperation1, class _BinaryOperation2>
257 // optional<_Tp> operator()(_Policy&&, _ForwardIterator1 __first1, _ForwardIterator1 __last1,
258 // _ForwardIterator2 __first2,
260 // _BinaryOperation1 __reduce,
261 // _BinaryOperation2 __transform) const noexcept;
263 template <class _Backend
, class _ExecutionPolicy
>
265 // template <class _Policy, class _ForwardIterator, class _Predicate>
266 // optional<__iter_diff_t<_ForwardIterator>>
267 // operator()(_Policy&&, _ForwardIterator __first, _ForwardIterator __last, _Predicate __pred) const noexcept;
269 template <class _Backend
, class _ExecutionPolicy
>
271 // template <class _Policy, class _ForwardIterator, class _Tp>
272 // optional<__iter_diff_t<_ForwardIterator>>
273 // operator()(_Policy&&, _ForwardIterator __first, _ForwardIterator __last, _Tp const& __value) const noexcept;
275 template <class _Backend
, class _ExecutionPolicy
>
277 // template <class _Policy, class _ForwardIterator1, class _ForwardIterator2, class _Predicate>
279 // operator()(_Policy&&, _ForwardIterator1 __first1, _ForwardIterator1 __last1,
280 // _ForwardIterator2 __first2,
281 // _Predicate __pred) const noexcept;
283 template <class _Backend
, class _ExecutionPolicy
>
285 // template <class _Policy, class _ForwardIterator1, class _ForwardIterator2, class _Predicate>
287 // operator()(_Policy&&, _ForwardIterator1 __first1, _ForwardIterator1 __last1,
288 // _ForwardIterator2 __first2, _ForwardIterator2 __last2,
289 // _Predicate __pred) const noexcept;
291 template <class _Backend
, class _ExecutionPolicy
>
293 // template <class _Policy, class _ForwardIterator, class _Tp, class _BinaryOperation>
295 // operator()(_Policy&&, _ForwardIterator __first, _ForwardIterator __last,
296 // _Tp __init, _BinaryOperation __op) const noexcept;
298 } // namespace __pstl
299 _LIBCPP_END_NAMESPACE_STD
301 #endif // _LIBCPP_STD_VER >= 17
305 #endif // _LIBCPP___PSTL_BACKEND_FWD_H