Debian Codegraph @

libstdc++-v3/include/pstl/glue_algorithm_impl.h

raw
1 // -*- C++ -*-
2 //===-- glue_algorithm_impl.h ---------------------------------------------===//
3 //
4 // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
5 // See https://llvm.org/LICENSE.txt for license information.
6 // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
7 //
8 //===----------------------------------------------------------------------===//
9
10 #ifndef _PSTL_GLUE_ALGORITHM_IMPL_H
11 #define _PSTL_GLUE_ALGORITHM_IMPL_H
12
13 #include <functional>
14
15 #include "execution_defs.h"
16 #include "utils.h"
17 #include "algorithm_fwd.h"
18 #include "numeric_fwd.h" /* count and count_if use __pattern_transform_reduce */
19
20 namespace std
21 {
22
23 // [alg.any_of]
24
25 template <class _ExecutionPolicy, class _ForwardIterator, class _Predicate>
26 __pstl::__internal::__enable_if_execution_policy<_ExecutionPolicy, bool>
27 any_of(_ExecutionPolicy&& __exec, _ForwardIterator __first, _ForwardIterator __last, _Predicate __pred)
28 {
29 auto __dispatch_tag = __pstl::__internal::__select_backend(__exec, __first);
30
31 return __pstl::__internal::__pattern_any_of(__dispatch_tag, std::forward<_ExecutionPolicy>(__exec), __first, __last,
32 __pred);
33 }
34
35 // [alg.all_of]
36
37 template <class _ExecutionPolicy, class _ForwardIterator, class _Pred>
38 __pstl::__internal::__enable_if_execution_policy<_ExecutionPolicy, bool>
39 all_of(_ExecutionPolicy&& __exec, _ForwardIterator __first, _ForwardIterator __last, _Pred __pred)
40 {
41 return !std::any_of(std::forward<_ExecutionPolicy>(__exec), __first, __last, std::not_fn(__pred));
42 }
43
44 // [alg.none_of]
45
46 template <class _ExecutionPolicy, class _ForwardIterator, class _Predicate>
47 __pstl::__internal::__enable_if_execution_policy<_ExecutionPolicy, bool>
48 none_of(_ExecutionPolicy&& __exec, _ForwardIterator __first, _ForwardIterator __last, _Predicate __pred)
49 {
50 return !std::any_of(std::forward<_ExecutionPolicy>(__exec), __first, __last, __pred);
51 }
52
53 // [alg.foreach]
54
55 template <class _ExecutionPolicy, class _ForwardIterator, class _Function>
56 __pstl::__internal::__enable_if_execution_policy<_ExecutionPolicy, void>
57 for_each(_ExecutionPolicy&& __exec, _ForwardIterator __first, _ForwardIterator __last, _Function __f)
58 {
59 auto __dispatch_tag = __pstl::__internal::__select_backend(__exec, __first);
60
61 __pstl::__internal::__pattern_walk1(__dispatch_tag, std::forward<_ExecutionPolicy>(__exec), __first, __last, __f);
62 }
63
64 template <class _ExecutionPolicy, class _ForwardIterator, class _Size, class _Function>
65 __pstl::__internal::__enable_if_execution_policy<_ExecutionPolicy, _ForwardIterator>
66 for_each_n(_ExecutionPolicy&& __exec, _ForwardIterator __first, _Size __n, _Function __f)
67 {
68 auto __dispatch_tag = __pstl::__internal::__select_backend(__exec, __first);
69
70 return __pstl::__internal::__pattern_walk1_n(__dispatch_tag, std::forward<_ExecutionPolicy>(__exec), __first, __n,
71 __f);
72 }
73
74 // [alg.find]
75
76 template <class _ExecutionPolicy, class _ForwardIterator, class _Predicate>
77 __pstl::__internal::__enable_if_execution_policy<_ExecutionPolicy, _ForwardIterator>
78 find_if(_ExecutionPolicy&& __exec, _ForwardIterator __first, _ForwardIterator __last, _Predicate __pred)
79 {
80 auto __dispatch_tag = __pstl::__internal::__select_backend(__exec, __first);
81
82 return __pstl::__internal::__pattern_find_if(__dispatch_tag, std::forward<_ExecutionPolicy>(__exec), __first,
83 __last, __pred);
84 }
85
86 template <class _ExecutionPolicy, class _ForwardIterator, class _Predicate>
87 __pstl::__internal::__enable_if_execution_policy<_ExecutionPolicy, _ForwardIterator>
88 find_if_not(_ExecutionPolicy&& __exec, _ForwardIterator __first, _ForwardIterator __last, _Predicate __pred)
89 {
90 return std::find_if(std::forward<_ExecutionPolicy>(__exec), __first, __last, std::not_fn(__pred));
91 }
92
93 template <class _ExecutionPolicy, class _ForwardIterator, class _Tp>
94 __pstl::__internal::__enable_if_execution_policy<_ExecutionPolicy, _ForwardIterator>
95 find(_ExecutionPolicy&& __exec, _ForwardIterator __first, _ForwardIterator __last, const _Tp& __value)
96 {
97 return std::find_if(std::forward<_ExecutionPolicy>(__exec), __first, __last,
98 __pstl::__internal::__equal_value<_Tp>(__value));
99 }
100
101 // [alg.find.end]
102 template <class _ExecutionPolicy, class _ForwardIterator1, class _ForwardIterator2, class _BinaryPredicate>
103 __pstl::__internal::__enable_if_execution_policy<_ExecutionPolicy, _ForwardIterator1>
104 find_end(_ExecutionPolicy&& __exec, _ForwardIterator1 __first, _ForwardIterator1 __last, _ForwardIterator2 __s_first,
105 _ForwardIterator2 __s_last, _BinaryPredicate __pred)
106 {
107 auto __dispatch_tag = __pstl::__internal::__select_backend(__exec, __first, __s_first);
108
109 return __pstl::__internal::__pattern_find_end(__dispatch_tag, std::forward<_ExecutionPolicy>(__exec), __first,
110 __last, __s_first, __s_last, __pred);
111 }
112
113 template <class _ExecutionPolicy, class _ForwardIterator1, class _ForwardIterator2>
114 __pstl::__internal::__enable_if_execution_policy<_ExecutionPolicy, _ForwardIterator1>
115 find_end(_ExecutionPolicy&& __exec, _ForwardIterator1 __first, _ForwardIterator1 __last, _ForwardIterator2 __s_first,
116 _ForwardIterator2 __s_last)
117 {
118 return std::find_end(std::forward<_ExecutionPolicy>(__exec), __first, __last, __s_first, __s_last,
119 std::equal_to<>());
120 }
121
122 // [alg.find_first_of]
123 template <class _ExecutionPolicy, class _ForwardIterator1, class _ForwardIterator2, class _BinaryPredicate>
124 __pstl::__internal::__enable_if_execution_policy<_ExecutionPolicy, _ForwardIterator1>
125 find_first_of(_ExecutionPolicy&& __exec, _ForwardIterator1 __first, _ForwardIterator1 __last,
126 _ForwardIterator2 __s_first, _ForwardIterator2 __s_last, _BinaryPredicate __pred)
127 {
128 auto __dispatch_tag = __pstl::__internal::__select_backend(__exec, __first, __s_first);
129
130 return __pstl::__internal::__pattern_find_first_of(__dispatch_tag, std::forward<_ExecutionPolicy>(__exec), __first,
131 __last, __s_first, __s_last, __pred);
132 }
133
134 template <class _ExecutionPolicy, class _ForwardIterator1, class _ForwardIterator2>
135 __pstl::__internal::__enable_if_execution_policy<_ExecutionPolicy, _ForwardIterator1>
136 find_first_of(_ExecutionPolicy&& __exec, _ForwardIterator1 __first, _ForwardIterator1 __last,
137 _ForwardIterator2 __s_first, _ForwardIterator2 __s_last)
138 {
139 return std::find_first_of(std::forward<_ExecutionPolicy>(__exec), __first, __last, __s_first, __s_last,
140 std::equal_to<>());
141 }
142
143 // [alg.adjacent_find]
144 template <class _ExecutionPolicy, class _ForwardIterator>
145 __pstl::__internal::__enable_if_execution_policy<_ExecutionPolicy, _ForwardIterator>
146 adjacent_find(_ExecutionPolicy&& __exec, _ForwardIterator __first, _ForwardIterator __last)
147 {
148 auto __dispatch_tag = __pstl::__internal::__select_backend(__exec, __first);
149
150 typedef typename iterator_traits<_ForwardIterator>::value_type _ValueType;
151 return __pstl::__internal::__pattern_adjacent_find(__dispatch_tag, std::forward<_ExecutionPolicy>(__exec), __first,
152 __last, std::equal_to<_ValueType>(), /*first_semantic*/ false);
153 }
154
155 template <class _ExecutionPolicy, class _ForwardIterator, class _BinaryPredicate>
156 __pstl::__internal::__enable_if_execution_policy<_ExecutionPolicy, _ForwardIterator>
157 adjacent_find(_ExecutionPolicy&& __exec, _ForwardIterator __first, _ForwardIterator __last, _BinaryPredicate __pred)
158 {
159 auto __dispatch_tag = __pstl::__internal::__select_backend(__exec, __first);
160 return __pstl::__internal::__pattern_adjacent_find(__dispatch_tag, std::forward<_ExecutionPolicy>(__exec), __first,
161 __last, __pred, /*first_semantic*/ false);
162 }
163
164 // [alg.count]
165
166 // Implementation note: count and count_if call the pattern directly instead of calling std::transform_reduce
167 // so that we do not have to include <numeric>.
168
169 template <class _ExecutionPolicy, class _ForwardIterator, class _Tp>
170 __pstl::__internal::__enable_if_execution_policy<_ExecutionPolicy,
171 typename iterator_traits<_ForwardIterator>::difference_type>
172 count(_ExecutionPolicy&& __exec, _ForwardIterator __first, _ForwardIterator __last, const _Tp& __value)
173 {
174 auto __dispatch_tag = __pstl::__internal::__select_backend(__exec, __first);
175
176 typedef typename iterator_traits<_ForwardIterator>::value_type _ValueType;
177 return __pstl::__internal::__pattern_count(__dispatch_tag, std::forward<_ExecutionPolicy>(__exec), __first, __last,
178 [&__value](const _ValueType& __x) { return __value == __x; });
179 }
180
181 template <class _ExecutionPolicy, class _ForwardIterator, class _Predicate>
182 __pstl::__internal::__enable_if_execution_policy<_ExecutionPolicy,
183 typename iterator_traits<_ForwardIterator>::difference_type>
184 count_if(_ExecutionPolicy&& __exec, _ForwardIterator __first, _ForwardIterator __last, _Predicate __pred)
185 {
186 auto __dispatch_tag = __pstl::__internal::__select_backend(__exec, __first);
187 return __pstl::__internal::__pattern_count(__dispatch_tag, std::forward<_ExecutionPolicy>(__exec), __first, __last,
188 __pred);
189 }
190
191 // [alg.search]
192
193 template <class _ExecutionPolicy, class _ForwardIterator1, class _ForwardIterator2, class _BinaryPredicate>
194 __pstl::__internal::__enable_if_execution_policy<_ExecutionPolicy, _ForwardIterator1>
195 search(_ExecutionPolicy&& __exec, _ForwardIterator1 __first, _ForwardIterator1 __last, _ForwardIterator2 __s_first,
196 _ForwardIterator2 __s_last, _BinaryPredicate __pred)
197 {
198 auto __dispatch_tag = __pstl::__internal::__select_backend(__exec, __first, __s_first);
199
200 return __pstl::__internal::__pattern_search(__dispatch_tag, std::forward<_ExecutionPolicy>(__exec), __first, __last,
201 __s_first, __s_last, __pred);
202 }
203
204 template <class _ExecutionPolicy, class _ForwardIterator1, class _ForwardIterator2>
205 __pstl::__internal::__enable_if_execution_policy<_ExecutionPolicy, _ForwardIterator1>
206 search(_ExecutionPolicy&& __exec, _ForwardIterator1 __first, _ForwardIterator1 __last, _ForwardIterator2 __s_first,
207 _ForwardIterator2 __s_last)
208 {
209 return std::search(std::forward<_ExecutionPolicy>(__exec), __first, __last, __s_first, __s_last, std::equal_to<>());
210 }
211
212 template <class _ExecutionPolicy, class _ForwardIterator, class _Size, class _Tp, class _BinaryPredicate>
213 __pstl::__internal::__enable_if_execution_policy<_ExecutionPolicy, _ForwardIterator>
214 search_n(_ExecutionPolicy&& __exec, _ForwardIterator __first, _ForwardIterator __last, _Size __count,
215 const _Tp& __value, _BinaryPredicate __pred)
216 {
217 auto __dispatch_tag = __pstl::__internal::__select_backend(__exec, __first);
218
219 return __pstl::__internal::__pattern_search_n(__dispatch_tag, std::forward<_ExecutionPolicy>(__exec), __first,
220 __last, __count, __value, __pred);
221 }
222
223 template <class _ExecutionPolicy, class _ForwardIterator, class _Size, class _Tp>
224 __pstl::__internal::__enable_if_execution_policy<_ExecutionPolicy, _ForwardIterator>
225 search_n(_ExecutionPolicy&& __exec, _ForwardIterator __first, _ForwardIterator __last, _Size __count,
226 const _Tp& __value)
227 {
228 return std::search_n(std::forward<_ExecutionPolicy>(__exec), __first, __last, __count, __value,
229 std::equal_to<typename iterator_traits<_ForwardIterator>::value_type>());
230 }
231
232 // [alg.copy]
233
234 template <class _ExecutionPolicy, class _ForwardIterator1, class _ForwardIterator2>
235 __pstl::__internal::__enable_if_execution_policy<_ExecutionPolicy, _ForwardIterator2>
236 copy(_ExecutionPolicy&& __exec, _ForwardIterator1 __first, _ForwardIterator1 __last, _ForwardIterator2 __result)
237 {
238 auto __dispatch_tag = __pstl::__internal::__select_backend(__exec, __first, __result);
239
240 using __is_vector = typename decltype(__dispatch_tag)::__is_vector;
241
242 return __pstl::__internal::__pattern_walk2_brick(
243 __dispatch_tag, std::forward<_ExecutionPolicy>(__exec), __first, __last, __result,
244 [](_ForwardIterator1 __begin, _ForwardIterator1 __end, _ForwardIterator2 __res)
245 { return __pstl::__internal::__brick_copy(__begin, __end, __res, __is_vector{}); });
246 }
247
248 template <class _ExecutionPolicy, class _ForwardIterator1, class _Size, class _ForwardIterator2>
249 __pstl::__internal::__enable_if_execution_policy<_ExecutionPolicy, _ForwardIterator2>
250 copy_n(_ExecutionPolicy&& __exec, _ForwardIterator1 __first, _Size __n, _ForwardIterator2 __result)
251 {
252 auto __dispatch_tag = __pstl::__internal::__select_backend(__exec, __first, __result);
253
254 using __is_vector = typename decltype(__dispatch_tag)::__is_vector;
255
256 return __pstl::__internal::__pattern_walk2_brick_n(
257 __dispatch_tag, std::forward<_ExecutionPolicy>(__exec), __first, __n, __result,
258 [](_ForwardIterator1 __begin, _Size __sz, _ForwardIterator2 __res)
259 { return __pstl::__internal::__brick_copy_n(__begin, __sz, __res, __is_vector{}); });
260 }
261
262 template <class _ExecutionPolicy, class _ForwardIterator1, class _ForwardIterator2, class _Predicate>
263 __pstl::__internal::__enable_if_execution_policy<_ExecutionPolicy, _ForwardIterator2>
264 copy_if(_ExecutionPolicy&& __exec, _ForwardIterator1 __first, _ForwardIterator1 __last, _ForwardIterator2 __result,
265 _Predicate __pred)
266 {
267 auto __dispatch_tag = __pstl::__internal::__select_backend(__exec, __first, __result);
268
269 return __pstl::__internal::__pattern_copy_if(__dispatch_tag, std::forward<_ExecutionPolicy>(__exec), __first,
270 __last, __result, __pred);
271 }
272
273 // [alg.swap]
274
275 template <class _ExecutionPolicy, class _ForwardIterator1, class _ForwardIterator2>
276 __pstl::__internal::__enable_if_execution_policy<_ExecutionPolicy, _ForwardIterator2>
277 swap_ranges(_ExecutionPolicy&& __exec, _ForwardIterator1 __first1, _ForwardIterator1 __last1,
278 _ForwardIterator2 __first2)
279 {
280 typedef typename iterator_traits<_ForwardIterator1>::reference _ReferenceType1;
281 typedef typename iterator_traits<_ForwardIterator2>::reference _ReferenceType2;
282
283 auto __dispatch_tag = __pstl::__internal::__select_backend(__exec, __first1, __first2);
284
285 return __pstl::__internal::__pattern_walk2(__dispatch_tag, std::forward<_ExecutionPolicy>(__exec), __first1,
286 __last1, __first2,
287 [](_ReferenceType1 __x, _ReferenceType2 __y)
288 {
289 using std::swap;
290 swap(__x, __y);
291 });
292 }
293
294 // [alg.transform]
295
296 template <class _ExecutionPolicy, class _ForwardIterator1, class _ForwardIterator2, class _UnaryOperation>
297 __pstl::__internal::__enable_if_execution_policy<_ExecutionPolicy, _ForwardIterator2>
298 transform(_ExecutionPolicy&& __exec, _ForwardIterator1 __first, _ForwardIterator1 __last, _ForwardIterator2 __result,
299 _UnaryOperation __op)
300 {
301 typedef typename iterator_traits<_ForwardIterator1>::reference _InputType;
302 typedef typename iterator_traits<_ForwardIterator2>::reference _OutputType;
303
304 auto __dispatch_tag = __pstl::__internal::__select_backend(__exec, __first, __result);
305
306 return __pstl::__internal::__pattern_walk2(__dispatch_tag, std::forward<_ExecutionPolicy>(__exec), __first, __last,
307 __result,
308 [__op](_InputType __x, _OutputType __y) mutable { __y = __op(__x); });
309 }
310
311 template <class _ExecutionPolicy, class _ForwardIterator1, class _ForwardIterator2, class _ForwardIterator,
312 class _BinaryOperation>
313 __pstl::__internal::__enable_if_execution_policy<_ExecutionPolicy, _ForwardIterator>
314 transform(_ExecutionPolicy&& __exec, _ForwardIterator1 __first1, _ForwardIterator1 __last1, _ForwardIterator2 __first2,
315 _ForwardIterator __result, _BinaryOperation __op)
316 {
317 typedef typename iterator_traits<_ForwardIterator1>::reference _Input1Type;
318 typedef typename iterator_traits<_ForwardIterator2>::reference _Input2Type;
319 typedef typename iterator_traits<_ForwardIterator>::reference _OutputType;
320
321 auto __dispatch_tag = __pstl::__internal::__select_backend(__exec, __first1, __first2, __result);
322
323 return __pstl::__internal::__pattern_walk3(
324 __dispatch_tag, std::forward<_ExecutionPolicy>(__exec), __first1, __last1, __first2, __result,
325 [__op](_Input1Type __x, _Input2Type __y, _OutputType __z) mutable { __z = __op(__x, __y); });
326 }
327
328 // [alg.replace]
329
330 template <class _ExecutionPolicy, class _ForwardIterator, class _UnaryPredicate, class _Tp>
331 __pstl::__internal::__enable_if_execution_policy<_ExecutionPolicy, void>
332 replace_if(_ExecutionPolicy&& __exec, _ForwardIterator __first, _ForwardIterator __last, _UnaryPredicate __pred,
333 const _Tp& __new_value)
334 {
335 typedef typename iterator_traits<_ForwardIterator>::reference _ElementType;
336
337 auto __dispatch_tag = __pstl::__internal::__select_backend(__exec, __first);
338
339 __pstl::__internal::__pattern_walk1(__dispatch_tag, std::forward<_ExecutionPolicy>(__exec), __first, __last,
340 [&__pred, &__new_value](_ElementType __elem)
341 {
342 if (__pred(__elem))
343 {
344 __elem = __new_value;
345 }
346 });
347 }
348
349 template <class _ExecutionPolicy, class _ForwardIterator, class _Tp>
350 __pstl::__internal::__enable_if_execution_policy<_ExecutionPolicy, void>
351 replace(_ExecutionPolicy&& __exec, _ForwardIterator __first, _ForwardIterator __last, const _Tp& __old_value,
352 const _Tp& __new_value)
353 {
354 std::replace_if(std::forward<_ExecutionPolicy>(__exec), __first, __last,
355 __pstl::__internal::__equal_value<_Tp>(__old_value), __new_value);
356 }
357
358 template <class _ExecutionPolicy, class _ForwardIterator1, class _ForwardIterator2, class _UnaryPredicate, class _Tp>
359 __pstl::__internal::__enable_if_execution_policy<_ExecutionPolicy, _ForwardIterator2>
360 replace_copy_if(_ExecutionPolicy&& __exec, _ForwardIterator1 __first, _ForwardIterator1 __last,
361 _ForwardIterator2 __result, _UnaryPredicate __pred, const _Tp& __new_value)
362 {
363 typedef typename iterator_traits<_ForwardIterator1>::reference _InputType;
364 typedef typename iterator_traits<_ForwardIterator2>::reference _OutputType;
365
366 auto __dispatch_tag = __pstl::__internal::__select_backend(__exec, __first, __result);
367
368 return __pstl::__internal::__pattern_walk2(
369 __dispatch_tag, std::forward<_ExecutionPolicy>(__exec), __first, __last, __result,
370 [__pred, &__new_value](_InputType __x, _OutputType __y) mutable { __y = __pred(__x) ? __new_value : __x; });
371 }
372
373 template <class _ExecutionPolicy, class _ForwardIterator1, class _ForwardIterator2, class _Tp>
374 __pstl::__internal::__enable_if_execution_policy<_ExecutionPolicy, _ForwardIterator2>
375 replace_copy(_ExecutionPolicy&& __exec, _ForwardIterator1 __first, _ForwardIterator1 __last, _ForwardIterator2 __result,
376 const _Tp& __old_value, const _Tp& __new_value)
377 {
378 return std::replace_copy_if(std::forward<_ExecutionPolicy>(__exec), __first, __last, __result,
379 __pstl::__internal::__equal_value<_Tp>(__old_value), __new_value);
380 }
381
382 // [alg.fill]
383
384 template <class _ExecutionPolicy, class _ForwardIterator, class _Tp>
385 __pstl::__internal::__enable_if_execution_policy<_ExecutionPolicy, void>
386 fill(_ExecutionPolicy&& __exec, _ForwardIterator __first, _ForwardIterator __last, const _Tp& __value)
387 {
388 auto __dispatch_tag = __pstl::__internal::__select_backend(__exec, __first);
389
390 __pstl::__internal::__pattern_fill(__dispatch_tag, std::forward<_ExecutionPolicy>(__exec), __first, __last,
391 __value);
392 }
393
394 template <class _ExecutionPolicy, class _ForwardIterator, class _Size, class _Tp>
395 __pstl::__internal::__enable_if_execution_policy<_ExecutionPolicy, _ForwardIterator>
396 fill_n(_ExecutionPolicy&& __exec, _ForwardIterator __first, _Size __count, const _Tp& __value)
397 {
398 if (__count <= 0)
399 return __first;
400
401 auto __dispatch_tag = __pstl::__internal::__select_backend(__exec, __first);
402
403 return __pstl::__internal::__pattern_fill_n(__dispatch_tag, std::forward<_ExecutionPolicy>(__exec), __first,
404 __count, __value);
405 }
406
407 // [alg.generate]
408 template <class _ExecutionPolicy, class _ForwardIterator, class _Generator>
409 __pstl::__internal::__enable_if_execution_policy<_ExecutionPolicy, void>
410 generate(_ExecutionPolicy&& __exec, _ForwardIterator __first, _ForwardIterator __last, _Generator __g)
411 {
412 auto __dispatch_tag = __pstl::__internal::__select_backend(__exec, __first);
413
414 __pstl::__internal::__pattern_generate(__dispatch_tag, std::forward<_ExecutionPolicy>(__exec), __first, __last,
415 __g);
416 }
417
418 template <class _ExecutionPolicy, class _ForwardIterator, class _Size, class _Generator>
419 __pstl::__internal::__enable_if_execution_policy<_ExecutionPolicy, _ForwardIterator>
420 generate_n(_ExecutionPolicy&& __exec, _ForwardIterator __first, _Size __count, _Generator __g)
421 {
422 if (__count <= 0)
423 return __first;
424
425 auto __dispatch_tag = __pstl::__internal::__select_backend(__exec, __first);
426
427 return __pstl::__internal::__pattern_generate_n(__dispatch_tag, std::forward<_ExecutionPolicy>(__exec), __first,
428 __count, __g);
429 }
430
431 // [alg.remove]
432
433 template <class _ExecutionPolicy, class _ForwardIterator1, class _ForwardIterator2, class _Predicate>
434 __pstl::__internal::__enable_if_execution_policy<_ExecutionPolicy, _ForwardIterator2>
435 remove_copy_if(_ExecutionPolicy&& __exec, _ForwardIterator1 __first, _ForwardIterator1 __last,
436 _ForwardIterator2 __result, _Predicate __pred)
437 {
438 return std::copy_if(std::forward<_ExecutionPolicy>(__exec), __first, __last, __result, std::not_fn(__pred));
439 }
440
441 template <class _ExecutionPolicy, class _ForwardIterator1, class _ForwardIterator2, class _Tp>
442 __pstl::__internal::__enable_if_execution_policy<_ExecutionPolicy, _ForwardIterator2>
443 remove_copy(_ExecutionPolicy&& __exec, _ForwardIterator1 __first, _ForwardIterator1 __last, _ForwardIterator2 __result,
444 const _Tp& __value)
445 {
446 return std::copy_if(std::forward<_ExecutionPolicy>(__exec), __first, __last, __result,
447 __pstl::__internal::__not_equal_value<_Tp>(__value));
448 }
449
450 template <class _ExecutionPolicy, class _ForwardIterator, class _UnaryPredicate>
451 __pstl::__internal::__enable_if_execution_policy<_ExecutionPolicy, _ForwardIterator>
452 remove_if(_ExecutionPolicy&& __exec, _ForwardIterator __first, _ForwardIterator __last, _UnaryPredicate __pred)
453 {
454 auto __dispatch_tag = __pstl::__internal::__select_backend(__exec, __first);
455
456 return __pstl::__internal::__pattern_remove_if(__dispatch_tag, std::forward<_ExecutionPolicy>(__exec), __first,
457 __last, __pred);
458 }
459
460 template <class _ExecutionPolicy, class _ForwardIterator, class _Tp>
461 __pstl::__internal::__enable_if_execution_policy<_ExecutionPolicy, _ForwardIterator>
462 remove(_ExecutionPolicy&& __exec, _ForwardIterator __first, _ForwardIterator __last, const _Tp& __value)
463 {
464 return std::remove_if(std::forward<_ExecutionPolicy>(__exec), __first, __last,
465 __pstl::__internal::__equal_value<_Tp>(__value));
466 }
467
468 // [alg.unique]
469
470 template <class _ExecutionPolicy, class _ForwardIterator, class _BinaryPredicate>
471 __pstl::__internal::__enable_if_execution_policy<_ExecutionPolicy, _ForwardIterator>
472 unique(_ExecutionPolicy&& __exec, _ForwardIterator __first, _ForwardIterator __last, _BinaryPredicate __pred)
473 {
474 auto __dispatch_tag = __pstl::__internal::__select_backend(__exec, __first);
475
476 return __pstl::__internal::__pattern_unique(__dispatch_tag, std::forward<_ExecutionPolicy>(__exec), __first, __last,
477 __pred);
478 }
479
480 template <class _ExecutionPolicy, class _ForwardIterator>
481 __pstl::__internal::__enable_if_execution_policy<_ExecutionPolicy, _ForwardIterator>
482 unique(_ExecutionPolicy&& __exec, _ForwardIterator __first, _ForwardIterator __last)
483 {
484 return std::unique(std::forward<_ExecutionPolicy>(__exec), __first, __last, std::equal_to<>());
485 }
486
487 template <class _ExecutionPolicy, class _ForwardIterator1, class _ForwardIterator2, class _BinaryPredicate>
488 __pstl::__internal::__enable_if_execution_policy<_ExecutionPolicy, _ForwardIterator2>
489 unique_copy(_ExecutionPolicy&& __exec, _ForwardIterator1 __first, _ForwardIterator1 __last, _ForwardIterator2 __result,
490 _BinaryPredicate __pred)
491 {
492 auto __dispatch_tag = __pstl::__internal::__select_backend(__exec, __first, __result);
493
494 return __pstl::__internal::__pattern_unique_copy(__dispatch_tag, std::forward<_ExecutionPolicy>(__exec), __first,
495 __last, __result, __pred);
496 }
497
498 template <class _ExecutionPolicy, class _ForwardIterator1, class _ForwardIterator2>
499 __pstl::__internal::__enable_if_execution_policy<_ExecutionPolicy, _ForwardIterator2>
500 unique_copy(_ExecutionPolicy&& __exec, _ForwardIterator1 __first, _ForwardIterator1 __last, _ForwardIterator2 __result)
501 {
502 return std::unique_copy(__exec, __first, __last, __result, std::equal_to<>());
503 }
504
505 // [alg.reverse]
506
507 template <class _ExecutionPolicy, class _BidirectionalIterator>
508 __pstl::__internal::__enable_if_execution_policy<_ExecutionPolicy, void>
509 reverse(_ExecutionPolicy&& __exec, _BidirectionalIterator __first, _BidirectionalIterator __last)
510 {
511 auto __dispatch_tag = __pstl::__internal::__select_backend(__exec, __first);
512
513 __pstl::__internal::__pattern_reverse(__dispatch_tag, std::forward<_ExecutionPolicy>(__exec), __first, __last);
514 }
515
516 template <class _ExecutionPolicy, class _BidirectionalIterator, class _ForwardIterator>
517 __pstl::__internal::__enable_if_execution_policy<_ExecutionPolicy, _ForwardIterator>
518 reverse_copy(_ExecutionPolicy&& __exec, _BidirectionalIterator __first, _BidirectionalIterator __last,
519 _ForwardIterator __d_first)
520 {
521 auto __dispatch_tag = __pstl::__internal::__select_backend(__exec, __first, __d_first);
522
523 return __pstl::__internal::__pattern_reverse_copy(__dispatch_tag, std::forward<_ExecutionPolicy>(__exec), __first,
524 __last, __d_first);
525 }
526
527 // [alg.rotate]
528
529 template <class _ExecutionPolicy, class _ForwardIterator>
530 __pstl::__internal::__enable_if_execution_policy<_ExecutionPolicy, _ForwardIterator>
531 rotate(_ExecutionPolicy&& __exec, _ForwardIterator __first, _ForwardIterator __middle, _ForwardIterator __last)
532 {
533 auto __dispatch_tag = __pstl::__internal::__select_backend(__exec, __first);
534
535 return __pstl::__internal::__pattern_rotate(__dispatch_tag, std::forward<_ExecutionPolicy>(__exec), __first,
536 __middle, __last);
537 }
538
539 template <class _ExecutionPolicy, class _ForwardIterator1, class _ForwardIterator2>
540 __pstl::__internal::__enable_if_execution_policy<_ExecutionPolicy, _ForwardIterator2>
541 rotate_copy(_ExecutionPolicy&& __exec, _ForwardIterator1 __first, _ForwardIterator1 __middle, _ForwardIterator1 __last,
542 _ForwardIterator2 __result)
543 {
544 auto __dispatch_tag = __pstl::__internal::__select_backend(__exec, __first, __result);
545
546 return __pstl::__internal::__pattern_rotate_copy(__dispatch_tag, std::forward<_ExecutionPolicy>(__exec), __first,
547 __middle, __last, __result);
548 }
549
550 // [alg.partitions]
551
552 template <class _ExecutionPolicy, class _ForwardIterator, class _UnaryPredicate>
553 __pstl::__internal::__enable_if_execution_policy<_ExecutionPolicy, bool>
554 is_partitioned(_ExecutionPolicy&& __exec, _ForwardIterator __first, _ForwardIterator __last, _UnaryPredicate __pred)
555 {
556 auto __dispatch_tag = __pstl::__internal::__select_backend(__exec, __first);
557 return __pstl::__internal::__pattern_is_partitioned(__dispatch_tag, std::forward<_ExecutionPolicy>(__exec), __first,
558 __last, __pred);
559 }
560
561 template <class _ExecutionPolicy, class _ForwardIterator, class _UnaryPredicate>
562 __pstl::__internal::__enable_if_execution_policy<_ExecutionPolicy, _ForwardIterator>
563 partition(_ExecutionPolicy&& __exec, _ForwardIterator __first, _ForwardIterator __last, _UnaryPredicate __pred)
564 {
565 auto __dispatch_tag = __pstl::__internal::__select_backend(__exec, __first);
566
567 return __pstl::__internal::__pattern_partition(__dispatch_tag, std::forward<_ExecutionPolicy>(__exec), __first,
568 __last, __pred);
569 }
570
571 template <class _ExecutionPolicy, class _BidirectionalIterator, class _UnaryPredicate>
572 __pstl::__internal::__enable_if_execution_policy<_ExecutionPolicy, _BidirectionalIterator>
573 stable_partition(_ExecutionPolicy&& __exec, _BidirectionalIterator __first, _BidirectionalIterator __last,
574 _UnaryPredicate __pred)
575 {
576 auto __dispatch_tag = __pstl::__internal::__select_backend(__exec, __first);
577 return __pstl::__internal::__pattern_stable_partition(__dispatch_tag, std::forward<_ExecutionPolicy>(__exec),
578 __first, __last, __pred);
579 }
580
581 template <class _ExecutionPolicy, class _ForwardIterator, class _ForwardIterator1, class _ForwardIterator2,
582 class _UnaryPredicate>
583 __pstl::__internal::__enable_if_execution_policy<_ExecutionPolicy, std::pair<_ForwardIterator1, _ForwardIterator2>>
584 partition_copy(_ExecutionPolicy&& __exec, _ForwardIterator __first, _ForwardIterator __last,
585 _ForwardIterator1 __out_true, _ForwardIterator2 __out_false, _UnaryPredicate __pred)
586 {
587 auto __dispatch_tag = __pstl::__internal::__select_backend(__exec, __first, __out_true, __out_false);
588
589 return __pstl::__internal::__pattern_partition_copy(__dispatch_tag, std::forward<_ExecutionPolicy>(__exec), __first,
590 __last, __out_true, __out_false, __pred);
591 }
592
593 // [alg.sort]
594
595 template <class _ExecutionPolicy, class _RandomAccessIterator, class _Compare>
596 __pstl::__internal::__enable_if_execution_policy<_ExecutionPolicy, void>
597 sort(_ExecutionPolicy&& __exec, _RandomAccessIterator __first, _RandomAccessIterator __last, _Compare __comp)
598 {
599 auto __dispatch_tag = __pstl::__internal::__select_backend(__exec, __first);
600
601 typedef typename iterator_traits<_RandomAccessIterator>::value_type _InputType;
602 return __pstl::__internal::__pattern_sort(__dispatch_tag, std::forward<_ExecutionPolicy>(__exec), __first, __last,
603 __comp, typename std::is_move_constructible<_InputType>::type());
604 }
605
606 template <class _ExecutionPolicy, class _RandomAccessIterator>
607 __pstl::__internal::__enable_if_execution_policy<_ExecutionPolicy, void>
608 sort(_ExecutionPolicy&& __exec, _RandomAccessIterator __first, _RandomAccessIterator __last)
609 {
610 typedef typename std::iterator_traits<_RandomAccessIterator>::value_type _InputType;
611 std::sort(std::forward<_ExecutionPolicy>(__exec), __first, __last, std::less<_InputType>());
612 }
613
614 // [stable.sort]
615
616 template <class _ExecutionPolicy, class _RandomAccessIterator, class _Compare>
617 __pstl::__internal::__enable_if_execution_policy<_ExecutionPolicy, void>
618 stable_sort(_ExecutionPolicy&& __exec, _RandomAccessIterator __first, _RandomAccessIterator __last, _Compare __comp)
619 {
620 auto __dispatch_tag = __pstl::__internal::__select_backend(__exec, __first);
621
622 return __pstl::__internal::__pattern_stable_sort(__dispatch_tag, std::forward<_ExecutionPolicy>(__exec), __first,
623 __last, __comp);
624 }
625
626 template <class _ExecutionPolicy, class _RandomAccessIterator>
627 __pstl::__internal::__enable_if_execution_policy<_ExecutionPolicy, void>
628 stable_sort(_ExecutionPolicy&& __exec, _RandomAccessIterator __first, _RandomAccessIterator __last)
629 {
630 typedef typename std::iterator_traits<_RandomAccessIterator>::value_type _InputType;
631 std::stable_sort(__exec, __first, __last, std::less<_InputType>());
632 }
633
634 // [mismatch]
635
636 template <class _ExecutionPolicy, class _ForwardIterator1, class _ForwardIterator2, class _BinaryPredicate>
637 __pstl::__internal::__enable_if_execution_policy<_ExecutionPolicy, std::pair<_ForwardIterator1, _ForwardIterator2>>
638 mismatch(_ExecutionPolicy&& __exec, _ForwardIterator1 __first1, _ForwardIterator1 __last1, _ForwardIterator2 __first2,
639 _ForwardIterator2 __last2, _BinaryPredicate __pred)
640 {
641 auto __dispatch_tag = __pstl::__internal::__select_backend(__exec, __first1, __first2);
642
643 return __pstl::__internal::__pattern_mismatch(__dispatch_tag, std::forward<_ExecutionPolicy>(__exec), __first1,
644 __last1, __first2, __last2, __pred);
645 }
646
647 template <class _ExecutionPolicy, class _ForwardIterator1, class _ForwardIterator2, class _BinaryPredicate>
648 __pstl::__internal::__enable_if_execution_policy<_ExecutionPolicy, std::pair<_ForwardIterator1, _ForwardIterator2>>
649 mismatch(_ExecutionPolicy&& __exec, _ForwardIterator1 __first1, _ForwardIterator1 __last1, _ForwardIterator2 __first2,
650 _BinaryPredicate __pred)
651 {
652 return std::mismatch(__exec, __first1, __last1, __first2, std::next(__first2, std::distance(__first1, __last1)),
653 __pred);
654 }
655
656 template <class _ExecutionPolicy, class _ForwardIterator1, class _ForwardIterator2>
657 __pstl::__internal::__enable_if_execution_policy<_ExecutionPolicy, std::pair<_ForwardIterator1, _ForwardIterator2>>
658 mismatch(_ExecutionPolicy&& __exec, _ForwardIterator1 __first1, _ForwardIterator1 __last1, _ForwardIterator2 __first2,
659 _ForwardIterator2 __last2)
660 {
661 return std::mismatch(std::forward<_ExecutionPolicy>(__exec), __first1, __last1, __first2, __last2,
662 std::equal_to<>());
663 }
664
665 template <class _ExecutionPolicy, class _ForwardIterator1, class _ForwardIterator2>
666 __pstl::__internal::__enable_if_execution_policy<_ExecutionPolicy, std::pair<_ForwardIterator1, _ForwardIterator2>>
667 mismatch(_ExecutionPolicy&& __exec, _ForwardIterator1 __first1, _ForwardIterator1 __last1, _ForwardIterator2 __first2)
668 {
669 //TODO: to get rid of "distance"
670 return std::mismatch(std::forward<_ExecutionPolicy>(__exec), __first1, __last1, __first2,
671 std::next(__first2, std::distance(__first1, __last1)));
672 }
673
674 // [alg.equal]
675
676 template <class _ExecutionPolicy, class _ForwardIterator1, class _ForwardIterator2, class _BinaryPredicate>
677 __pstl::__internal::__enable_if_execution_policy<_ExecutionPolicy, bool>
678 equal(_ExecutionPolicy&& __exec, _ForwardIterator1 __first1, _ForwardIterator1 __last1, _ForwardIterator2 __first2,
679 _BinaryPredicate __p)
680 {
681 auto __dispatch_tag = __pstl::__internal::__select_backend(__exec, __first1, __first2);
682
683 return __pstl::__internal::__pattern_equal(__dispatch_tag, std::forward<_ExecutionPolicy>(__exec), __first1,
684 __last1, __first2, __p);
685 }
686
687 template <class _ExecutionPolicy, class _ForwardIterator1, class _ForwardIterator2>
688 __pstl::__internal::__enable_if_execution_policy<_ExecutionPolicy, bool>
689 equal(_ExecutionPolicy&& __exec, _ForwardIterator1 __first1, _ForwardIterator1 __last1, _ForwardIterator2 __first2)
690 {
691 return std::equal(std::forward<_ExecutionPolicy>(__exec), __first1, __last1, __first2, std::equal_to<>());
692 }
693
694 template <class _ExecutionPolicy, class _ForwardIterator1, class _ForwardIterator2, class _BinaryPredicate>
695 __pstl::__internal::__enable_if_execution_policy<_ExecutionPolicy, bool>
696 equal(_ExecutionPolicy&& __exec, _ForwardIterator1 __first1, _ForwardIterator1 __last1, _ForwardIterator2 __first2,
697 _ForwardIterator2 __last2, _BinaryPredicate __p)
698 {
699 auto __dispatch_tag = __pstl::__internal::__select_backend(__exec, __first1, __first2);
700
701 return __pstl::__internal::__pattern_equal(__dispatch_tag, std::forward<_ExecutionPolicy>(__exec), __first1,
702 __last1, __first2, __last2, __p);
703 }
704
705 template <class _ExecutionPolicy, class _ForwardIterator1, class _ForwardIterator2>
706 __pstl::__internal::__enable_if_execution_policy<_ExecutionPolicy, bool>
707 equal(_ExecutionPolicy&& __exec, _ForwardIterator1 __first1, _ForwardIterator1 __last1, _ForwardIterator2 __first2,
708 _ForwardIterator2 __last2)
709 {
710 return equal(std::forward<_ExecutionPolicy>(__exec), __first1, __last1, __first2, __last2, std::equal_to<>());
711 }
712
713 // [alg.move]
714 template <class _ExecutionPolicy, class _ForwardIterator1, class _ForwardIterator2>
715 __pstl::__internal::__enable_if_execution_policy<_ExecutionPolicy, _ForwardIterator2>
716 move(_ExecutionPolicy&& __exec, _ForwardIterator1 __first, _ForwardIterator1 __last, _ForwardIterator2 __d_first)
717 {
718 auto __dispatch_tag = __pstl::__internal::__select_backend(__exec, __first, __d_first);
719
720 using __is_vector = typename decltype(__dispatch_tag)::__is_vector;
721
722 return __pstl::__internal::__pattern_walk2_brick(
723 __dispatch_tag, std::forward<_ExecutionPolicy>(__exec), __first, __last, __d_first,
724 [](_ForwardIterator1 __begin, _ForwardIterator1 __end, _ForwardIterator2 __res)
725 { return __pstl::__internal::__brick_move(__begin, __end, __res, __is_vector{}); });
726 }
727
728 // [partial.sort]
729
730 template <class _ExecutionPolicy, class _RandomAccessIterator, class _Compare>
731 __pstl::__internal::__enable_if_execution_policy<_ExecutionPolicy, void>
732 partial_sort(_ExecutionPolicy&& __exec, _RandomAccessIterator __first, _RandomAccessIterator __middle,
733 _RandomAccessIterator __last, _Compare __comp)
734 {
735 auto __dispatch_tag = __pstl::__internal::__select_backend(__exec, __first);
736
737 __pstl::__internal::__pattern_partial_sort(__dispatch_tag, std::forward<_ExecutionPolicy>(__exec), __first,
738 __middle, __last, __comp);
739 }
740
741 template <class _ExecutionPolicy, class _RandomAccessIterator>
742 __pstl::__internal::__enable_if_execution_policy<_ExecutionPolicy, void>
743 partial_sort(_ExecutionPolicy&& __exec, _RandomAccessIterator __first, _RandomAccessIterator __middle,
744 _RandomAccessIterator __last)
745 {
746 typedef typename iterator_traits<_RandomAccessIterator>::value_type _InputType;
747 std::partial_sort(__exec, __first, __middle, __last, std::less<_InputType>());
748 }
749
750 // [partial.sort.copy]
751
752 template <class _ExecutionPolicy, class _ForwardIterator, class _RandomAccessIterator, class _Compare>
753 __pstl::__internal::__enable_if_execution_policy<_ExecutionPolicy, _RandomAccessIterator>
754 partial_sort_copy(_ExecutionPolicy&& __exec, _ForwardIterator __first, _ForwardIterator __last,
755 _RandomAccessIterator __d_first, _RandomAccessIterator __d_last, _Compare __comp)
756 {
757 auto __dispatch_tag = __pstl::__internal::__select_backend(__exec, __first, __d_first);
758
759 return __pstl::__internal::__pattern_partial_sort_copy(__dispatch_tag, std::forward<_ExecutionPolicy>(__exec),
760 __first, __last, __d_first, __d_last, __comp);
761 }
762
763 template <class _ExecutionPolicy, class _ForwardIterator, class _RandomAccessIterator>
764 __pstl::__internal::__enable_if_execution_policy<_ExecutionPolicy, _RandomAccessIterator>
765 partial_sort_copy(_ExecutionPolicy&& __exec, _ForwardIterator __first, _ForwardIterator __last,
766 _RandomAccessIterator __d_first, _RandomAccessIterator __d_last)
767 {
768 return std::partial_sort_copy(std::forward<_ExecutionPolicy>(__exec), __first, __last, __d_first, __d_last,
769 std::less<>());
770 }
771
772 // [is.sorted]
773 template <class _ExecutionPolicy, class _ForwardIterator, class _Compare>
774 __pstl::__internal::__enable_if_execution_policy<_ExecutionPolicy, _ForwardIterator>
775 is_sorted_until(_ExecutionPolicy&& __exec, _ForwardIterator __first, _ForwardIterator __last, _Compare __comp)
776 {
777 auto __dispatch_tag = __pstl::__internal::__select_backend(__exec, __first);
778 const _ForwardIterator __res =
779 __pstl::__internal::__pattern_adjacent_find(__dispatch_tag, std::forward<_ExecutionPolicy>(__exec), __first,
780 __last, __pstl::__internal::__reorder_pred<_Compare>(__comp),
781 /*first_semantic*/ false);
782 return __res == __last ? __last : std::next(__res);
783 }
784
785 template <class _ExecutionPolicy, class _ForwardIterator>
786 __pstl::__internal::__enable_if_execution_policy<_ExecutionPolicy, _ForwardIterator>
787 is_sorted_until(_ExecutionPolicy&& __exec, _ForwardIterator __first, _ForwardIterator __last)
788 {
789 typedef typename std::iterator_traits<_ForwardIterator>::value_type _InputType;
790 return is_sorted_until(std::forward<_ExecutionPolicy>(__exec), __first, __last, std::less<_InputType>());
791 }
792
793 template <class _ExecutionPolicy, class _ForwardIterator, class _Compare>
794 __pstl::__internal::__enable_if_execution_policy<_ExecutionPolicy, bool>
795 is_sorted(_ExecutionPolicy&& __exec, _ForwardIterator __first, _ForwardIterator __last, _Compare __comp)
796 {
797 auto __dispatch_tag = __pstl::__internal::__select_backend(__exec, __first);
798 return __pstl::__internal::__pattern_adjacent_find(__dispatch_tag, std::forward<_ExecutionPolicy>(__exec), __first,
799 __last, __pstl::__internal::__reorder_pred<_Compare>(__comp),
800 /*or_semantic*/ true) == __last;
801 }
802
803 template <class _ExecutionPolicy, class _ForwardIterator>
804 __pstl::__internal::__enable_if_execution_policy<_ExecutionPolicy, bool>
805 is_sorted(_ExecutionPolicy&& __exec, _ForwardIterator __first, _ForwardIterator __last)
806 {
807 typedef typename std::iterator_traits<_ForwardIterator>::value_type _InputType;
808 return std::is_sorted(std::forward<_ExecutionPolicy>(__exec), __first, __last, std::less<_InputType>());
809 }
810
811 // [alg.merge]
812 template <class _ExecutionPolicy, class _ForwardIterator1, class _ForwardIterator2, class _ForwardIterator,
813 class _Compare>
814 __pstl::__internal::__enable_if_execution_policy<_ExecutionPolicy, _ForwardIterator>
815 merge(_ExecutionPolicy&& __exec, _ForwardIterator1 __first1, _ForwardIterator1 __last1, _ForwardIterator2 __first2,
816 _ForwardIterator2 __last2, _ForwardIterator __d_first, _Compare __comp)
817 {
818 auto __dispatch_tag = __pstl::__internal::__select_backend(__exec, __first1, __first2, __d_first);
819
820 return __pstl::__internal::__pattern_merge(__dispatch_tag, std::forward<_ExecutionPolicy>(__exec), __first1,
821 __last1, __first2, __last2, __d_first, __comp);
822 }
823
824 template <class _ExecutionPolicy, class _ForwardIterator1, class _ForwardIterator2, class _ForwardIterator>
825 __pstl::__internal::__enable_if_execution_policy<_ExecutionPolicy, _ForwardIterator>
826 merge(_ExecutionPolicy&& __exec, _ForwardIterator1 __first1, _ForwardIterator1 __last1, _ForwardIterator2 __first2,
827 _ForwardIterator2 __last2, _ForwardIterator __d_first)
828 {
829 return std::merge(std::forward<_ExecutionPolicy>(__exec), __first1, __last1, __first2, __last2, __d_first,
830 std::less<>());
831 }
832
833 template <class _ExecutionPolicy, class _BidirectionalIterator, class _Compare>
834 __pstl::__internal::__enable_if_execution_policy<_ExecutionPolicy, void>
835 inplace_merge(_ExecutionPolicy&& __exec, _BidirectionalIterator __first, _BidirectionalIterator __middle,
836 _BidirectionalIterator __last, _Compare __comp)
837 {
838 auto __dispatch_tag = __pstl::__internal::__select_backend(__exec, __first);
839
840 __pstl::__internal::__pattern_inplace_merge(__dispatch_tag, std::forward<_ExecutionPolicy>(__exec), __first,
841 __middle, __last, __comp);
842 }
843
844 template <class _ExecutionPolicy, class _BidirectionalIterator>
845 __pstl::__internal::__enable_if_execution_policy<_ExecutionPolicy, void>
846 inplace_merge(_ExecutionPolicy&& __exec, _BidirectionalIterator __first, _BidirectionalIterator __middle,
847 _BidirectionalIterator __last)
848 {
849 typedef typename std::iterator_traits<_BidirectionalIterator>::value_type _InputType;
850 std::inplace_merge(__exec, __first, __middle, __last, std::less<_InputType>());
851 }
852
853 // [includes]
854
855 template <class _ExecutionPolicy, class _ForwardIterator1, class _ForwardIterator2, class _Compare>
856 __pstl::__internal::__enable_if_execution_policy<_ExecutionPolicy, bool>
857 includes(_ExecutionPolicy&& __exec, _ForwardIterator1 __first1, _ForwardIterator1 __last1, _ForwardIterator2 __first2,
858 _ForwardIterator2 __last2, _Compare __comp)
859 {
860 auto __dispatch_tag = __pstl::__internal::__select_backend(__exec, __first1, __first2);
861
862 return __pstl::__internal::__pattern_includes(__dispatch_tag, std::forward<_ExecutionPolicy>(__exec), __first1,
863 __last1, __first2, __last2, __comp);
864 }
865
866 template <class _ExecutionPolicy, class _ForwardIterator1, class _ForwardIterator2>
867 __pstl::__internal::__enable_if_execution_policy<_ExecutionPolicy, bool>
868 includes(_ExecutionPolicy&& __exec, _ForwardIterator1 __first1, _ForwardIterator1 __last1, _ForwardIterator2 __first2,
869 _ForwardIterator2 __last2)
870 {
871 return std::includes(std::forward<_ExecutionPolicy>(__exec), __first1, __last1, __first2, __last2, std::less<>());
872 }
873
874 // [set.union]
875
876 template <class _ExecutionPolicy, class _ForwardIterator1, class _ForwardIterator2, class _ForwardIterator,
877 class _Compare>
878 __pstl::__internal::__enable_if_execution_policy<_ExecutionPolicy, _ForwardIterator>
879 set_union(_ExecutionPolicy&& __exec, _ForwardIterator1 __first1, _ForwardIterator1 __last1, _ForwardIterator2 __first2,
880 _ForwardIterator2 __last2, _ForwardIterator __result, _Compare __comp)
881 {
882 auto __dispatch_tag = __pstl::__internal::__select_backend(__exec, __first1, __first2, __result);
883
884 return __pstl::__internal::__pattern_set_union(__dispatch_tag, std::forward<_ExecutionPolicy>(__exec), __first1,
885 __last1, __first2, __last2, __result, __comp);
886 }
887
888 template <class _ExecutionPolicy, class _ForwardIterator1, class _ForwardIterator2, class _ForwardIterator>
889 __pstl::__internal::__enable_if_execution_policy<_ExecutionPolicy, _ForwardIterator>
890 set_union(_ExecutionPolicy&& __exec, _ForwardIterator1 __first1, _ForwardIterator1 __last1, _ForwardIterator2 __first2,
891 _ForwardIterator2 __last2, _ForwardIterator __result)
892 {
893 return std::set_union(std::forward<_ExecutionPolicy>(__exec), __first1, __last1, __first2, __last2, __result,
894 std::less<>());
895 }
896
897 // [set.intersection]
898
899 template <class _ExecutionPolicy, class _ForwardIterator1, class _ForwardIterator2, class _ForwardIterator,
900 class _Compare>
901 __pstl::__internal::__enable_if_execution_policy<_ExecutionPolicy, _ForwardIterator>
902 set_intersection(_ExecutionPolicy&& __exec, _ForwardIterator1 __first1, _ForwardIterator1 __last1,
903 _ForwardIterator2 __first2, _ForwardIterator2 __last2, _ForwardIterator __result, _Compare __comp)
904 {
905 auto __dispatch_tag = __pstl::__internal::__select_backend(__exec, __first1, __first2, __result);
906
907 return __pstl::__internal::__pattern_set_intersection(__dispatch_tag, std::forward<_ExecutionPolicy>(__exec),
908 __first1, __last1, __first2, __last2, __result, __comp);
909 }
910
911 template <class _ExecutionPolicy, class _ForwardIterator1, class _ForwardIterator2, class _ForwardIterator>
912 __pstl::__internal::__enable_if_execution_policy<_ExecutionPolicy, _ForwardIterator>
913 set_intersection(_ExecutionPolicy&& __exec, _ForwardIterator1 __first1, _ForwardIterator1 __last1,
914 _ForwardIterator2 __first2, _ForwardIterator2 __last2, _ForwardIterator __result)
915 {
916 return std::set_intersection(std::forward<_ExecutionPolicy>(__exec), __first1, __last1, __first2, __last2, __result,
917 std::less<>());
918 }
919
920 // [set.difference]
921
922 template <class _ExecutionPolicy, class _ForwardIterator1, class _ForwardIterator2, class _ForwardIterator,
923 class _Compare>
924 __pstl::__internal::__enable_if_execution_policy<_ExecutionPolicy, _ForwardIterator>
925 set_difference(_ExecutionPolicy&& __exec, _ForwardIterator1 __first1, _ForwardIterator1 __last1,
926 _ForwardIterator2 __first2, _ForwardIterator2 __last2, _ForwardIterator __result, _Compare __comp)
927 {
928 auto __dispatch_tag = __pstl::__internal::__select_backend(__exec, __first1, __first2, __result);
929
930 return __pstl::__internal::__pattern_set_difference(__dispatch_tag, std::forward<_ExecutionPolicy>(__exec),
931 __first1, __last1, __first2, __last2, __result, __comp);
932 }
933
934 template <class _ExecutionPolicy, class _ForwardIterator1, class _ForwardIterator2, class _ForwardIterator>
935 __pstl::__internal::__enable_if_execution_policy<_ExecutionPolicy, _ForwardIterator>
936 set_difference(_ExecutionPolicy&& __exec, _ForwardIterator1 __first1, _ForwardIterator1 __last1,
937 _ForwardIterator2 __first2, _ForwardIterator2 __last2, _ForwardIterator __result)
938 {
939 return std::set_difference(std::forward<_ExecutionPolicy>(__exec), __first1, __last1, __first2, __last2, __result,
940 std::less<>());
941 }
942
943 // [set.symmetric.difference]
944
945 template <class _ExecutionPolicy, class _ForwardIterator1, class _ForwardIterator2, class _ForwardIterator,
946 class _Compare>
947 __pstl::__internal::__enable_if_execution_policy<_ExecutionPolicy, _ForwardIterator>
948 set_symmetric_difference(_ExecutionPolicy&& __exec, _ForwardIterator1 __first1, _ForwardIterator1 __last1,
949 _ForwardIterator2 __first2, _ForwardIterator2 __last2, _ForwardIterator __result,
950 _Compare __comp)
951 {
952 auto __dispatch_tag = __pstl::__internal::__select_backend(__exec, __first1, __first2, __result);
953
954 return __pstl::__internal::__pattern_set_symmetric_difference(
955 __dispatch_tag, std::forward<_ExecutionPolicy>(__exec), __first1, __last1, __first2, __last2, __result, __comp);
956 }
957
958 template <class _ExecutionPolicy, class _ForwardIterator1, class _ForwardIterator2, class _ForwardIterator>
959 __pstl::__internal::__enable_if_execution_policy<_ExecutionPolicy, _ForwardIterator>
960 set_symmetric_difference(_ExecutionPolicy&& __exec, _ForwardIterator1 __first1, _ForwardIterator1 __last1,
961 _ForwardIterator2 __first2, _ForwardIterator2 __last2, _ForwardIterator __result)
962 {
963 return std::set_symmetric_difference(std::forward<_ExecutionPolicy>(__exec), __first1, __last1, __first2, __last2,
964 __result, std::less<>());
965 }
966
967 // [is.heap]
968 template <class _ExecutionPolicy, class _RandomAccessIterator, class _Compare>
969 __pstl::__internal::__enable_if_execution_policy<_ExecutionPolicy, _RandomAccessIterator>
970 is_heap_until(_ExecutionPolicy&& __exec, _RandomAccessIterator __first, _RandomAccessIterator __last, _Compare __comp)
971 {
972 auto __dispatch_tag = __pstl::__internal::__select_backend(__exec, __first);
973
974 return __pstl::__internal::__pattern_is_heap_until(__dispatch_tag, std::forward<_ExecutionPolicy>(__exec), __first,
975 __last, __comp);
976 }
977
978 template <class _ExecutionPolicy, class _RandomAccessIterator>
979 __pstl::__internal::__enable_if_execution_policy<_ExecutionPolicy, _RandomAccessIterator>
980 is_heap_until(_ExecutionPolicy&& __exec, _RandomAccessIterator __first, _RandomAccessIterator __last)
981 {
982 typedef typename std::iterator_traits<_RandomAccessIterator>::value_type _InputType;
983 return std::is_heap_until(std::forward<_ExecutionPolicy>(__exec), __first, __last, std::less<_InputType>());
984 }
985
986 template <class _ExecutionPolicy, class _RandomAccessIterator, class _Compare>
987 __pstl::__internal::__enable_if_execution_policy<_ExecutionPolicy, bool>
988 is_heap(_ExecutionPolicy&& __exec, _RandomAccessIterator __first, _RandomAccessIterator __last, _Compare __comp)
989 {
990 return std::is_heap_until(std::forward<_ExecutionPolicy>(__exec), __first, __last, __comp) == __last;
991 }
992
993 template <class _ExecutionPolicy, class _RandomAccessIterator>
994 __pstl::__internal::__enable_if_execution_policy<_ExecutionPolicy, bool>
995 is_heap(_ExecutionPolicy&& __exec, _RandomAccessIterator __first, _RandomAccessIterator __last)
996 {
997 typedef typename std::iterator_traits<_RandomAccessIterator>::value_type _InputType;
998 return std::is_heap(std::forward<_ExecutionPolicy>(__exec), __first, __last, std::less<_InputType>());
999 }
1000
1001 // [alg.min.max]
1002
1003 template <class _ExecutionPolicy, class _ForwardIterator, class _Compare>
1004 __pstl::__internal::__enable_if_execution_policy<_ExecutionPolicy, _ForwardIterator>
1005 min_element(_ExecutionPolicy&& __exec, _ForwardIterator __first, _ForwardIterator __last, _Compare __comp)
1006 {
1007 auto __dispatch_tag = __pstl::__internal::__select_backend(__exec, __first);
1008 return __pstl::__internal::__pattern_min_element(__dispatch_tag, std::forward<_ExecutionPolicy>(__exec), __first,
1009 __last, __comp);
1010 }
1011
1012 template <class _ExecutionPolicy, class _ForwardIterator>
1013 __pstl::__internal::__enable_if_execution_policy<_ExecutionPolicy, _ForwardIterator>
1014 min_element(_ExecutionPolicy&& __exec, _ForwardIterator __first, _ForwardIterator __last)
1015 {
1016 typedef typename std::iterator_traits<_ForwardIterator>::value_type _InputType;
1017 return std::min_element(std::forward<_ExecutionPolicy>(__exec), __first, __last, std::less<_InputType>());
1018 }
1019
1020 template <class _ExecutionPolicy, class _ForwardIterator, class _Compare>
1021 __pstl::__internal::__enable_if_execution_policy<_ExecutionPolicy, _ForwardIterator>
1022 max_element(_ExecutionPolicy&& __exec, _ForwardIterator __first, _ForwardIterator __last, _Compare __comp)
1023 {
1024 return min_element(std::forward<_ExecutionPolicy>(__exec), __first, __last,
1025 __pstl::__internal::__reorder_pred<_Compare>(__comp));
1026 }
1027
1028 template <class _ExecutionPolicy, class _ForwardIterator>
1029 __pstl::__internal::__enable_if_execution_policy<_ExecutionPolicy, _ForwardIterator>
1030 max_element(_ExecutionPolicy&& __exec, _ForwardIterator __first, _ForwardIterator __last)
1031 {
1032 typedef typename std::iterator_traits<_ForwardIterator>::value_type _InputType;
1033 return std::min_element(std::forward<_ExecutionPolicy>(__exec), __first, __last,
1034 __pstl::__internal::__reorder_pred<std::less<_InputType>>(std::less<_InputType>()));
1035 }
1036
1037 template <class _ExecutionPolicy, class _ForwardIterator, class _Compare>
1038 __pstl::__internal::__enable_if_execution_policy<_ExecutionPolicy, std::pair<_ForwardIterator, _ForwardIterator>>
1039 minmax_element(_ExecutionPolicy&& __exec, _ForwardIterator __first, _ForwardIterator __last, _Compare __comp)
1040 {
1041 auto __dispatch_tag = __pstl::__internal::__select_backend(__exec, __first);
1042 return __pstl::__internal::__pattern_minmax_element(__dispatch_tag, std::forward<_ExecutionPolicy>(__exec), __first,
1043 __last, __comp);
1044 }
1045
1046 template <class _ExecutionPolicy, class _ForwardIterator>
1047 __pstl::__internal::__enable_if_execution_policy<_ExecutionPolicy, std::pair<_ForwardIterator, _ForwardIterator>>
1048 minmax_element(_ExecutionPolicy&& __exec, _ForwardIterator __first, _ForwardIterator __last)
1049 {
1050 typedef typename iterator_traits<_ForwardIterator>::value_type _ValueType;
1051 return std::minmax_element(std::forward<_ExecutionPolicy>(__exec), __first, __last, std::less<_ValueType>());
1052 }
1053
1054 // [alg.nth.element]
1055
1056 template <class _ExecutionPolicy, class _RandomAccessIterator, class _Compare>
1057 __pstl::__internal::__enable_if_execution_policy<_ExecutionPolicy, void>
1058 nth_element(_ExecutionPolicy&& __exec, _RandomAccessIterator __first, _RandomAccessIterator __nth,
1059 _RandomAccessIterator __last, _Compare __comp)
1060 {
1061 auto __dispatch_tag = __pstl::__internal::__select_backend(__exec, __first);
1062
1063 __pstl::__internal::__pattern_nth_element(__dispatch_tag, std::forward<_ExecutionPolicy>(__exec), __first, __nth,
1064 __last, __comp);
1065 }
1066
1067 template <class _ExecutionPolicy, class _RandomAccessIterator>
1068 __pstl::__internal::__enable_if_execution_policy<_ExecutionPolicy, void>
1069 nth_element(_ExecutionPolicy&& __exec, _RandomAccessIterator __first, _RandomAccessIterator __nth,
1070 _RandomAccessIterator __last)
1071 {
1072 typedef typename iterator_traits<_RandomAccessIterator>::value_type _InputType;
1073 std::nth_element(std::forward<_ExecutionPolicy>(__exec), __first, __nth, __last, std::less<_InputType>());
1074 }
1075
1076 // [alg.lex.comparison]
1077
1078 template <class _ExecutionPolicy, class _ForwardIterator1, class _ForwardIterator2, class _Compare>
1079 __pstl::__internal::__enable_if_execution_policy<_ExecutionPolicy, bool>
1080 lexicographical_compare(_ExecutionPolicy&& __exec, _ForwardIterator1 __first1, _ForwardIterator1 __last1,
1081 _ForwardIterator2 __first2, _ForwardIterator2 __last2, _Compare __comp)
1082 {
1083 auto __dispatch_tag = __pstl::__internal::__select_backend(__exec, __first1, __first2);
1084
1085 return __pstl::__internal::__pattern_lexicographical_compare(__dispatch_tag, std::forward<_ExecutionPolicy>(__exec),
1086 __first1, __last1, __first2, __last2, __comp);
1087 }
1088
1089 template <class _ExecutionPolicy, class _ForwardIterator1, class _ForwardIterator2>
1090 __pstl::__internal::__enable_if_execution_policy<_ExecutionPolicy, bool>
1091 lexicographical_compare(_ExecutionPolicy&& __exec, _ForwardIterator1 __first1, _ForwardIterator1 __last1,
1092 _ForwardIterator2 __first2, _ForwardIterator2 __last2)
1093 {
1094 return std::lexicographical_compare(std::forward<_ExecutionPolicy>(__exec), __first1, __last1, __first2, __last2,
1095 std::less<>());
1096 }
1097
1098 } // namespace std
1099
1100 #endif /* _PSTL_GLUE_ALGORITHM_IMPL_H */