Qt
Internal/Contributor docs for the Qt SDK. Note: These are NOT official API docs; those are found at https://doc.qt.io/
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// Qt-Security score:significant reason:default
4
5#ifndef QTCONCURRENT_FILTER_H
6#define QTCONCURRENT_FILTER_H
7
8#if 0
9#pragma qt_class(QtConcurrentFilter)
10#endif
11
12#include <QtConcurrent/qtconcurrent_global.h>
13
14#if !defined(QT_NO_CONCURRENT) || defined(Q_QDOC)
15
16#include <QtConcurrent/qtconcurrentfilterkernel.h>
17#include <QtConcurrent/qtconcurrentfunctionwrappers.h>
18
19QT_BEGIN_NAMESPACE
20
21namespace QtConcurrent {
22
23//! [QtConcurrent-1]
24template <typename Sequence, typename KeepFunctor, typename ReduceFunctor>
25ThreadEngineStarter<void> filterInternal(QThreadPool *pool, Sequence &sequence,
26 KeepFunctor &&keep, ReduceFunctor &&reduce)
27{
28 typedef FilterKernel<Sequence, std::decay_t<KeepFunctor>, std::decay_t<ReduceFunctor>>
29 KernelType;
30 return startThreadEngine(new KernelType(pool, sequence, std::forward<KeepFunctor>(keep),
31 std::forward<ReduceFunctor>(reduce)));
32}
33
34// filter() on sequences
35template <typename Sequence, typename KeepFunctor>
36QFuture<void> filter(QThreadPool *pool, Sequence &sequence, KeepFunctor &&keep)
37{
38 return filterInternal(pool, sequence, std::forward<KeepFunctor>(keep),
39 QtPrivate::PushBackWrapper());
40}
41
42template <typename Sequence, typename KeepFunctor>
43QFuture<void> filter(Sequence &sequence, KeepFunctor &&keep)
44{
45 return filterInternal(QThreadPool::globalInstance(),
46 sequence, std::forward<KeepFunctor>(keep), QtPrivate::PushBackWrapper());
47}
48
49// filteredReduced() on sequences
50template <typename ResultType, typename Sequence, typename KeepFunctor, typename ReduceFunctor>
52 Sequence &&sequence,
53 KeepFunctor &&keep,
54 ReduceFunctor &&reduce,
55 ReduceOptions options = ReduceOptions(UnorderedReduce
57{
58 return startFilteredReduced<ResultType>(pool, std::forward<Sequence>(sequence),
59 std::forward<KeepFunctor>(keep),
60 std::forward<ReduceFunctor>(reduce), options);
61}
62
63template <typename ResultType, typename Sequence, typename KeepFunctor, typename ReduceFunctor>
64QFuture<ResultType> filteredReduced(Sequence &&sequence,
65 KeepFunctor &&keep,
66 ReduceFunctor &&reduce,
67 ReduceOptions options = ReduceOptions(UnorderedReduce
69{
70 return startFilteredReduced<ResultType>(
71 QThreadPool::globalInstance(), std::forward<Sequence>(sequence),
72 std::forward<KeepFunctor>(keep), std::forward<ReduceFunctor>(reduce), options);
73}
74
75#ifdef Q_QDOC
76template <typename ResultType, typename Sequence, typename KeepFunctor, typename ReduceFunctor,
77 typename InitialValueType>
78#else
79template <typename ResultType, typename Sequence, typename KeepFunctor, typename ReduceFunctor,
80 typename InitialValueType,
82 int> = 0>
83#endif
97
98#ifdef Q_QDOC
99template <typename ResultType, typename Sequence, typename KeepFunctor, typename ReduceFunctor,
100 typename InitialValueType>
101#else
102template <typename ResultType, typename Sequence, typename KeepFunctor, typename ReduceFunctor,
103 typename InitialValueType,
105 int> = 0>
106#endif
119
120#ifndef Q_QDOC
121template <typename Sequence, typename KeepFunctor, typename ReduceFunctor,
135
136template <typename Sequence, typename KeepFunctor, typename ReduceFunctor,
149
150template <typename Sequence, typename KeepFunctor, typename ReduceFunctor,
151 typename InitialValueType,
155 int> = 0>
169
170template <typename Sequence, typename KeepFunctor, typename ReduceFunctor,
171 typename InitialValueType,
175 int> = 0>
188#endif
189
190// filteredReduced() on iterators
191template <typename ResultType, typename Iterator, typename KeepFunctor, typename ReduceFunctor>
193 Iterator begin,
194 Iterator end,
195 KeepFunctor &&keep,
196 ReduceFunctor &&reduce,
197 ReduceOptions options = ReduceOptions(UnorderedReduce
199{
200 return startFilteredReduced<ResultType>(pool, begin, end, std::forward<KeepFunctor>(keep),
201 std::forward<ReduceFunctor>(reduce), options);
202}
203
204template <typename ResultType, typename Iterator, typename KeepFunctor, typename ReduceFunctor>
206 Iterator end,
207 KeepFunctor &&keep,
208 ReduceFunctor &&reduce,
209 ReduceOptions options = ReduceOptions(UnorderedReduce
211{
212 return startFilteredReduced<ResultType>(QThreadPool::globalInstance(), begin, end,
213 std::forward<KeepFunctor>(keep),
214 std::forward<ReduceFunctor>(reduce), options);
215}
216
217#ifdef Q_QDOC
218template <typename ResultType, typename Iterator, typename KeepFunctor, typename ReduceFunctor,
219 typename InitialValueType>
220#else
221template <typename ResultType, typename Iterator, typename KeepFunctor, typename ReduceFunctor,
222 typename InitialValueType,
224 int> = 0>
225#endif
239
240#ifdef Q_QDOC
241template <typename ResultType, typename Iterator, typename KeepFunctor, typename ReduceFunctor,
242 typename InitialValueType>
243#else
244template <typename ResultType, typename Iterator, typename KeepFunctor, typename ReduceFunctor,
245 typename InitialValueType,
247 int> = 0>
248#endif
262
263#ifndef Q_QDOC
264template <typename Iterator, typename KeepFunctor, typename ReduceFunctor,
273{
276}
277
278template <typename Iterator, typename KeepFunctor, typename ReduceFunctor,
286{
290}
291
292template <typename Iterator, typename KeepFunctor, typename ReduceFunctor,
294 typename InitialValueType,
296 int> = 0>
305{
309}
310
311template <typename Iterator, typename KeepFunctor, typename ReduceFunctor,
314 typename InitialValueType,
316 int> = 0>
330#endif
331
332// filtered() on sequences
333template <typename Sequence, typename KeepFunctor>
339
340template <typename Sequence, typename KeepFunctor>
347
348// filtered() on iterators
349template <typename Iterator, typename KeepFunctor>
350QFuture<typename qValueType<Iterator>::value_type> filtered(QThreadPool *pool,
351 Iterator begin,
352 Iterator end,
353 KeepFunctor &&keep)
354{
355 return startFiltered(pool, begin, end, std::forward<KeepFunctor>(keep));
356}
357
358template <typename Iterator, typename KeepFunctor>
359QFuture<typename qValueType<Iterator>::value_type> filtered(Iterator begin,
360 Iterator end,
361 KeepFunctor &&keep)
362{
363 return startFiltered(QThreadPool::globalInstance(), begin, end,
364 std::forward<KeepFunctor>(keep));
365}
366
367// blocking filter() on sequences
368template <typename Sequence, typename KeepFunctor>
369void blockingFilter(QThreadPool *pool, Sequence &sequence, KeepFunctor &&keep)
370{
371 QFuture<void> future = filter(pool, sequence, std::forward<KeepFunctor>(keep));
372 future.waitForFinished();
373}
374
375template <typename Sequence, typename KeepFunctor>
376void blockingFilter(Sequence &sequence, KeepFunctor &&keep)
377{
378 QFuture<void> future = filter(sequence, std::forward<KeepFunctor>(keep));
379 future.waitForFinished();
380}
381
382// blocking filteredReduced() on sequences
383template <typename ResultType, typename Sequence, typename KeepFunctor, typename ReduceFunctor>
384ResultType blockingFilteredReduced(QThreadPool *pool,
385 Sequence &&sequence,
386 KeepFunctor &&keep,
387 ReduceFunctor &&reduce,
388 ReduceOptions options = ReduceOptions(UnorderedReduce
390{
391 QFuture<ResultType> future = filteredReduced<ResultType>(
392 pool, std::forward<Sequence>(sequence), std::forward<KeepFunctor>(keep),
393 std::forward<ReduceFunctor>(reduce), options);
394 return future.takeResult();
395}
396
397template <typename ResultType, typename Sequence, typename KeepFunctor, typename ReduceFunctor>
398ResultType blockingFilteredReduced(Sequence &&sequence,
399 KeepFunctor &&keep,
400 ReduceFunctor &&reduce,
401 ReduceOptions options = ReduceOptions(UnorderedReduce
403{
404 QFuture<ResultType> future = filteredReduced<ResultType>(
405 std::forward<Sequence>(sequence), std::forward<KeepFunctor>(keep),
406 std::forward<ReduceFunctor>(reduce), options);
407 return future.takeResult();
408}
409
410#ifdef Q_QDOC
411template <typename ResultType, typename Sequence, typename KeepFunctor, typename ReduceFunctor,
412 typename InitialValueType>
413#else
414template <typename ResultType, typename Sequence, typename KeepFunctor, typename ReduceFunctor,
415 typename InitialValueType,
417 int> = 0>
418#endif
433
434#ifdef Q_QDOC
435template <typename ResultType, typename Sequence, typename KeepFunctor, typename ReduceFunctor,
436 typename InitialValueType>
437#else
438template <typename ResultType, typename Sequence, typename KeepFunctor, typename ReduceFunctor,
439 typename InitialValueType,
441 int> = 0>
442#endif
456
457#ifndef Q_QDOC
458template <typename Sequence, typename KeepFunctor, typename ReduceFunctor,
473
474template <typename Sequence, typename KeepFunctor, typename ReduceFunctor,
488
489template <typename Sequence, typename KeepFunctor, typename ReduceFunctor,
490 typename InitialValueType,
494 int> = 0>
509
510template <typename Sequence, typename KeepFunctor, typename ReduceFunctor,
511 typename InitialValueType,
515 int> = 0>
529#endif
530
531// blocking filteredReduced() on iterators
532template <typename ResultType, typename Iterator, typename KeepFunctor, typename ReduceFunctor>
533ResultType blockingFilteredReduced(QThreadPool *pool,
534 Iterator begin,
535 Iterator end,
536 KeepFunctor &&keep,
537 ReduceFunctor &&reduce,
538 ReduceOptions options = ReduceOptions(UnorderedReduce
540{
541 QFuture<ResultType> future =
542 filteredReduced<ResultType>(pool, begin, end, std::forward<KeepFunctor>(keep),
543 std::forward<ReduceFunctor>(reduce), options);
544 return future.takeResult();
545}
546
547template <typename ResultType, typename Iterator, typename KeepFunctor, typename ReduceFunctor>
548ResultType blockingFilteredReduced(Iterator begin,
549 Iterator end,
550 KeepFunctor &&keep,
551 ReduceFunctor &&reduce,
552 ReduceOptions options = ReduceOptions(UnorderedReduce
554{
555 QFuture<ResultType> future =
556 filteredReduced<ResultType>(begin, end, std::forward<KeepFunctor>(keep),
557 std::forward<ReduceFunctor>(reduce), options);
558 return future.takeResult();
559}
560
561#ifdef Q_QDOC
562template <typename ResultType, typename Iterator, typename KeepFunctor, typename ReduceFunctor,
563 typename InitialValueType>
564#else
565template <typename ResultType, typename Iterator, typename KeepFunctor, typename ReduceFunctor,
566 typename InitialValueType,
568 int> = 0>
569#endif
584
585#ifdef Q_QDOC
586template <typename ResultType, typename Iterator, typename KeepFunctor, typename ReduceFunctor,
587 typename InitialValueType>
588#else
589template <typename ResultType, typename Iterator, typename KeepFunctor, typename ReduceFunctor,
590 typename InitialValueType,
592 int> = 0>
593#endif
607
608#ifndef Q_QDOC
609template <typename Iterator, typename KeepFunctor, typename ReduceFunctor,
618{
622 return future.takeResult();
623}
624
625template <typename Iterator, typename KeepFunctor, typename ReduceFunctor,
633{
637 return future.takeResult();
638}
639
640template <typename Iterator, typename KeepFunctor, typename ReduceFunctor,
642 typename InitialValueType,
644 int> = 0>
652{
656 return future.takeResult();
657}
658
659template <typename Iterator, typename KeepFunctor, typename ReduceFunctor,
662 typename InitialValueType,
664 int> = 0>
678#endif
679
680// blocking filtered() on sequences
681template <typename Sequence, typename KeepFunctor>
682std::decay_t<Sequence> blockingFiltered(QThreadPool *pool, Sequence &&sequence, KeepFunctor &&keep)
683{
684 return blockingFilteredReduced<std::decay_t<Sequence>>(
685 pool, std::forward<Sequence>(sequence), std::forward<KeepFunctor>(keep),
686 QtPrivate::PushBackWrapper(), OrderedReduce);
687}
688
689template <typename Sequence, typename KeepFunctor>
690std::decay_t<Sequence> blockingFiltered(Sequence &&sequence, KeepFunctor &&keep)
691{
692 return blockingFilteredReduced<std::decay_t<Sequence>>(
693 QThreadPool::globalInstance(), std::forward<Sequence>(sequence),
694 std::forward<KeepFunctor>(keep), QtPrivate::PushBackWrapper(), OrderedReduce);
695}
696
697// blocking filtered() on iterators
698template <typename OutputSequence, typename Iterator, typename KeepFunctor>
699OutputSequence blockingFiltered(QThreadPool *pool, Iterator begin, Iterator end, KeepFunctor &&keep)
700{
701 return blockingFilteredReduced<OutputSequence>(pool, begin, end,
702 std::forward<KeepFunctor>(keep),
703 QtPrivate::PushBackWrapper(), OrderedReduce);
704}
705
706template <typename OutputSequence, typename Iterator, typename KeepFunctor>
707OutputSequence blockingFiltered(Iterator begin, Iterator end, KeepFunctor &&keep)
708{
709 return blockingFilteredReduced<OutputSequence>(QThreadPool::globalInstance(), begin, end,
710 std::forward<KeepFunctor>(keep),
711 QtPrivate::PushBackWrapper(), OrderedReduce);
712}
713
714} // namespace QtConcurrent
715
716QT_END_NAMESPACE
717
718#endif // QT_NO_CONCURRENT
719
720#endif
\inmodule QtConcurrent
QFuture< void > filter(QThreadPool *pool, Sequence &sequence, KeepFunctor &&keep)
Calls filterFunction once for each item in sequence.
QFuture< ResultType > filteredReduced(Sequence &&sequence, KeepFunctor &&keep, ReduceFunctor &&reduce, ReduceOptions options=ReduceOptions(UnorderedReduce|SequentialReduce))
OutputSequence blockingFiltered(QThreadPool *pool, Iterator begin, Iterator end, KeepFunctor &&keep)
Calls filterFunction once for each item from begin to end and returns a new Sequence of kept items.
QFuture< ResultType > filteredReduced(QThreadPool *pool, Sequence &&sequence, KeepFunctor &&keep, ReduceFunctor &&reduce, ReduceOptions options=ReduceOptions(UnorderedReduce|SequentialReduce))
QFuture< void > filter(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]
void blockingFilter(Sequence &sequence, KeepFunctor &&keep)
Calls filterFunction once for each item in sequence.
QFuture< ResultType > filteredReduced(QThreadPool *pool, Iterator begin, Iterator end, KeepFunctor &&keep, ReduceFunctor &&reduce, ReduceOptions options=ReduceOptions(UnorderedReduce|SequentialReduce))
QFuture< typename qValueType< Iterator >::value_type > filtered(Iterator begin, Iterator end, KeepFunctor &&keep)
Calls filterFunction once for each item from begin to end and returns a new Sequence of kept items.
ResultType blockingFilteredReduced(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.
OutputSequence blockingFiltered(Iterator begin, Iterator end, KeepFunctor &&keep)
Calls filterFunction once for each item from begin to end and returns a new Sequence of kept items.
ResultType blockingFilteredReduced(QThreadPool *pool, Iterator begin, Iterator end, KeepFunctor &&keep, ReduceFunctor &&reduce, ReduceOptions options=ReduceOptions(UnorderedReduce|SequentialReduce))
ResultType blockingFilteredReduced(Iterator begin, Iterator end, KeepFunctor &&keep, ReduceFunctor &&reduce, ReduceOptions options=ReduceOptions(UnorderedReduce|SequentialReduce))
ResultType blockingFilteredReduced(QThreadPool *pool, Sequence &&sequence, KeepFunctor &&keep, ReduceFunctor &&reduce, ReduceOptions options=ReduceOptions(UnorderedReduce|SequentialReduce))
QFuture< typename qValueType< Iterator >::value_type > filtered(QThreadPool *pool, Iterator begin, Iterator end, KeepFunctor &&keep)
Calls filterFunction once for each item from begin to end and returns a new Sequence of kept items.
QFuture< ResultType > filteredReduced(Iterator begin, Iterator end, 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.
std::decay_t< Sequence > blockingFiltered(Sequence &&sequence, KeepFunctor &&keep)
Calls filterFunction once for each item in sequence and returns a new Sequence of kept items.
QString type