5#ifndef QTCONCURRENT_FILTER_H
6#define QTCONCURRENT_FILTER_H
9#pragma qt_class(QtConcurrentFilter)
12#include <QtConcurrent/qtconcurrent_global.h>
14#if !defined(QT_NO_CONCURRENT) || defined(Q_QDOC)
16#include <QtConcurrent/qtconcurrentfilterkernel.h>
17#include <QtConcurrent/qtconcurrentfunctionwrappers.h>
24template <
typename Sequence,
typename KeepFunctor,
typename ReduceFunctor>
26 KeepFunctor &&keep, ReduceFunctor &&reduce)
28 typedef FilterKernel<Sequence, std::decay_t<KeepFunctor>, std::decay_t<ReduceFunctor>>
30 return startThreadEngine(
new KernelType(pool, sequence, std::forward<KeepFunctor>(keep),
31 std::forward<ReduceFunctor>(reduce)));
35template <
typename Sequence,
typename KeepFunctor>
36QFuture<
void>
filter(QThreadPool *pool, Sequence &sequence, KeepFunctor &&keep)
38 return filterInternal(pool, sequence, std::forward<KeepFunctor>(keep),
39 QtPrivate::PushBackWrapper());
42template <
typename Sequence,
typename KeepFunctor>
45 return filterInternal(QThreadPool::globalInstance(),
46 sequence, std::forward<KeepFunctor>(keep), QtPrivate::PushBackWrapper());
50template <
typename ResultType,
typename Sequence,
typename KeepFunctor,
typename ReduceFunctor>
54 ReduceFunctor &&reduce,
58 return startFilteredReduced<ResultType>(pool, std::forward<Sequence>(sequence),
59 std::forward<KeepFunctor>(keep),
60 std::forward<ReduceFunctor>(reduce), options);
63template <
typename ResultType,
typename Sequence,
typename KeepFunctor,
typename ReduceFunctor>
66 ReduceFunctor &&reduce,
70 return startFilteredReduced<ResultType>(
71 QThreadPool::globalInstance(), std::forward<Sequence>(sequence),
72 std::forward<KeepFunctor>(keep), std::forward<ReduceFunctor>(reduce), options);
191template <
typename ResultType,
typename Iterator,
typename KeepFunctor,
typename ReduceFunctor>
196 ReduceFunctor &&reduce,
200 return startFilteredReduced<ResultType>(pool, begin, end, std::forward<KeepFunctor>(keep),
201 std::forward<ReduceFunctor>(reduce), options);
204template <
typename ResultType,
typename Iterator,
typename KeepFunctor,
typename ReduceFunctor>
208 ReduceFunctor &&reduce,
212 return startFilteredReduced<ResultType>(QThreadPool::globalInstance(), begin, end,
213 std::forward<KeepFunctor>(keep),
214 std::forward<ReduceFunctor>(reduce), options);
294 typename InitialValueType,
349template <
typename Iterator,
typename KeepFunctor>
355 return startFiltered(pool, begin, end, std::forward<KeepFunctor>(keep));
358template <
typename Iterator,
typename KeepFunctor>
363 return startFiltered(QThreadPool::globalInstance(), begin, end,
364 std::forward<KeepFunctor>(keep));
368template <
typename Sequence,
typename KeepFunctor>
371 QFuture<
void> future = filter(pool, sequence, std::forward<KeepFunctor>(keep));
372 future.waitForFinished();
375template <
typename Sequence,
typename KeepFunctor>
378 QFuture<
void> future = filter(sequence, std::forward<KeepFunctor>(keep));
379 future.waitForFinished();
383template <
typename ResultType,
typename Sequence,
typename KeepFunctor,
typename ReduceFunctor>
387 ReduceFunctor &&reduce,
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();
397template <
typename ResultType,
typename Sequence,
typename KeepFunctor,
typename ReduceFunctor>
400 ReduceFunctor &&reduce,
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();
532template <
typename ResultType,
typename Iterator,
typename KeepFunctor,
typename ReduceFunctor>
537 ReduceFunctor &&reduce,
541 QFuture<ResultType> future =
542 filteredReduced<ResultType>(pool, begin, end, std::forward<KeepFunctor>(keep),
543 std::forward<ReduceFunctor>(reduce), options);
544 return future.takeResult();
547template <
typename ResultType,
typename Iterator,
typename KeepFunctor,
typename ReduceFunctor>
551 ReduceFunctor &&reduce,
555 QFuture<ResultType> future =
556 filteredReduced<ResultType>(begin, end, std::forward<KeepFunctor>(keep),
557 std::forward<ReduceFunctor>(reduce), options);
558 return future.takeResult();
642 typename InitialValueType,
681template <
typename Sequence,
typename KeepFunctor>
684 return blockingFilteredReduced<std::decay_t<Sequence>>(
685 pool, std::forward<Sequence>(sequence), std::forward<KeepFunctor>(keep),
686 QtPrivate::PushBackWrapper(), OrderedReduce);
689template <
typename Sequence,
typename KeepFunctor>
692 return blockingFilteredReduced<std::decay_t<Sequence>>(
693 QThreadPool::globalInstance(), std::forward<Sequence>(sequence),
694 std::forward<KeepFunctor>(keep), QtPrivate::PushBackWrapper(), OrderedReduce);
698template <
typename OutputSequence,
typename Iterator,
typename KeepFunctor>
699OutputSequence
blockingFiltered(QThreadPool *pool, Iterator begin, Iterator end, KeepFunctor &&keep)
701 return blockingFilteredReduced<OutputSequence>(pool, begin, end,
702 std::forward<KeepFunctor>(keep),
703 QtPrivate::PushBackWrapper(), OrderedReduce);
706template <
typename OutputSequence,
typename Iterator,
typename KeepFunctor>
709 return blockingFilteredReduced<OutputSequence>(QThreadPool::globalInstance(), begin, end,
710 std::forward<KeepFunctor>(keep),
711 QtPrivate::PushBackWrapper(), OrderedReduce);
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.