diff options
author | Jarek Kobus <jaroslaw.kobus@qt.io> | 2020-04-28 14:19:42 +0200 |
---|---|---|
committer | Jarek Kobus <jaroslaw.kobus@qt.io> | 2020-05-18 10:03:29 +0200 |
commit | 8a11641bb9709b2c6cb5051163eb5086838c8fac (patch) | |
tree | c1a684ba92207c5d05a253c08c499cf4d294573f /src/concurrent/qtconcurrentfilter.h | |
parent | 4857fee0fc6a9b277a779266d521d4dc1ca3bd95 (diff) |
Enable setting custom QThreadPool for QtConcurrent methods
Task-number: QTBUG-53465
Change-Id: Icff05d5f65dce453ff702502b85c35e20fca86a9
Reviewed-by: Sona Kurazyan <sona.kurazyan@qt.io>
Diffstat (limited to 'src/concurrent/qtconcurrentfilter.h')
-rw-r--r-- | src/concurrent/qtconcurrentfilter.h | 476 |
1 files changed, 375 insertions, 101 deletions
diff --git a/src/concurrent/qtconcurrentfilter.h b/src/concurrent/qtconcurrentfilter.h index df4c9ed384..5feedec751 100644 --- a/src/concurrent/qtconcurrentfilter.h +++ b/src/concurrent/qtconcurrentfilter.h @@ -53,286 +53,560 @@ namespace QtConcurrent { //! [QtConcurrent-1] template <typename Sequence, typename KeepFunctor, typename ReduceFunctor> -ThreadEngineStarter<void> filterInternal(Sequence &sequence, KeepFunctor keep, ReduceFunctor reduce) +ThreadEngineStarter<void> filterInternal(QThreadPool *pool, Sequence &sequence, + KeepFunctor keep, ReduceFunctor reduce) { typedef FilterKernel<Sequence, KeepFunctor, ReduceFunctor> KernelType; - return startThreadEngine(new KernelType(sequence, keep, reduce)); + return startThreadEngine(new KernelType(pool, sequence, keep, reduce)); } // filter() on sequences template <typename Sequence, typename KeepFunctor> +QFuture<void> filter(QThreadPool *pool, Sequence &sequence, KeepFunctor keep) +{ + return filterInternal(pool, sequence, keep, QtPrivate::PushBackWrapper()); +} + +template <typename Sequence, typename KeepFunctor> QFuture<void> filter(Sequence &sequence, KeepFunctor keep) { - return filterInternal(sequence, keep, QtPrivate::PushBackWrapper()); + return filterInternal(QThreadPool::globalInstance(), + sequence, keep, QtPrivate::PushBackWrapper()); } // filteredReduced() on sequences template <typename ResultType, typename Sequence, typename KeepFunctor, typename ReduceFunctor> +QFuture<ResultType> filteredReduced(QThreadPool *pool, + const Sequence &sequence, + KeepFunctor keep, + ReduceFunctor reduce, + ReduceOptions options = ReduceOptions(UnorderedReduce + | SequentialReduce)) +{ + return startFilteredReduced<ResultType>(pool, sequence, keep, reduce, options); +} + +template <typename ResultType, typename Sequence, typename KeepFunctor, typename ReduceFunctor> QFuture<ResultType> filteredReduced(const Sequence &sequence, KeepFunctor keep, ReduceFunctor reduce, - ReduceOptions options = ReduceOptions(UnorderedReduce | SequentialReduce)) + ReduceOptions options = ReduceOptions(UnorderedReduce + | SequentialReduce)) { - return startFilteredReduced<ResultType>(sequence, keep, reduce, options); + return startFilteredReduced<ResultType>(QThreadPool::globalInstance(), + sequence, keep, reduce, options); } template <typename ResultType, typename Sequence, typename KeepFunctor, typename ReduceFunctor, typename InitialValueType, std::enable_if_t<std::is_convertible_v<InitialValueType, ResultType>, int> = 0> -QFuture<ResultType> filteredReduced(const Sequence &sequence, KeepFunctor keep, - ReduceFunctor reduce, InitialValueType &&initialValue, +QFuture<ResultType> filteredReduced(QThreadPool *pool, + const Sequence &sequence, + KeepFunctor keep, + ReduceFunctor reduce, + InitialValueType &&initialValue, ReduceOptions options = ReduceOptions(UnorderedReduce | SequentialReduce)) { - return startFilteredReduced<ResultType>( - sequence, keep, - reduce, - ResultType(std::forward<InitialValueType>(initialValue)), options); + return startFilteredReduced<ResultType>(pool, sequence, keep, reduce, + ResultType(std::forward<InitialValueType>(initialValue)), options); +} + +template <typename ResultType, typename Sequence, typename KeepFunctor, typename ReduceFunctor, + typename InitialValueType, + std::enable_if_t<std::is_convertible_v<InitialValueType, ResultType>, int> = 0> +QFuture<ResultType> filteredReduced(const Sequence &sequence, + KeepFunctor keep, + ReduceFunctor reduce, + InitialValueType &&initialValue, + ReduceOptions options = ReduceOptions(UnorderedReduce + | SequentialReduce)) +{ + return startFilteredReduced<ResultType>(QThreadPool::globalInstance(), sequence, keep, reduce, + ResultType(std::forward<InitialValueType>(initialValue)), options); } #ifndef Q_CLANG_QDOC template <typename Sequence, typename KeepFunctor, typename ReduceFunctor> -QFuture<typename QtPrivate::ReduceResultType<ReduceFunctor>::ResultType> filteredReduced(const Sequence &sequence, +QFuture<typename QtPrivate::ReduceResultType<ReduceFunctor>::ResultType> filteredReduced( + QThreadPool *pool, + const Sequence &sequence, KeepFunctor keep, ReduceFunctor reduce, - ReduceOptions options = ReduceOptions(UnorderedReduce | SequentialReduce)) + ReduceOptions options = ReduceOptions(UnorderedReduce + | SequentialReduce)) { return startFilteredReduced<typename QtPrivate::ReduceResultType<ReduceFunctor>::ResultType> - (sequence, - keep, - reduce, - options); + (pool, sequence, keep, reduce, options); +} + +template <typename Sequence, typename KeepFunctor, typename ReduceFunctor> +QFuture<typename QtPrivate::ReduceResultType<ReduceFunctor>::ResultType> filteredReduced( + const Sequence &sequence, + KeepFunctor keep, + ReduceFunctor reduce, + ReduceOptions options = ReduceOptions(UnorderedReduce + | SequentialReduce)) +{ + return startFilteredReduced<typename QtPrivate::ReduceResultType<ReduceFunctor>::ResultType> + (QThreadPool::globalInstance(), sequence, keep, reduce, options); +} + +template <typename Sequence, typename KeepFunctor, typename ReduceFunctor, + typename ResultType = typename QtPrivate::ReduceResultType<ReduceFunctor>::ResultType, + typename InitialValueType, + std::enable_if_t<std::is_convertible_v<InitialValueType, ResultType>, int> = 0> +QFuture<ResultType> filteredReduced(QThreadPool *pool, + const Sequence &sequence, + KeepFunctor keep, + ReduceFunctor reduce, + InitialValueType &&initialValue, + ReduceOptions options = ReduceOptions(UnorderedReduce + | SequentialReduce)) +{ + return startFilteredReduced<ResultType>(pool, sequence, keep, reduce, + ResultType(std::forward<InitialValueType>(initialValue)), options); } template <typename Sequence, typename KeepFunctor, typename ReduceFunctor, typename ResultType = typename QtPrivate::ReduceResultType<ReduceFunctor>::ResultType, typename InitialValueType, std::enable_if_t<std::is_convertible_v<InitialValueType, ResultType>, int> = 0> -QFuture<ResultType> filteredReduced(const Sequence &sequence, KeepFunctor keep, - ReduceFunctor reduce, InitialValueType &&initialValue, +QFuture<ResultType> filteredReduced(const Sequence &sequence, + KeepFunctor keep, + ReduceFunctor reduce, + InitialValueType &&initialValue, ReduceOptions options = ReduceOptions(UnorderedReduce | SequentialReduce)) { - return startFilteredReduced<ResultType>( - sequence, keep, - reduce, - ResultType(std::forward<InitialValueType>(initialValue)), options); + return startFilteredReduced<ResultType>(QThreadPool::globalInstance(), sequence, keep, reduce, + ResultType(std::forward<InitialValueType>(initialValue)), options); } #endif // filteredReduced() on iterators template <typename ResultType, typename Iterator, typename KeepFunctor, typename ReduceFunctor> +QFuture<ResultType> filteredReduced(QThreadPool *pool, + Iterator begin, + Iterator end, + KeepFunctor keep, + ReduceFunctor reduce, + ReduceOptions options = ReduceOptions(UnorderedReduce + | SequentialReduce)) +{ + return startFilteredReduced<ResultType>(pool, begin, end, keep, reduce, options); +} + +template <typename ResultType, typename Iterator, typename KeepFunctor, typename ReduceFunctor> QFuture<ResultType> filteredReduced(Iterator begin, Iterator end, KeepFunctor keep, ReduceFunctor reduce, - ReduceOptions options = ReduceOptions(UnorderedReduce | SequentialReduce)) + ReduceOptions options = ReduceOptions(UnorderedReduce + | SequentialReduce)) { - return startFilteredReduced<ResultType>(begin, end, keep, reduce, options); + return startFilteredReduced<ResultType>(QThreadPool::globalInstance(), begin, end, keep, reduce, + options); } template <typename ResultType, typename Iterator, typename KeepFunctor, typename ReduceFunctor, typename InitialValueType, std::enable_if_t<std::is_convertible_v<InitialValueType, ResultType>, int> = 0> -QFuture<ResultType> filteredReduced(Iterator begin, Iterator end, KeepFunctor keep, - ReduceFunctor reduce, InitialValueType &&initialValue, +QFuture<ResultType> filteredReduced(QThreadPool *pool, + Iterator begin, + Iterator end, + KeepFunctor keep, + ReduceFunctor reduce, + InitialValueType &&initialValue, + ReduceOptions options = ReduceOptions(UnorderedReduce + | SequentialReduce)) +{ + return startFilteredReduced<ResultType>(pool, begin, end, keep, reduce, + ResultType(std::forward<InitialValueType>(initialValue)), options); +} + +template <typename ResultType, typename Iterator, typename KeepFunctor, typename ReduceFunctor, + typename InitialValueType, + std::enable_if_t<std::is_convertible_v<InitialValueType, ResultType>, int> = 0> +QFuture<ResultType> filteredReduced(Iterator begin, + Iterator end, + KeepFunctor keep, + ReduceFunctor reduce, + InitialValueType &&initialValue, ReduceOptions options = ReduceOptions(UnorderedReduce | SequentialReduce)) { - return startFilteredReduced<ResultType>( - begin, end, keep, - reduce, - ResultType(std::forward<InitialValueType>(initialValue)), options); + return startFilteredReduced<ResultType>(QThreadPool::globalInstance(), begin, end, keep, reduce, + ResultType(std::forward<InitialValueType>(initialValue)), options); } #ifndef Q_CLANG_QDOC template <typename Iterator, typename KeepFunctor, typename ReduceFunctor> -QFuture<typename QtPrivate::ReduceResultType<ReduceFunctor>::ResultType> filteredReduced(Iterator begin, +QFuture<typename QtPrivate::ReduceResultType<ReduceFunctor>::ResultType> filteredReduced( + QThreadPool *pool, + Iterator begin, Iterator end, KeepFunctor keep, ReduceFunctor reduce, - ReduceOptions options = ReduceOptions(UnorderedReduce | SequentialReduce)) + ReduceOptions options = ReduceOptions(UnorderedReduce + | SequentialReduce)) { return startFilteredReduced<typename QtPrivate::ReduceResultType<ReduceFunctor>::ResultType> - (begin, end, - keep, - reduce, - options); + (pool, begin, end, keep, reduce, options); +} + +template <typename Iterator, typename KeepFunctor, typename ReduceFunctor> +QFuture<typename QtPrivate::ReduceResultType<ReduceFunctor>::ResultType> filteredReduced( + Iterator begin, + Iterator end, + KeepFunctor keep, + ReduceFunctor reduce, + ReduceOptions options = ReduceOptions(UnorderedReduce + | SequentialReduce)) +{ + return startFilteredReduced<typename QtPrivate::ReduceResultType<ReduceFunctor>::ResultType> + (QThreadPool::globalInstance(), begin, end, keep, reduce, options); +} + +template <typename Iterator, typename KeepFunctor, typename ReduceFunctor, + typename ResultType = typename QtPrivate::ReduceResultType<ReduceFunctor>::ResultType, + typename InitialValueType, + std::enable_if_t<std::is_convertible_v<InitialValueType, ResultType>, int> = 0> +QFuture<ResultType> filteredReduced(QThreadPool *pool, + Iterator begin, + Iterator end, + KeepFunctor keep, + ReduceFunctor reduce, + InitialValueType &&initialValue, + ReduceOptions options = ReduceOptions(UnorderedReduce + | SequentialReduce)) +{ + return startFilteredReduced<ResultType>(pool, begin, end, keep, reduce, + ResultType(std::forward<InitialValueType>(initialValue)), options); } template <typename Iterator, typename KeepFunctor, typename ReduceFunctor, typename ResultType = typename QtPrivate::ReduceResultType<ReduceFunctor>::ResultType, typename InitialValueType, std::enable_if_t<std::is_convertible_v<InitialValueType, ResultType>, int> = 0> -QFuture<ResultType> filteredReduced(Iterator begin, Iterator end, KeepFunctor keep, - ReduceFunctor reduce, InitialValueType &&initialValue, +QFuture<ResultType> filteredReduced(Iterator begin, + Iterator end, + KeepFunctor keep, + ReduceFunctor reduce, + InitialValueType &&initialValue, ReduceOptions options = ReduceOptions(UnorderedReduce | SequentialReduce)) { - return startFilteredReduced<ResultType>( - begin, end, keep, - reduce, - ResultType(std::forward<InitialValueType>(initialValue)), options); + return startFilteredReduced<ResultType>(QThreadPool::globalInstance(), begin, end, keep, reduce, + ResultType(std::forward<InitialValueType>(initialValue)), options); } #endif // filtered() on sequences template <typename Sequence, typename KeepFunctor> +QFuture<typename Sequence::value_type> filtered(QThreadPool *pool, + const Sequence &sequence, + KeepFunctor keep) +{ + return startFiltered(pool, sequence, keep); +} + +template <typename Sequence, typename KeepFunctor> QFuture<typename Sequence::value_type> filtered(const Sequence &sequence, KeepFunctor keep) { - return startFiltered(sequence, keep); + return startFiltered(QThreadPool::globalInstance(), sequence, keep); } // filtered() on iterators template <typename Iterator, typename KeepFunctor> -QFuture<typename qValueType<Iterator>::value_type> filtered(Iterator begin, Iterator end, KeepFunctor keep) +QFuture<typename qValueType<Iterator>::value_type> filtered(QThreadPool *pool, + Iterator begin, + Iterator end, + KeepFunctor keep) +{ + return startFiltered(pool, begin, end, keep); +} + +template <typename Iterator, typename KeepFunctor> +QFuture<typename qValueType<Iterator>::value_type> filtered(Iterator begin, + Iterator end, + KeepFunctor keep) { - return startFiltered(begin, end, keep); + return startFiltered(QThreadPool::globalInstance(), begin, end, keep); } // blocking filter() on sequences template <typename Sequence, typename KeepFunctor> +void blockingFilter(QThreadPool *pool, Sequence &sequence, KeepFunctor keep) +{ + filterInternal(pool, sequence, keep, QtPrivate::PushBackWrapper()).startBlocking(); +} + +template <typename Sequence, typename KeepFunctor> void blockingFilter(Sequence &sequence, KeepFunctor keep) { - filterInternal(sequence, keep, QtPrivate::PushBackWrapper()).startBlocking(); + filterInternal(QThreadPool::globalInstance(), sequence, keep, QtPrivate::PushBackWrapper()) + .startBlocking(); } // blocking filteredReduced() on sequences template <typename ResultType, typename Sequence, typename KeepFunctor, typename ReduceFunctor> -ResultType blockingFilteredReduced(const Sequence &sequence, +ResultType blockingFilteredReduced(QThreadPool *pool, + const Sequence &sequence, KeepFunctor keep, ReduceFunctor reduce, - ReduceOptions options = ReduceOptions(UnorderedReduce | SequentialReduce)) + ReduceOptions options = ReduceOptions(UnorderedReduce + | SequentialReduce)) { - return startFilteredReduced<ResultType>(sequence, keep, reduce, options) + return startFilteredReduced<ResultType>(pool, sequence, keep, reduce, options) .startBlocking(); } +template <typename ResultType, typename Sequence, typename KeepFunctor, typename ReduceFunctor> +ResultType blockingFilteredReduced(const Sequence &sequence, + KeepFunctor keep, + ReduceFunctor reduce, + ReduceOptions options = ReduceOptions(UnorderedReduce + | SequentialReduce)) +{ + return startFilteredReduced<ResultType>(QThreadPool::globalInstance(), + sequence, keep, reduce, options).startBlocking(); +} + template <typename ResultType, typename Sequence, typename KeepFunctor, typename ReduceFunctor, typename InitialValueType, std::enable_if_t<std::is_convertible_v<InitialValueType, ResultType>, int> = 0> -ResultType blockingFilteredReduced(const Sequence &sequence, KeepFunctor keep, ReduceFunctor reduce, +ResultType blockingFilteredReduced(QThreadPool *pool, + const Sequence &sequence, + KeepFunctor keep, + ReduceFunctor reduce, InitialValueType &&initialValue, ReduceOptions options = ReduceOptions(UnorderedReduce | SequentialReduce)) { - return startFilteredReduced<ResultType>( - sequence, keep, - reduce, - ResultType(std::forward<InitialValueType>(initialValue)), options) - .startBlocking(); + return startFilteredReduced<ResultType>(pool, sequence, keep, reduce, + ResultType(std::forward<InitialValueType>(initialValue)), options).startBlocking(); +} + +template <typename ResultType, typename Sequence, typename KeepFunctor, typename ReduceFunctor, + typename InitialValueType, + std::enable_if_t<std::is_convertible_v<InitialValueType, ResultType>, int> = 0> +ResultType blockingFilteredReduced(const Sequence &sequence, + KeepFunctor keep, + ReduceFunctor reduce, + InitialValueType &&initialValue, + ReduceOptions options = ReduceOptions(UnorderedReduce + | SequentialReduce)) +{ + return startFilteredReduced<ResultType>(QThreadPool::globalInstance(), sequence, keep, reduce, + ResultType(std::forward<InitialValueType>(initialValue)), options).startBlocking(); } #ifndef Q_CLANG_QDOC template <typename Sequence, typename KeepFunctor, typename ReduceFunctor> -typename QtPrivate::ReduceResultType<ReduceFunctor>::ResultType blockingFilteredReduced(const Sequence &sequence, +typename QtPrivate::ReduceResultType<ReduceFunctor>::ResultType blockingFilteredReduced( + QThreadPool *pool, + const Sequence &sequence, KeepFunctor keep, ReduceFunctor reduce, - ReduceOptions options = ReduceOptions(UnorderedReduce | SequentialReduce)) + ReduceOptions options = ReduceOptions(UnorderedReduce + | SequentialReduce)) { return startFilteredReduced<typename QtPrivate::ReduceResultType<ReduceFunctor>::ResultType> - (sequence, - keep, - reduce, - options).startBlocking(); + (pool, sequence, keep, reduce, options).startBlocking(); +} + +template <typename Sequence, typename KeepFunctor, typename ReduceFunctor> +typename QtPrivate::ReduceResultType<ReduceFunctor>::ResultType blockingFilteredReduced( + const Sequence &sequence, + KeepFunctor keep, + ReduceFunctor reduce, + ReduceOptions options = ReduceOptions(UnorderedReduce + | SequentialReduce)) +{ + return startFilteredReduced<typename QtPrivate::ReduceResultType<ReduceFunctor>::ResultType> + (QThreadPool::globalInstance(), sequence, keep, reduce, options).startBlocking(); } template <typename Sequence, typename KeepFunctor, typename ReduceFunctor, typename ResultType = typename QtPrivate::ReduceResultType<ReduceFunctor>::ResultType, typename InitialValueType, std::enable_if_t<std::is_convertible_v<InitialValueType, ResultType>, int> = 0> -ResultType blockingFilteredReduced(const Sequence &sequence, KeepFunctor keep, ReduceFunctor reduce, +ResultType blockingFilteredReduced(QThreadPool *pool, + const Sequence &sequence, + KeepFunctor keep, + ReduceFunctor reduce, InitialValueType &&initialValue, ReduceOptions options = ReduceOptions(UnorderedReduce | SequentialReduce)) { - return startFilteredReduced<ResultType>( - sequence, keep, - reduce, - ResultType(std::forward<InitialValueType>(initialValue)), options) - .startBlocking(); + return startFilteredReduced<ResultType>(pool, sequence, keep, reduce, + ResultType(std::forward<InitialValueType>(initialValue)), options).startBlocking(); +} + +template <typename Sequence, typename KeepFunctor, typename ReduceFunctor, + typename ResultType = typename QtPrivate::ReduceResultType<ReduceFunctor>::ResultType, + typename InitialValueType, + std::enable_if_t<std::is_convertible_v<InitialValueType, ResultType>, int> = 0> +ResultType blockingFilteredReduced(const Sequence &sequence, + KeepFunctor keep, + ReduceFunctor reduce, + InitialValueType &&initialValue, + ReduceOptions options = ReduceOptions(UnorderedReduce + | SequentialReduce)) +{ + return startFilteredReduced<ResultType>(QThreadPool::globalInstance(), sequence, keep, reduce, + ResultType(std::forward<InitialValueType>(initialValue)), options).startBlocking(); } #endif // blocking filteredReduced() on iterators template <typename ResultType, typename Iterator, typename KeepFunctor, typename ReduceFunctor> -ResultType blockingFilteredReduced(Iterator begin, +ResultType blockingFilteredReduced(QThreadPool *pool, + Iterator begin, Iterator end, KeepFunctor keep, ReduceFunctor reduce, - ReduceOptions options = ReduceOptions(UnorderedReduce | SequentialReduce)) + ReduceOptions options = ReduceOptions(UnorderedReduce + | SequentialReduce)) { - return startFilteredReduced<ResultType> - (begin, end, - keep, - reduce, - options) + return startFilteredReduced<ResultType>(pool, begin, end, keep, reduce, options) .startBlocking(); } +template <typename ResultType, typename Iterator, typename KeepFunctor, typename ReduceFunctor> +ResultType blockingFilteredReduced(Iterator begin, + Iterator end, + KeepFunctor keep, + ReduceFunctor reduce, + ReduceOptions options = ReduceOptions(UnorderedReduce + | SequentialReduce)) +{ + return startFilteredReduced<ResultType>(QThreadPool::globalInstance(), begin, end, keep, + reduce, options).startBlocking(); +} + + +template <typename ResultType, typename Iterator, typename KeepFunctor, typename ReduceFunctor, + typename InitialValueType, + std::enable_if_t<std::is_convertible_v<InitialValueType, ResultType>, int> = 0> +ResultType blockingFilteredReduced(QThreadPool *pool, + Iterator begin, + Iterator end, + KeepFunctor keep, + ReduceFunctor reduce, + InitialValueType &&initialValue, + ReduceOptions options = ReduceOptions(UnorderedReduce + | SequentialReduce)) +{ + return startFilteredReduced<ResultType>(pool, begin, end, keep, reduce, + ResultType(std::forward<InitialValueType>(initialValue)), options).startBlocking(); +} + template <typename ResultType, typename Iterator, typename KeepFunctor, typename ReduceFunctor, typename InitialValueType, std::enable_if_t<std::is_convertible_v<InitialValueType, ResultType>, int> = 0> -ResultType blockingFilteredReduced(Iterator begin, Iterator end, KeepFunctor keep, - ReduceFunctor reduce, InitialValueType &&initialValue, +ResultType blockingFilteredReduced(Iterator begin, + Iterator end, + KeepFunctor keep, + ReduceFunctor reduce, + InitialValueType &&initialValue, ReduceOptions options = ReduceOptions(UnorderedReduce | SequentialReduce)) { - return startFilteredReduced<ResultType>( - begin, end, keep, - reduce, - ResultType(std::forward<InitialValueType>(initialValue)), options) - .startBlocking(); + return startFilteredReduced<ResultType>(QThreadPool::globalInstance(), begin, end, keep, reduce, + ResultType(std::forward<InitialValueType>(initialValue)), options).startBlocking(); } #ifndef Q_CLANG_QDOC template <typename Iterator, typename KeepFunctor, typename ReduceFunctor> -typename QtPrivate::ReduceResultType<ReduceFunctor>::ResultType blockingFilteredReduced(Iterator begin, +typename QtPrivate::ReduceResultType<ReduceFunctor>::ResultType blockingFilteredReduced( + QThreadPool *pool, + Iterator begin, Iterator end, KeepFunctor keep, ReduceFunctor reduce, - ReduceOptions options = ReduceOptions(UnorderedReduce | SequentialReduce)) + ReduceOptions options = ReduceOptions(UnorderedReduce + | SequentialReduce)) { return startFilteredReduced<typename QtPrivate::ReduceResultType<ReduceFunctor>::ResultType> - (begin, end, - keep, - reduce, - options) - .startBlocking(); + (pool, begin, end, keep, reduce, options).startBlocking(); +} + +template <typename Iterator, typename KeepFunctor, typename ReduceFunctor> +typename QtPrivate::ReduceResultType<ReduceFunctor>::ResultType blockingFilteredReduced( + Iterator begin, + Iterator end, + KeepFunctor keep, + ReduceFunctor reduce, + ReduceOptions options = ReduceOptions(UnorderedReduce + | SequentialReduce)) +{ + return startFilteredReduced<typename QtPrivate::ReduceResultType<ReduceFunctor>::ResultType> + (QThreadPool::globalInstance(), begin, end, keep, reduce, options).startBlocking(); +} + +template <typename Iterator, typename KeepFunctor, typename ReduceFunctor, + typename ResultType = typename QtPrivate::ReduceResultType<ReduceFunctor>::ResultType, + typename InitialValueType, + std::enable_if_t<std::is_convertible_v<InitialValueType, ResultType>, int> = 0> +ResultType blockingFilteredReduced(QThreadPool *pool, + Iterator begin, + Iterator end, KeepFunctor keep, + ReduceFunctor reduce, + InitialValueType &&initialValue, + ReduceOptions options = ReduceOptions(UnorderedReduce + | SequentialReduce)) +{ + return startFilteredReduced<ResultType>(pool, begin, end, keep, reduce, + ResultType(std::forward<InitialValueType>(initialValue)), options).startBlocking(); } template <typename Iterator, typename KeepFunctor, typename ReduceFunctor, typename ResultType = typename QtPrivate::ReduceResultType<ReduceFunctor>::ResultType, typename InitialValueType, std::enable_if_t<std::is_convertible_v<InitialValueType, ResultType>, int> = 0> -ResultType blockingFilteredReduced(Iterator begin, Iterator end, KeepFunctor keep, - ReduceFunctor reduce, InitialValueType &&initialValue, +ResultType blockingFilteredReduced(Iterator begin, + Iterator end, + KeepFunctor keep, + ReduceFunctor reduce, + InitialValueType &&initialValue, ReduceOptions options = ReduceOptions(UnorderedReduce | SequentialReduce)) { - return startFilteredReduced<ResultType>( - begin, end, keep, - reduce, - ResultType(std::forward<InitialValueType>(initialValue)), options) - .startBlocking(); + return startFilteredReduced<ResultType>(QThreadPool::globalInstance(), begin, end, keep, reduce, + ResultType(std::forward<InitialValueType>(initialValue)), options).startBlocking(); } #endif // blocking filtered() on sequences template <typename Sequence, typename KeepFunctor> +Sequence blockingFiltered(QThreadPool *pool, const Sequence &sequence, KeepFunctor keep) +{ + return startFilteredReduced<Sequence>(pool, sequence, keep, QtPrivate::PushBackWrapper(), + OrderedReduce).startBlocking(); +} + +template <typename Sequence, typename KeepFunctor> Sequence blockingFiltered(const Sequence &sequence, KeepFunctor keep) { - return startFilteredReduced<Sequence>(sequence, keep, QtPrivate::PushBackWrapper(), OrderedReduce).startBlocking(); + return startFilteredReduced<Sequence>(QThreadPool::globalInstance(), sequence, keep, + QtPrivate::PushBackWrapper(), OrderedReduce).startBlocking(); } // blocking filtered() on iterators template <typename OutputSequence, typename Iterator, typename KeepFunctor> +OutputSequence blockingFiltered(QThreadPool *pool, Iterator begin, Iterator end, KeepFunctor keep) +{ + return startFilteredReduced<OutputSequence>(pool, begin, end, keep, + QtPrivate::PushBackWrapper(), OrderedReduce).startBlocking(); +} + +template <typename OutputSequence, typename Iterator, typename KeepFunctor> OutputSequence blockingFiltered(Iterator begin, Iterator end, KeepFunctor keep) { - return startFilteredReduced<OutputSequence>(begin, end, - keep, - QtPrivate::PushBackWrapper(), - OrderedReduce).startBlocking(); + return startFilteredReduced<OutputSequence>(QThreadPool::globalInstance(), begin, end, keep, + QtPrivate::PushBackWrapper(), OrderedReduce).startBlocking(); } } // namespace QtConcurrent |