1 | // Copyright (C) 2016 The Qt Company Ltd. |
2 | // SPDX-License-Identifier: LicenseRef-Qt-Commercial OR LGPL-3.0-only OR GPL-2.0-only OR GPL-3.0-only |
3 | |
4 | #ifndef QTCONCURRENT_FILTER_H |
5 | #define QTCONCURRENT_FILTER_H |
6 | |
7 | #if 0 |
8 | #pragma qt_class(QtConcurrentFilter) |
9 | #endif |
10 | |
11 | #include <QtConcurrent/qtconcurrent_global.h> |
12 | |
13 | #if !defined(QT_NO_CONCURRENT) || defined(Q_QDOC) |
14 | |
15 | #include <QtConcurrent/qtconcurrentfilterkernel.h> |
16 | #include <QtConcurrent/qtconcurrentfunctionwrappers.h> |
17 | |
18 | QT_BEGIN_NAMESPACE |
19 | |
20 | namespace QtConcurrent { |
21 | |
22 | //! [QtConcurrent-1] |
23 | template <typename Sequence, typename KeepFunctor, typename ReduceFunctor> |
24 | ThreadEngineStarter<void> filterInternal(QThreadPool *pool, Sequence &sequence, |
25 | KeepFunctor &&keep, ReduceFunctor &&reduce) |
26 | { |
27 | typedef FilterKernel<Sequence, std::decay_t<KeepFunctor>, std::decay_t<ReduceFunctor>> |
28 | KernelType; |
29 | return startThreadEngine(new KernelType(pool, sequence, std::forward<KeepFunctor>(keep), |
30 | std::forward<ReduceFunctor>(reduce))); |
31 | } |
32 | |
33 | // filter() on sequences |
34 | template <typename Sequence, typename KeepFunctor> |
35 | QFuture<void> filter(QThreadPool *pool, Sequence &sequence, KeepFunctor &&keep) |
36 | { |
37 | return filterInternal(pool, sequence, std::forward<KeepFunctor>(keep), |
38 | QtPrivate::PushBackWrapper()); |
39 | } |
40 | |
41 | template <typename Sequence, typename KeepFunctor> |
42 | QFuture<void> filter(Sequence &sequence, KeepFunctor &&keep) |
43 | { |
44 | return filterInternal(QThreadPool::globalInstance(), |
45 | sequence, std::forward<KeepFunctor>(keep), QtPrivate::PushBackWrapper()); |
46 | } |
47 | |
48 | // filteredReduced() on sequences |
49 | template <typename ResultType, typename Sequence, typename KeepFunctor, typename ReduceFunctor> |
50 | QFuture<ResultType> filteredReduced(QThreadPool *pool, |
51 | Sequence &&sequence, |
52 | KeepFunctor &&keep, |
53 | ReduceFunctor &&reduce, |
54 | ReduceOptions options = ReduceOptions(UnorderedReduce |
55 | | SequentialReduce)) |
56 | { |
57 | return startFilteredReduced<ResultType>(pool, std::forward<Sequence>(sequence), |
58 | std::forward<KeepFunctor>(keep), |
59 | std::forward<ReduceFunctor>(reduce), options); |
60 | } |
61 | |
62 | template <typename ResultType, typename Sequence, typename KeepFunctor, typename ReduceFunctor> |
63 | QFuture<ResultType> filteredReduced(Sequence &&sequence, |
64 | KeepFunctor &&keep, |
65 | ReduceFunctor &&reduce, |
66 | ReduceOptions options = ReduceOptions(UnorderedReduce |
67 | | SequentialReduce)) |
68 | { |
69 | return startFilteredReduced<ResultType>( |
70 | QThreadPool::globalInstance(), std::forward<Sequence>(sequence), |
71 | std::forward<KeepFunctor>(keep), std::forward<ReduceFunctor>(reduce), options); |
72 | } |
73 | |
74 | #ifdef Q_QDOC |
75 | template <typename ResultType, typename Sequence, typename KeepFunctor, typename ReduceFunctor, |
76 | typename InitialValueType> |
77 | #else |
78 | template <typename ResultType, typename Sequence, typename KeepFunctor, typename ReduceFunctor, |
79 | typename InitialValueType, |
80 | std::enable_if_t<QtPrivate::isInitialValueCompatible_v<InitialValueType, ResultType>, |
81 | int> = 0> |
82 | #endif |
83 | QFuture<ResultType> filteredReduced(QThreadPool *pool, |
84 | Sequence &&sequence, |
85 | KeepFunctor &&keep, |
86 | ReduceFunctor &&reduce, |
87 | InitialValueType &&initialValue, |
88 | ReduceOptions options = ReduceOptions(UnorderedReduce |
89 | | SequentialReduce)) |
90 | { |
91 | return startFilteredReduced<ResultType>( |
92 | pool, std::forward<Sequence>(sequence), std::forward<KeepFunctor>(keep), |
93 | std::forward<ReduceFunctor>(reduce), |
94 | ResultType(std::forward<InitialValueType>(initialValue)), options); |
95 | } |
96 | |
97 | #ifdef Q_QDOC |
98 | template <typename ResultType, typename Sequence, typename KeepFunctor, typename ReduceFunctor, |
99 | typename InitialValueType> |
100 | #else |
101 | template <typename ResultType, typename Sequence, typename KeepFunctor, typename ReduceFunctor, |
102 | typename InitialValueType, |
103 | std::enable_if_t<QtPrivate::isInitialValueCompatible_v<InitialValueType, ResultType>, |
104 | int> = 0> |
105 | #endif |
106 | QFuture<ResultType> filteredReduced(Sequence &&sequence, |
107 | KeepFunctor &&keep, |
108 | ReduceFunctor &&reduce, |
109 | InitialValueType &&initialValue, |
110 | ReduceOptions options = ReduceOptions(UnorderedReduce |
111 | | SequentialReduce)) |
112 | { |
113 | return startFilteredReduced<ResultType>( |
114 | QThreadPool::globalInstance(), std::forward<Sequence>(sequence), |
115 | std::forward<KeepFunctor>(keep), std::forward<ReduceFunctor>(reduce), |
116 | ResultType(std::forward<InitialValueType>(initialValue)), options); |
117 | } |
118 | |
119 | #ifndef Q_QDOC |
120 | template <typename Sequence, typename KeepFunctor, typename ReduceFunctor, |
121 | std::enable_if_t<QtPrivate::isInvocable<KeepFunctor, Sequence>::value, int> = 0, |
122 | typename ResultType = typename QtPrivate::ReduceResultTypeHelper<ReduceFunctor>::type> |
123 | QFuture<ResultType> filteredReduced(QThreadPool *pool, |
124 | Sequence &&sequence, |
125 | KeepFunctor &&keep, |
126 | ReduceFunctor &&reduce, |
127 | ReduceOptions options = ReduceOptions(UnorderedReduce |
128 | | SequentialReduce)) |
129 | { |
130 | return startFilteredReduced<ResultType>(pool, std::forward<Sequence>(sequence), |
131 | std::forward<KeepFunctor>(keep), |
132 | std::forward<ReduceFunctor>(reduce), options); |
133 | } |
134 | |
135 | template <typename Sequence, typename KeepFunctor, typename ReduceFunctor, |
136 | std::enable_if_t<QtPrivate::isInvocable<KeepFunctor, Sequence>::value, int> = 0, |
137 | typename ResultType = typename QtPrivate::ReduceResultTypeHelper<ReduceFunctor>::type> |
138 | QFuture<ResultType> filteredReduced(Sequence &&sequence, |
139 | KeepFunctor &&keep, |
140 | ReduceFunctor &&reduce, |
141 | ReduceOptions options = ReduceOptions(UnorderedReduce |
142 | | SequentialReduce)) |
143 | { |
144 | return startFilteredReduced<ResultType>( |
145 | QThreadPool::globalInstance(), std::forward<Sequence>(sequence), |
146 | std::forward<KeepFunctor>(keep), std::forward<ReduceFunctor>(reduce), options); |
147 | } |
148 | |
149 | template <typename Sequence, typename KeepFunctor, typename ReduceFunctor, |
150 | typename InitialValueType, |
151 | std::enable_if_t<QtPrivate::isInvocable<KeepFunctor, Sequence>::value, int> = 0, |
152 | typename ResultType = typename QtPrivate::ReduceResultTypeHelper<ReduceFunctor>::type, |
153 | std::enable_if_t<QtPrivate::isInitialValueCompatible_v<InitialValueType, ResultType>, |
154 | int> = 0> |
155 | QFuture<ResultType> filteredReduced(QThreadPool *pool, |
156 | Sequence &&sequence, |
157 | KeepFunctor &&keep, |
158 | ReduceFunctor &&reduce, |
159 | InitialValueType &&initialValue, |
160 | ReduceOptions options = ReduceOptions(UnorderedReduce |
161 | | SequentialReduce)) |
162 | { |
163 | return startFilteredReduced<ResultType>( |
164 | pool, std::forward<Sequence>(sequence), std::forward<KeepFunctor>(keep), |
165 | std::forward<ReduceFunctor>(reduce), |
166 | ResultType(std::forward<InitialValueType>(initialValue)), options); |
167 | } |
168 | |
169 | template <typename Sequence, typename KeepFunctor, typename ReduceFunctor, |
170 | typename InitialValueType, |
171 | std::enable_if_t<QtPrivate::isInvocable<KeepFunctor, Sequence>::value, int> = 0, |
172 | typename ResultType = typename QtPrivate::ReduceResultTypeHelper<ReduceFunctor>::type, |
173 | std::enable_if_t<QtPrivate::isInitialValueCompatible_v<InitialValueType, ResultType>, |
174 | int> = 0> |
175 | QFuture<ResultType> filteredReduced(Sequence &&sequence, |
176 | KeepFunctor &&keep, |
177 | ReduceFunctor &&reduce, |
178 | InitialValueType &&initialValue, |
179 | ReduceOptions options = ReduceOptions(UnorderedReduce |
180 | | SequentialReduce)) |
181 | { |
182 | return startFilteredReduced<ResultType>( |
183 | QThreadPool::globalInstance(), std::forward<Sequence>(sequence), |
184 | std::forward<KeepFunctor>(keep), std::forward<ReduceFunctor>(reduce), |
185 | ResultType(std::forward<InitialValueType>(initialValue)), options); |
186 | } |
187 | #endif |
188 | |
189 | // filteredReduced() on iterators |
190 | template <typename ResultType, typename Iterator, typename KeepFunctor, typename ReduceFunctor> |
191 | QFuture<ResultType> filteredReduced(QThreadPool *pool, |
192 | Iterator begin, |
193 | Iterator end, |
194 | KeepFunctor &&keep, |
195 | ReduceFunctor &&reduce, |
196 | ReduceOptions options = ReduceOptions(UnorderedReduce |
197 | | SequentialReduce)) |
198 | { |
199 | return startFilteredReduced<ResultType>(pool, begin, end, std::forward<KeepFunctor>(keep), |
200 | std::forward<ReduceFunctor>(reduce), options); |
201 | } |
202 | |
203 | template <typename ResultType, typename Iterator, typename KeepFunctor, typename ReduceFunctor> |
204 | QFuture<ResultType> filteredReduced(Iterator begin, |
205 | Iterator end, |
206 | KeepFunctor &&keep, |
207 | ReduceFunctor &&reduce, |
208 | ReduceOptions options = ReduceOptions(UnorderedReduce |
209 | | SequentialReduce)) |
210 | { |
211 | return startFilteredReduced<ResultType>(QThreadPool::globalInstance(), begin, end, |
212 | std::forward<KeepFunctor>(keep), |
213 | std::forward<ReduceFunctor>(reduce), options); |
214 | } |
215 | |
216 | #ifdef Q_QDOC |
217 | template <typename ResultType, typename Iterator, typename KeepFunctor, typename ReduceFunctor, |
218 | typename InitialValueType> |
219 | #else |
220 | template <typename ResultType, typename Iterator, typename KeepFunctor, typename ReduceFunctor, |
221 | typename InitialValueType, |
222 | std::enable_if_t<QtPrivate::isInitialValueCompatible_v<InitialValueType, ResultType>, |
223 | int> = 0> |
224 | #endif |
225 | QFuture<ResultType> filteredReduced(QThreadPool *pool, |
226 | Iterator begin, |
227 | Iterator end, |
228 | KeepFunctor &&keep, |
229 | ReduceFunctor &&reduce, |
230 | InitialValueType &&initialValue, |
231 | ReduceOptions options = ReduceOptions(UnorderedReduce |
232 | | SequentialReduce)) |
233 | { |
234 | return startFilteredReduced<ResultType>( |
235 | pool, begin, end, std::forward<KeepFunctor>(keep), std::forward<ReduceFunctor>(reduce), |
236 | ResultType(std::forward<InitialValueType>(initialValue)), options); |
237 | } |
238 | |
239 | #ifdef Q_QDOC |
240 | template <typename ResultType, typename Iterator, typename KeepFunctor, typename ReduceFunctor, |
241 | typename InitialValueType> |
242 | #else |
243 | template <typename ResultType, typename Iterator, typename KeepFunctor, typename ReduceFunctor, |
244 | typename InitialValueType, |
245 | std::enable_if_t<QtPrivate::isInitialValueCompatible_v<InitialValueType, ResultType>, |
246 | int> = 0> |
247 | #endif |
248 | QFuture<ResultType> filteredReduced(Iterator begin, |
249 | Iterator end, |
250 | KeepFunctor &&keep, |
251 | ReduceFunctor &&reduce, |
252 | InitialValueType &&initialValue, |
253 | ReduceOptions options = ReduceOptions(UnorderedReduce |
254 | | SequentialReduce)) |
255 | { |
256 | return startFilteredReduced<ResultType>( |
257 | QThreadPool::globalInstance(), begin, end, std::forward<KeepFunctor>(keep), |
258 | std::forward<ReduceFunctor>(reduce), |
259 | ResultType(std::forward<InitialValueType>(initialValue)), options); |
260 | } |
261 | |
262 | #ifndef Q_QDOC |
263 | template <typename Iterator, typename KeepFunctor, typename ReduceFunctor, |
264 | typename ResultType = typename QtPrivate::ReduceResultTypeHelper<ReduceFunctor>::type> |
265 | QFuture<ResultType> filteredReduced(QThreadPool *pool, |
266 | Iterator begin, |
267 | Iterator end, |
268 | KeepFunctor &&keep, |
269 | ReduceFunctor &&reduce, |
270 | ReduceOptions options = ReduceOptions(UnorderedReduce |
271 | | SequentialReduce)) |
272 | { |
273 | return startFilteredReduced<ResultType>(pool, begin, end, std::forward<KeepFunctor>(keep), |
274 | std::forward<ReduceFunctor>(reduce), options); |
275 | } |
276 | |
277 | template <typename Iterator, typename KeepFunctor, typename ReduceFunctor, |
278 | typename ResultType = typename QtPrivate::ReduceResultTypeHelper<ReduceFunctor>::type> |
279 | QFuture<ResultType> filteredReduced(Iterator begin, |
280 | Iterator end, |
281 | KeepFunctor &&keep, |
282 | ReduceFunctor &&reduce, |
283 | ReduceOptions options = ReduceOptions(UnorderedReduce |
284 | | SequentialReduce)) |
285 | { |
286 | return startFilteredReduced<ResultType>(QThreadPool::globalInstance(), begin, end, |
287 | std::forward<KeepFunctor>(keep), |
288 | std::forward<ReduceFunctor>(reduce), options); |
289 | } |
290 | |
291 | template <typename Iterator, typename KeepFunctor, typename ReduceFunctor, |
292 | typename ResultType = typename QtPrivate::ReduceResultTypeHelper<ReduceFunctor>::type, |
293 | typename InitialValueType, |
294 | std::enable_if_t<QtPrivate::isInitialValueCompatible_v<InitialValueType, ResultType>, |
295 | int> = 0> |
296 | QFuture<ResultType> filteredReduced(QThreadPool *pool, |
297 | Iterator begin, |
298 | Iterator end, |
299 | KeepFunctor &&keep, |
300 | ReduceFunctor &&reduce, |
301 | InitialValueType &&initialValue, |
302 | ReduceOptions options = ReduceOptions(UnorderedReduce |
303 | | SequentialReduce)) |
304 | { |
305 | return startFilteredReduced<ResultType>( |
306 | pool, begin, end, std::forward<KeepFunctor>(keep), std::forward<ReduceFunctor>(reduce), |
307 | ResultType(std::forward<InitialValueType>(initialValue)), options); |
308 | } |
309 | |
310 | template <typename Iterator, typename KeepFunctor, typename ReduceFunctor, |
311 | std::enable_if_t<QtPrivate::isIterator_v<Iterator>, int> = 0, |
312 | typename ResultType = typename QtPrivate::ReduceResultTypeHelper<ReduceFunctor>::type, |
313 | typename InitialValueType, |
314 | std::enable_if_t<QtPrivate::isInitialValueCompatible_v<InitialValueType, ResultType>, |
315 | int> = 0> |
316 | QFuture<ResultType> filteredReduced(Iterator begin, |
317 | Iterator end, |
318 | KeepFunctor &&keep, |
319 | ReduceFunctor &&reduce, |
320 | InitialValueType &&initialValue, |
321 | ReduceOptions options = ReduceOptions(UnorderedReduce |
322 | | SequentialReduce)) |
323 | { |
324 | return startFilteredReduced<ResultType>( |
325 | QThreadPool::globalInstance(), begin, end, std::forward<KeepFunctor>(keep), |
326 | std::forward<ReduceFunctor>(reduce), |
327 | ResultType(std::forward<InitialValueType>(initialValue)), options); |
328 | } |
329 | #endif |
330 | |
331 | // filtered() on sequences |
332 | template <typename Sequence, typename KeepFunctor> |
333 | QFuture<typename std::decay_t<Sequence>::value_type> filtered(QThreadPool *pool,Sequence &&sequence, |
334 | KeepFunctor &&keep) |
335 | { |
336 | return startFiltered(pool, std::forward<Sequence>(sequence), std::forward<KeepFunctor>(keep)); |
337 | } |
338 | |
339 | template <typename Sequence, typename KeepFunctor> |
340 | QFuture<typename std::decay_t<Sequence>::value_type> filtered(Sequence &&sequence, |
341 | KeepFunctor &&keep) |
342 | { |
343 | return startFiltered(QThreadPool::globalInstance(), std::forward<Sequence>(sequence), |
344 | std::forward<KeepFunctor>(keep)); |
345 | } |
346 | |
347 | // filtered() on iterators |
348 | template <typename Iterator, typename KeepFunctor> |
349 | QFuture<typename qValueType<Iterator>::value_type> filtered(QThreadPool *pool, |
350 | Iterator begin, |
351 | Iterator end, |
352 | KeepFunctor &&keep) |
353 | { |
354 | return startFiltered(pool, begin, end, std::forward<KeepFunctor>(keep)); |
355 | } |
356 | |
357 | template <typename Iterator, typename KeepFunctor> |
358 | QFuture<typename qValueType<Iterator>::value_type> filtered(Iterator begin, |
359 | Iterator end, |
360 | KeepFunctor &&keep) |
361 | { |
362 | return startFiltered(QThreadPool::globalInstance(), begin, end, |
363 | std::forward<KeepFunctor>(keep)); |
364 | } |
365 | |
366 | // blocking filter() on sequences |
367 | template <typename Sequence, typename KeepFunctor> |
368 | void blockingFilter(QThreadPool *pool, Sequence &sequence, KeepFunctor &&keep) |
369 | { |
370 | QFuture<void> future = filter(pool, sequence, std::forward<KeepFunctor>(keep)); |
371 | future.waitForFinished(); |
372 | } |
373 | |
374 | template <typename Sequence, typename KeepFunctor> |
375 | void blockingFilter(Sequence &sequence, KeepFunctor &&keep) |
376 | { |
377 | QFuture<void> future = filter(sequence, std::forward<KeepFunctor>(keep)); |
378 | future.waitForFinished(); |
379 | } |
380 | |
381 | // blocking filteredReduced() on sequences |
382 | template <typename ResultType, typename Sequence, typename KeepFunctor, typename ReduceFunctor> |
383 | ResultType blockingFilteredReduced(QThreadPool *pool, |
384 | Sequence &&sequence, |
385 | KeepFunctor &&keep, |
386 | ReduceFunctor &&reduce, |
387 | ReduceOptions options = ReduceOptions(UnorderedReduce |
388 | | SequentialReduce)) |
389 | { |
390 | QFuture<ResultType> future = filteredReduced<ResultType>( |
391 | pool, std::forward<Sequence>(sequence), std::forward<KeepFunctor>(keep), |
392 | std::forward<ReduceFunctor>(reduce), options); |
393 | return future.takeResult(); |
394 | } |
395 | |
396 | template <typename ResultType, typename Sequence, typename KeepFunctor, typename ReduceFunctor> |
397 | ResultType blockingFilteredReduced(Sequence &&sequence, |
398 | KeepFunctor &&keep, |
399 | ReduceFunctor &&reduce, |
400 | ReduceOptions options = ReduceOptions(UnorderedReduce |
401 | | SequentialReduce)) |
402 | { |
403 | QFuture<ResultType> future = filteredReduced<ResultType>( |
404 | std::forward<Sequence>(sequence), std::forward<KeepFunctor>(keep), |
405 | std::forward<ReduceFunctor>(reduce), options); |
406 | return future.takeResult(); |
407 | } |
408 | |
409 | #ifdef Q_QDOC |
410 | template <typename ResultType, typename Sequence, typename KeepFunctor, typename ReduceFunctor, |
411 | typename InitialValueType> |
412 | #else |
413 | template <typename ResultType, typename Sequence, typename KeepFunctor, typename ReduceFunctor, |
414 | typename InitialValueType, |
415 | std::enable_if_t<QtPrivate::isInitialValueCompatible_v<InitialValueType, ResultType>, |
416 | int> = 0> |
417 | #endif |
418 | ResultType blockingFilteredReduced(QThreadPool *pool, |
419 | Sequence &&sequence, |
420 | KeepFunctor &&keep, |
421 | ReduceFunctor &&reduce, |
422 | InitialValueType &&initialValue, |
423 | ReduceOptions options = ReduceOptions(UnorderedReduce |
424 | | SequentialReduce)) |
425 | { |
426 | QFuture<ResultType> future = filteredReduced<ResultType>( |
427 | pool, std::forward<Sequence>(sequence), std::forward<KeepFunctor>(keep), |
428 | std::forward<ReduceFunctor>(reduce), |
429 | ResultType(std::forward<InitialValueType>(initialValue)), options); |
430 | return future.takeResult(); |
431 | } |
432 | |
433 | #ifdef Q_QDOC |
434 | template <typename ResultType, typename Sequence, typename KeepFunctor, typename ReduceFunctor, |
435 | typename InitialValueType> |
436 | #else |
437 | template <typename ResultType, typename Sequence, typename KeepFunctor, typename ReduceFunctor, |
438 | typename InitialValueType, |
439 | std::enable_if_t<QtPrivate::isInitialValueCompatible_v<InitialValueType, ResultType>, |
440 | int> = 0> |
441 | #endif |
442 | ResultType blockingFilteredReduced(Sequence &&sequence, |
443 | KeepFunctor &&keep, |
444 | ReduceFunctor &&reduce, |
445 | InitialValueType &&initialValue, |
446 | ReduceOptions options = ReduceOptions(UnorderedReduce |
447 | | SequentialReduce)) |
448 | { |
449 | QFuture<ResultType> future = filteredReduced<ResultType>( |
450 | std::forward<Sequence>(sequence), std::forward<KeepFunctor>(keep), |
451 | std::forward<ReduceFunctor>(reduce), |
452 | ResultType(std::forward<InitialValueType>(initialValue)), options); |
453 | return future.takeResult(); |
454 | } |
455 | |
456 | #ifndef Q_QDOC |
457 | template <typename Sequence, typename KeepFunctor, typename ReduceFunctor, |
458 | std::enable_if_t<QtPrivate::isInvocable<KeepFunctor, Sequence>::value, int> = 0, |
459 | typename ResultType = typename QtPrivate::ReduceResultTypeHelper<ReduceFunctor>::type> |
460 | ResultType blockingFilteredReduced(QThreadPool *pool, |
461 | Sequence &&sequence, |
462 | KeepFunctor &&keep, |
463 | ReduceFunctor &&reduce, |
464 | ReduceOptions options = ReduceOptions(UnorderedReduce |
465 | | SequentialReduce)) |
466 | { |
467 | QFuture<ResultType> future = filteredReduced<ResultType>( |
468 | pool, std::forward<Sequence>(sequence), std::forward<KeepFunctor>(keep), |
469 | std::forward<ReduceFunctor>(reduce), options); |
470 | return future.takeResult(); |
471 | } |
472 | |
473 | template <typename Sequence, typename KeepFunctor, typename ReduceFunctor, |
474 | std::enable_if_t<QtPrivate::isInvocable<KeepFunctor, Sequence>::value, int> = 0, |
475 | typename ResultType = typename QtPrivate::ReduceResultTypeHelper<ReduceFunctor>::type> |
476 | ResultType blockingFilteredReduced(Sequence &&sequence, |
477 | KeepFunctor &&keep, |
478 | ReduceFunctor &&reduce, |
479 | ReduceOptions options = ReduceOptions(UnorderedReduce |
480 | | SequentialReduce)) |
481 | { |
482 | QFuture<ResultType> future = filteredReduced<ResultType>( |
483 | std::forward<Sequence>(sequence), std::forward<KeepFunctor>(keep), |
484 | std::forward<ReduceFunctor>(reduce), options); |
485 | return future.takeResult(); |
486 | } |
487 | |
488 | template <typename Sequence, typename KeepFunctor, typename ReduceFunctor, |
489 | typename InitialValueType, |
490 | std::enable_if_t<QtPrivate::isInvocable<KeepFunctor, Sequence>::value, int> = 0, |
491 | typename ResultType = typename QtPrivate::ReduceResultTypeHelper<ReduceFunctor>::type, |
492 | std::enable_if_t<QtPrivate::isInitialValueCompatible_v<InitialValueType, ResultType>, |
493 | int> = 0> |
494 | ResultType blockingFilteredReduced(QThreadPool *pool, |
495 | Sequence &&sequence, |
496 | KeepFunctor &&keep, |
497 | ReduceFunctor &&reduce, |
498 | InitialValueType &&initialValue, |
499 | ReduceOptions options = ReduceOptions(UnorderedReduce |
500 | | SequentialReduce)) |
501 | { |
502 | QFuture<ResultType> future = filteredReduced<ResultType>( |
503 | pool, std::forward<Sequence>(sequence), std::forward<KeepFunctor>(keep), |
504 | std::forward<ReduceFunctor>(reduce), |
505 | ResultType(std::forward<InitialValueType>(initialValue)), options); |
506 | return future.takeResult(); |
507 | } |
508 | |
509 | template <typename Sequence, typename KeepFunctor, typename ReduceFunctor, |
510 | typename InitialValueType, |
511 | std::enable_if_t<QtPrivate::isInvocable<KeepFunctor, Sequence>::value, int> = 0, |
512 | typename ResultType = typename QtPrivate::ReduceResultTypeHelper<ReduceFunctor>::type, |
513 | std::enable_if_t<QtPrivate::isInitialValueCompatible_v<InitialValueType, ResultType>, |
514 | int> = 0> |
515 | ResultType blockingFilteredReduced(Sequence &&sequence, |
516 | KeepFunctor &&keep, |
517 | ReduceFunctor &&reduce, |
518 | InitialValueType &&initialValue, |
519 | ReduceOptions options = ReduceOptions(UnorderedReduce |
520 | | SequentialReduce)) |
521 | { |
522 | QFuture<ResultType> future = filteredReduced<ResultType>( |
523 | std::forward<Sequence>(sequence), std::forward<KeepFunctor>(keep), |
524 | std::forward<ReduceFunctor>(reduce), |
525 | ResultType(std::forward<InitialValueType>(initialValue)), options); |
526 | return future.takeResult(); |
527 | } |
528 | #endif |
529 | |
530 | // blocking filteredReduced() on iterators |
531 | template <typename ResultType, typename Iterator, typename KeepFunctor, typename ReduceFunctor> |
532 | ResultType blockingFilteredReduced(QThreadPool *pool, |
533 | Iterator begin, |
534 | Iterator end, |
535 | KeepFunctor &&keep, |
536 | ReduceFunctor &&reduce, |
537 | ReduceOptions options = ReduceOptions(UnorderedReduce |
538 | | SequentialReduce)) |
539 | { |
540 | QFuture<ResultType> future = |
541 | filteredReduced<ResultType>(pool, begin, end, std::forward<KeepFunctor>(keep), |
542 | std::forward<ReduceFunctor>(reduce), options); |
543 | return future.takeResult(); |
544 | } |
545 | |
546 | template <typename ResultType, typename Iterator, typename KeepFunctor, typename ReduceFunctor> |
547 | ResultType blockingFilteredReduced(Iterator begin, |
548 | Iterator end, |
549 | KeepFunctor &&keep, |
550 | ReduceFunctor &&reduce, |
551 | ReduceOptions options = ReduceOptions(UnorderedReduce |
552 | | SequentialReduce)) |
553 | { |
554 | QFuture<ResultType> future = |
555 | filteredReduced<ResultType>(begin, end, std::forward<KeepFunctor>(keep), |
556 | std::forward<ReduceFunctor>(reduce), options); |
557 | return future.takeResult(); |
558 | } |
559 | |
560 | #ifdef Q_QDOC |
561 | template <typename ResultType, typename Iterator, typename KeepFunctor, typename ReduceFunctor, |
562 | typename InitialValueType> |
563 | #else |
564 | template <typename ResultType, typename Iterator, typename KeepFunctor, typename ReduceFunctor, |
565 | typename InitialValueType, |
566 | std::enable_if_t<QtPrivate::isInitialValueCompatible_v<InitialValueType, ResultType>, |
567 | int> = 0> |
568 | #endif |
569 | ResultType blockingFilteredReduced(QThreadPool *pool, |
570 | Iterator begin, |
571 | Iterator end, |
572 | KeepFunctor &&keep, |
573 | ReduceFunctor &&reduce, |
574 | InitialValueType &&initialValue, |
575 | ReduceOptions options = ReduceOptions(UnorderedReduce |
576 | | SequentialReduce)) |
577 | { |
578 | QFuture<ResultType> future = filteredReduced<ResultType>( |
579 | pool, begin, end, std::forward<KeepFunctor>(keep), std::forward<ReduceFunctor>(reduce), |
580 | ResultType(std::forward<InitialValueType>(initialValue)), options); |
581 | return future.takeResult(); |
582 | } |
583 | |
584 | #ifdef Q_QDOC |
585 | template <typename ResultType, typename Iterator, typename KeepFunctor, typename ReduceFunctor, |
586 | typename InitialValueType> |
587 | #else |
588 | template <typename ResultType, typename Iterator, typename KeepFunctor, typename ReduceFunctor, |
589 | typename InitialValueType, |
590 | std::enable_if_t<QtPrivate::isInitialValueCompatible_v<InitialValueType, ResultType>, |
591 | int> = 0> |
592 | #endif |
593 | ResultType blockingFilteredReduced(Iterator begin, |
594 | Iterator end, |
595 | KeepFunctor &&keep, |
596 | ReduceFunctor &&reduce, |
597 | InitialValueType &&initialValue, |
598 | ReduceOptions options = ReduceOptions(UnorderedReduce |
599 | | SequentialReduce)) |
600 | { |
601 | QFuture<ResultType> future = filteredReduced<ResultType>( |
602 | begin, end, std::forward<KeepFunctor>(keep), std::forward<ReduceFunctor>(reduce), |
603 | ResultType(std::forward<InitialValueType>(initialValue)), options); |
604 | return future.takeResult(); |
605 | } |
606 | |
607 | #ifndef Q_QDOC |
608 | template <typename Iterator, typename KeepFunctor, typename ReduceFunctor, |
609 | typename ResultType = typename QtPrivate::ReduceResultTypeHelper<ReduceFunctor>::type> |
610 | ResultType blockingFilteredReduced(QThreadPool *pool, |
611 | Iterator begin, |
612 | Iterator end, |
613 | KeepFunctor &&keep, |
614 | ReduceFunctor &&reduce, |
615 | ReduceOptions options = ReduceOptions(UnorderedReduce |
616 | | SequentialReduce)) |
617 | { |
618 | QFuture<ResultType> future = |
619 | filteredReduced<ResultType>(pool, begin, end, std::forward<KeepFunctor>(keep), |
620 | std::forward<ReduceFunctor>(reduce), options); |
621 | return future.takeResult(); |
622 | } |
623 | |
624 | template <typename Iterator, typename KeepFunctor, typename ReduceFunctor, |
625 | typename ResultType = typename QtPrivate::ReduceResultTypeHelper<ReduceFunctor>::type> |
626 | ResultType blockingFilteredReduced(Iterator begin, |
627 | Iterator end, |
628 | KeepFunctor &&keep, |
629 | ReduceFunctor &&reduce, |
630 | ReduceOptions options = ReduceOptions(UnorderedReduce |
631 | | SequentialReduce)) |
632 | { |
633 | QFuture<ResultType> future = |
634 | filteredReduced<ResultType>(begin, end, std::forward<KeepFunctor>(keep), |
635 | std::forward<ReduceFunctor>(reduce), options); |
636 | return future.takeResult(); |
637 | } |
638 | |
639 | template <typename Iterator, typename KeepFunctor, typename ReduceFunctor, |
640 | typename ResultType = typename QtPrivate::ReduceResultTypeHelper<ReduceFunctor>::type, |
641 | typename InitialValueType, |
642 | std::enable_if_t<QtPrivate::isInitialValueCompatible_v<InitialValueType, ResultType>, |
643 | int> = 0> |
644 | ResultType blockingFilteredReduced(QThreadPool *pool, |
645 | Iterator begin, |
646 | Iterator end, KeepFunctor &&keep, |
647 | ReduceFunctor &&reduce, |
648 | InitialValueType &&initialValue, |
649 | ReduceOptions options = ReduceOptions(UnorderedReduce |
650 | | SequentialReduce)) |
651 | { |
652 | QFuture<ResultType> future = filteredReduced<ResultType>( |
653 | pool, begin, end, std::forward<KeepFunctor>(keep), std::forward<ReduceFunctor>(reduce), |
654 | ResultType(std::forward<InitialValueType>(initialValue)), options); |
655 | return future.takeResult(); |
656 | } |
657 | |
658 | template <typename Iterator, typename KeepFunctor, typename ReduceFunctor, |
659 | std::enable_if_t<QtPrivate::isIterator_v<Iterator>, int> = 0, |
660 | typename ResultType = typename QtPrivate::ReduceResultTypeHelper<ReduceFunctor>::type, |
661 | typename InitialValueType, |
662 | std::enable_if_t<QtPrivate::isInitialValueCompatible_v<InitialValueType, ResultType>, |
663 | int> = 0> |
664 | ResultType blockingFilteredReduced(Iterator begin, |
665 | Iterator end, |
666 | KeepFunctor &&keep, |
667 | ReduceFunctor &&reduce, |
668 | InitialValueType &&initialValue, |
669 | ReduceOptions options = ReduceOptions(UnorderedReduce |
670 | | SequentialReduce)) |
671 | { |
672 | QFuture<ResultType> future = filteredReduced<ResultType>( |
673 | begin, end, std::forward<KeepFunctor>(keep), std::forward<ReduceFunctor>(reduce), |
674 | ResultType(std::forward<InitialValueType>(initialValue)), options); |
675 | return future.takeResult(); |
676 | } |
677 | #endif |
678 | |
679 | // blocking filtered() on sequences |
680 | template <typename Sequence, typename KeepFunctor> |
681 | std::decay_t<Sequence> blockingFiltered(QThreadPool *pool, Sequence &&sequence, KeepFunctor &&keep) |
682 | { |
683 | return blockingFilteredReduced<std::decay_t<Sequence>>( |
684 | pool, std::forward<Sequence>(sequence), std::forward<KeepFunctor>(keep), |
685 | QtPrivate::PushBackWrapper(), OrderedReduce); |
686 | } |
687 | |
688 | template <typename Sequence, typename KeepFunctor> |
689 | std::decay_t<Sequence> blockingFiltered(Sequence &&sequence, KeepFunctor &&keep) |
690 | { |
691 | return blockingFilteredReduced<std::decay_t<Sequence>>( |
692 | QThreadPool::globalInstance(), std::forward<Sequence>(sequence), |
693 | std::forward<KeepFunctor>(keep), QtPrivate::PushBackWrapper(), OrderedReduce); |
694 | } |
695 | |
696 | // blocking filtered() on iterators |
697 | template <typename OutputSequence, typename Iterator, typename KeepFunctor> |
698 | OutputSequence blockingFiltered(QThreadPool *pool, Iterator begin, Iterator end, KeepFunctor &&keep) |
699 | { |
700 | return blockingFilteredReduced<OutputSequence>(pool, begin, end, |
701 | std::forward<KeepFunctor>(keep), |
702 | QtPrivate::PushBackWrapper(), OrderedReduce); |
703 | } |
704 | |
705 | template <typename OutputSequence, typename Iterator, typename KeepFunctor> |
706 | OutputSequence blockingFiltered(Iterator begin, Iterator end, KeepFunctor &&keep) |
707 | { |
708 | return blockingFilteredReduced<OutputSequence>(QThreadPool::globalInstance(), begin, end, |
709 | std::forward<KeepFunctor>(keep), |
710 | QtPrivate::PushBackWrapper(), OrderedReduce); |
711 | } |
712 | |
713 | } // namespace QtConcurrent |
714 | |
715 | QT_END_NAMESPACE |
716 | |
717 | #endif // QT_NO_CONCURRENT |
718 | |
719 | #endif |
720 | |