Qt
Internal/Contributor docs for the Qt SDK. <b>Note:</b> These are NOT official API docs; those are found <a href='https://doc.qt.io/'>here</a>.
Loading...
Searching...
No Matches
qtconcurrentfilter.h
Go to the documentation of this file.
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
19
20namespace QtConcurrent {
21
23template <typename Sequence, typename KeepFunctor, typename ReduceFunctor>
24ThreadEngineStarter<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
34template <typename Sequence, typename KeepFunctor>
35QFuture<void> filter(QThreadPool *pool, Sequence &sequence, KeepFunctor &&keep)
36{
37 return filterInternal(pool, sequence, std::forward<KeepFunctor>(keep),
39}
40
41template <typename Sequence, typename KeepFunctor>
42QFuture<void> filter(Sequence &sequence, KeepFunctor &&keep)
43{
45 sequence, std::forward<KeepFunctor>(keep), QtPrivate::PushBackWrapper());
46}
47
48// filteredReduced() on sequences
49template <typename ResultType, typename Sequence, typename KeepFunctor, typename ReduceFunctor>
50QFuture<ResultType> filteredReduced(QThreadPool *pool,
51 Sequence &&sequence,
52 KeepFunctor &&keep,
53 ReduceFunctor &&reduce,
54 ReduceOptions options = ReduceOptions(UnorderedReduce
56{
57 return startFilteredReduced<ResultType>(pool, std::forward<Sequence>(sequence),
58 std::forward<KeepFunctor>(keep),
59 std::forward<ReduceFunctor>(reduce), options);
60}
61
62template <typename ResultType, typename Sequence, typename KeepFunctor, typename ReduceFunctor>
63QFuture<ResultType> filteredReduced(Sequence &&sequence,
64 KeepFunctor &&keep,
65 ReduceFunctor &&reduce,
66 ReduceOptions options = ReduceOptions(UnorderedReduce
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
75template <typename ResultType, typename Sequence, typename KeepFunctor, typename ReduceFunctor,
76 typename InitialValueType>
77#else
78template <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
83QFuture<ResultType> filteredReduced(QThreadPool *pool,
84 Sequence &&sequence,
85 KeepFunctor &&keep,
86 ReduceFunctor &&reduce,
87 InitialValueType &&initialValue,
88 ReduceOptions options = ReduceOptions(UnorderedReduce
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
98template <typename ResultType, typename Sequence, typename KeepFunctor, typename ReduceFunctor,
99 typename InitialValueType>
100#else
101template <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
106QFuture<ResultType> filteredReduced(Sequence &&sequence,
107 KeepFunctor &&keep,
108 ReduceFunctor &&reduce,
109 InitialValueType &&initialValue,
110 ReduceOptions options = ReduceOptions(UnorderedReduce
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
120template <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>
123QFuture<ResultType> filteredReduced(QThreadPool *pool,
124 Sequence &&sequence,
125 KeepFunctor &&keep,
126 ReduceFunctor &&reduce,
127 ReduceOptions options = ReduceOptions(UnorderedReduce
129{
130 return startFilteredReduced<ResultType>(pool, std::forward<Sequence>(sequence),
131 std::forward<KeepFunctor>(keep),
132 std::forward<ReduceFunctor>(reduce), options);
133}
134
135template <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>
138QFuture<ResultType> filteredReduced(Sequence &&sequence,
139 KeepFunctor &&keep,
140 ReduceFunctor &&reduce,
141 ReduceOptions options = ReduceOptions(UnorderedReduce
143{
144 return startFilteredReduced<ResultType>(
145 QThreadPool::globalInstance(), std::forward<Sequence>(sequence),
146 std::forward<KeepFunctor>(keep), std::forward<ReduceFunctor>(reduce), options);
147}
148
149template <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>
155QFuture<ResultType> filteredReduced(QThreadPool *pool,
156 Sequence &&sequence,
157 KeepFunctor &&keep,
158 ReduceFunctor &&reduce,
159 InitialValueType &&initialValue,
160 ReduceOptions options = ReduceOptions(UnorderedReduce
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
169template <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>
175QFuture<ResultType> filteredReduced(Sequence &&sequence,
176 KeepFunctor &&keep,
177 ReduceFunctor &&reduce,
178 InitialValueType &&initialValue,
179 ReduceOptions options = ReduceOptions(UnorderedReduce
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
190template <typename ResultType, typename Iterator, typename KeepFunctor, typename ReduceFunctor>
191QFuture<ResultType> filteredReduced(QThreadPool *pool,
192 Iterator begin,
193 Iterator end,
194 KeepFunctor &&keep,
195 ReduceFunctor &&reduce,
196 ReduceOptions options = ReduceOptions(UnorderedReduce
198{
199 return startFilteredReduced<ResultType>(pool, begin, end, std::forward<KeepFunctor>(keep),
200 std::forward<ReduceFunctor>(reduce), options);
201}
202
203template <typename ResultType, typename Iterator, typename KeepFunctor, typename ReduceFunctor>
204QFuture<ResultType> filteredReduced(Iterator begin,
205 Iterator end,
206 KeepFunctor &&keep,
207 ReduceFunctor &&reduce,
208 ReduceOptions options = ReduceOptions(UnorderedReduce
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
217template <typename ResultType, typename Iterator, typename KeepFunctor, typename ReduceFunctor,
218 typename InitialValueType>
219#else
220template <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
225QFuture<ResultType> filteredReduced(QThreadPool *pool,
226 Iterator begin,
227 Iterator end,
228 KeepFunctor &&keep,
229 ReduceFunctor &&reduce,
230 InitialValueType &&initialValue,
231 ReduceOptions options = ReduceOptions(UnorderedReduce
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
240template <typename ResultType, typename Iterator, typename KeepFunctor, typename ReduceFunctor,
241 typename InitialValueType>
242#else
243template <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
248QFuture<ResultType> filteredReduced(Iterator begin,
249 Iterator end,
250 KeepFunctor &&keep,
251 ReduceFunctor &&reduce,
252 InitialValueType &&initialValue,
253 ReduceOptions options = ReduceOptions(UnorderedReduce
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
263template <typename Iterator, typename KeepFunctor, typename ReduceFunctor,
264 typename ResultType = typename QtPrivate::ReduceResultTypeHelper<ReduceFunctor>::type>
265QFuture<ResultType> filteredReduced(QThreadPool *pool,
266 Iterator begin,
267 Iterator end,
268 KeepFunctor &&keep,
269 ReduceFunctor &&reduce,
270 ReduceOptions options = ReduceOptions(UnorderedReduce
272{
273 return startFilteredReduced<ResultType>(pool, begin, end, std::forward<KeepFunctor>(keep),
274 std::forward<ReduceFunctor>(reduce), options);
275}
276
277template <typename Iterator, typename KeepFunctor, typename ReduceFunctor,
278 typename ResultType = typename QtPrivate::ReduceResultTypeHelper<ReduceFunctor>::type>
279QFuture<ResultType> filteredReduced(Iterator begin,
280 Iterator end,
281 KeepFunctor &&keep,
282 ReduceFunctor &&reduce,
283 ReduceOptions options = ReduceOptions(UnorderedReduce
285{
286 return startFilteredReduced<ResultType>(QThreadPool::globalInstance(), begin, end,
287 std::forward<KeepFunctor>(keep),
288 std::forward<ReduceFunctor>(reduce), options);
289}
290
291template <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>
296QFuture<ResultType> filteredReduced(QThreadPool *pool,
297 Iterator begin,
298 Iterator end,
299 KeepFunctor &&keep,
300 ReduceFunctor &&reduce,
301 InitialValueType &&initialValue,
302 ReduceOptions options = ReduceOptions(UnorderedReduce
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
310template <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>
316QFuture<ResultType> filteredReduced(Iterator begin,
317 Iterator end,
318 KeepFunctor &&keep,
319 ReduceFunctor &&reduce,
320 InitialValueType &&initialValue,
321 ReduceOptions options = ReduceOptions(UnorderedReduce
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
332template <typename Sequence, typename KeepFunctor>
333QFuture<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
339template <typename Sequence, typename KeepFunctor>
340QFuture<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
348template <typename Iterator, typename KeepFunctor>
349QFuture<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
357template <typename Iterator, typename KeepFunctor>
358QFuture<typename qValueType<Iterator>::value_type> filtered(Iterator begin,
359 Iterator end,
360 KeepFunctor &&keep)
361{
363 std::forward<KeepFunctor>(keep));
364}
365
366// blocking filter() on sequences
367template <typename Sequence, typename KeepFunctor>
368void blockingFilter(QThreadPool *pool, Sequence &sequence, KeepFunctor &&keep)
369{
370 QFuture<void> future = filter(pool, sequence, std::forward<KeepFunctor>(keep));
372}
373
374template <typename Sequence, typename KeepFunctor>
375void blockingFilter(Sequence &sequence, KeepFunctor &&keep)
376{
377 QFuture<void> future = filter(sequence, std::forward<KeepFunctor>(keep));
379}
380
381// blocking filteredReduced() on sequences
382template <typename ResultType, typename Sequence, typename KeepFunctor, typename ReduceFunctor>
384 Sequence &&sequence,
385 KeepFunctor &&keep,
386 ReduceFunctor &&reduce,
387 ReduceOptions options = ReduceOptions(UnorderedReduce
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
396template <typename ResultType, typename Sequence, typename KeepFunctor, typename ReduceFunctor>
397ResultType blockingFilteredReduced(Sequence &&sequence,
398 KeepFunctor &&keep,
399 ReduceFunctor &&reduce,
400 ReduceOptions options = ReduceOptions(UnorderedReduce
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
410template <typename ResultType, typename Sequence, typename KeepFunctor, typename ReduceFunctor,
411 typename InitialValueType>
412#else
413template <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
419 Sequence &&sequence,
420 KeepFunctor &&keep,
421 ReduceFunctor &&reduce,
422 InitialValueType &&initialValue,
423 ReduceOptions options = ReduceOptions(UnorderedReduce
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
434template <typename ResultType, typename Sequence, typename KeepFunctor, typename ReduceFunctor,
435 typename InitialValueType>
436#else
437template <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
442ResultType blockingFilteredReduced(Sequence &&sequence,
443 KeepFunctor &&keep,
444 ReduceFunctor &&reduce,
445 InitialValueType &&initialValue,
446 ReduceOptions options = ReduceOptions(UnorderedReduce
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
457template <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>
461 Sequence &&sequence,
462 KeepFunctor &&keep,
463 ReduceFunctor &&reduce,
464 ReduceOptions options = ReduceOptions(UnorderedReduce
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
473template <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>
476ResultType blockingFilteredReduced(Sequence &&sequence,
477 KeepFunctor &&keep,
478 ReduceFunctor &&reduce,
479 ReduceOptions options = ReduceOptions(UnorderedReduce
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
488template <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>
495 Sequence &&sequence,
496 KeepFunctor &&keep,
497 ReduceFunctor &&reduce,
498 InitialValueType &&initialValue,
499 ReduceOptions options = ReduceOptions(UnorderedReduce
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
509template <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>
515ResultType blockingFilteredReduced(Sequence &&sequence,
516 KeepFunctor &&keep,
517 ReduceFunctor &&reduce,
518 InitialValueType &&initialValue,
519 ReduceOptions options = ReduceOptions(UnorderedReduce
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
531template <typename ResultType, typename Iterator, typename KeepFunctor, typename ReduceFunctor>
533 Iterator begin,
534 Iterator end,
535 KeepFunctor &&keep,
536 ReduceFunctor &&reduce,
537 ReduceOptions options = ReduceOptions(UnorderedReduce
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
546template <typename ResultType, typename Iterator, typename KeepFunctor, typename ReduceFunctor>
547ResultType blockingFilteredReduced(Iterator begin,
548 Iterator end,
549 KeepFunctor &&keep,
550 ReduceFunctor &&reduce,
551 ReduceOptions options = ReduceOptions(UnorderedReduce
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
561template <typename ResultType, typename Iterator, typename KeepFunctor, typename ReduceFunctor,
562 typename InitialValueType>
563#else
564template <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
570 Iterator begin,
571 Iterator end,
572 KeepFunctor &&keep,
573 ReduceFunctor &&reduce,
574 InitialValueType &&initialValue,
575 ReduceOptions options = ReduceOptions(UnorderedReduce
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
585template <typename ResultType, typename Iterator, typename KeepFunctor, typename ReduceFunctor,
586 typename InitialValueType>
587#else
588template <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
593ResultType blockingFilteredReduced(Iterator begin,
594 Iterator end,
595 KeepFunctor &&keep,
596 ReduceFunctor &&reduce,
597 InitialValueType &&initialValue,
598 ReduceOptions options = ReduceOptions(UnorderedReduce
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
608template <typename Iterator, typename KeepFunctor, typename ReduceFunctor,
609 typename ResultType = typename QtPrivate::ReduceResultTypeHelper<ReduceFunctor>::type>
611 Iterator begin,
612 Iterator end,
613 KeepFunctor &&keep,
614 ReduceFunctor &&reduce,
615 ReduceOptions options = ReduceOptions(UnorderedReduce
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
624template <typename Iterator, typename KeepFunctor, typename ReduceFunctor,
625 typename ResultType = typename QtPrivate::ReduceResultTypeHelper<ReduceFunctor>::type>
626ResultType blockingFilteredReduced(Iterator begin,
627 Iterator end,
628 KeepFunctor &&keep,
629 ReduceFunctor &&reduce,
630 ReduceOptions options = ReduceOptions(UnorderedReduce
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
639template <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>
645 Iterator begin,
646 Iterator end, KeepFunctor &&keep,
647 ReduceFunctor &&reduce,
648 InitialValueType &&initialValue,
649 ReduceOptions options = ReduceOptions(UnorderedReduce
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
658template <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>
664ResultType blockingFilteredReduced(Iterator begin,
665 Iterator end,
666 KeepFunctor &&keep,
667 ReduceFunctor &&reduce,
668 InitialValueType &&initialValue,
669 ReduceOptions options = ReduceOptions(UnorderedReduce
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
680template <typename Sequence, typename KeepFunctor>
681std::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),
686}
687
688template <typename Sequence, typename KeepFunctor>
689std::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
697template <typename OutputSequence, typename Iterator, typename KeepFunctor>
698OutputSequence blockingFiltered(QThreadPool *pool, Iterator begin, Iterator end, KeepFunctor &&keep)
699{
700 return blockingFilteredReduced<OutputSequence>(pool, begin, end,
701 std::forward<KeepFunctor>(keep),
703}
704
705template <typename OutputSequence, typename Iterator, typename KeepFunctor>
706OutputSequence blockingFiltered(Iterator begin, Iterator end, KeepFunctor &&keep)
707{
708 return blockingFilteredReduced<OutputSequence>(QThreadPool::globalInstance(), begin, end,
709 std::forward<KeepFunctor>(keep),
711}
712
713} // namespace QtConcurrent
714
716
717#endif // QT_NO_CONCURRENT
718
719#endif
void waitForFinished()
Definition qfuture.h:102
T takeResult()
Definition qfuture.h:117
\inmodule QtCore
Definition qthreadpool.h:22
static QThreadPool * globalInstance()
Returns the global QThreadPool instance.
Combined button and popup list for selecting options.
\inmodule QtConcurrent
QFuture< typename std::decay_t< Sequence >::value_type > filtered(QThreadPool *pool, Sequence &&sequence, KeepFunctor &&keep)
Calls filterFunction once for each item in sequence and returns a new Sequence of kept items.
QFuture< ResultType > filteredReduced(QThreadPool *pool, Sequence &&sequence, KeepFunctor &&keep, ReduceFunctor &&reduce, ReduceOptions options=ReduceOptions(UnorderedReduce|SequentialReduce))
void blockingFilter(QThreadPool *pool, Sequence &sequence, KeepFunctor &&keep)
Calls filterFunction once for each item in sequence.
ThreadEngineStarter< void > filterInternal(QThreadPool *pool, Sequence &sequence, KeepFunctor &&keep, ReduceFunctor &&reduce)
[QtConcurrent-1]
ThreadEngineStarter< typename qValueType< Iterator >::value_type > startFiltered(QThreadPool *pool, Iterator begin, Iterator end, KeepFunctor &&functor)
[QtConcurrent-2]
ThreadEngineStarter< typename ThreadEngine::ResultType > startThreadEngine(ThreadEngine *threadEngine)
[qtconcurrentthreadengine-1]
ResultType blockingFilteredReduced(QThreadPool *pool, Sequence &&sequence, KeepFunctor &&keep, ReduceFunctor &&reduce, ReduceOptions options=ReduceOptions(UnorderedReduce|SequentialReduce))
std::decay_t< Sequence > blockingFiltered(QThreadPool *pool, Sequence &&sequence, KeepFunctor &&keep)
Calls filterFunction once for each item in sequence and returns a new Sequence of kept items.
GLuint GLuint end
GLint GLint GLint GLint GLint GLint GLint GLbitfield GLenum filter
QtPrivate::QRegularExpressionMatchIteratorRangeBasedForIterator begin(const QRegularExpressionMatchIterator &iterator)
QFuture< void > future
[5]