Reuse the non blocking implementation for blocking one

Replace the implementation of blockingMappedReduced():
after calling non-blocking version of mappedReduced() we are getting
the future object, so we may call in sequence result(), which
will block and return the result when the all tasks are done.

The same is done with blockigMapped(), which calls blockingMappedReduced()
with a custom reduce function.

Looks like with this pattern we can reuse the non-blocking version
for implementing blocking version of mapped / filtered methods.

Task-number: QTBUG-83918
Change-Id: I7f240cfbd04834d551ff79d717b72194a26996d7
Reviewed-by: Sona Kurazyan <sona.kurazyan@qt.io>
This commit is contained in:
Jarek Kobus 2020-05-14 18:46:15 +02:00
parent c49728eb27
commit 79fd1cb2c6
4 changed files with 248 additions and 252 deletions

View File

@ -127,29 +127,28 @@ QFuture<ResultType> filteredReduced(const Sequence &sequence,
} }
#ifndef Q_CLANG_QDOC #ifndef Q_CLANG_QDOC
template <typename Sequence, typename KeepFunctor, typename ReduceFunctor> template <typename Sequence, typename KeepFunctor, typename ReduceFunctor,
QFuture<typename QtPrivate::ReduceResultType<ReduceFunctor>::ResultType> filteredReduced( typename ResultType = typename QtPrivate::ReduceResultType<ReduceFunctor>::ResultType>
QThreadPool *pool, QFuture<ResultType> filteredReduced(QThreadPool *pool,
const Sequence &sequence, const Sequence &sequence,
KeepFunctor keep, KeepFunctor keep,
ReduceFunctor reduce, ReduceFunctor reduce,
ReduceOptions options = ReduceOptions(UnorderedReduce ReduceOptions options = ReduceOptions(UnorderedReduce
| SequentialReduce)) | SequentialReduce))
{ {
return startFilteredReduced<typename QtPrivate::ReduceResultType<ReduceFunctor>::ResultType> return startFilteredReduced<ResultType>(pool, sequence, keep, reduce, options);
(pool, sequence, keep, reduce, options);
} }
template <typename Sequence, typename KeepFunctor, typename ReduceFunctor> template <typename Sequence, typename KeepFunctor, typename ReduceFunctor,
QFuture<typename QtPrivate::ReduceResultType<ReduceFunctor>::ResultType> filteredReduced( typename ResultType = typename QtPrivate::ReduceResultType<ReduceFunctor>::ResultType>
const Sequence &sequence, QFuture<ResultType> filteredReduced(const Sequence &sequence,
KeepFunctor keep, KeepFunctor keep,
ReduceFunctor reduce, ReduceFunctor reduce,
ReduceOptions options = ReduceOptions(UnorderedReduce ReduceOptions options = ReduceOptions(UnorderedReduce
| SequentialReduce)) | SequentialReduce))
{ {
return startFilteredReduced<typename QtPrivate::ReduceResultType<ReduceFunctor>::ResultType> return startFilteredReduced<ResultType>(QThreadPool::globalInstance(),
(QThreadPool::globalInstance(), sequence, keep, reduce, options); sequence, keep, reduce, options);
} }
template <typename Sequence, typename KeepFunctor, typename ReduceFunctor, template <typename Sequence, typename KeepFunctor, typename ReduceFunctor,
@ -241,9 +240,9 @@ QFuture<ResultType> filteredReduced(Iterator begin,
} }
#ifndef Q_CLANG_QDOC #ifndef Q_CLANG_QDOC
template <typename Iterator, typename KeepFunctor, typename ReduceFunctor> template <typename Iterator, typename KeepFunctor, typename ReduceFunctor,
QFuture<typename QtPrivate::ReduceResultType<ReduceFunctor>::ResultType> filteredReduced( typename ResultType = typename QtPrivate::ReduceResultType<ReduceFunctor>::ResultType>
QThreadPool *pool, QFuture<ResultType> filteredReduced(QThreadPool *pool,
Iterator begin, Iterator begin,
Iterator end, Iterator end,
KeepFunctor keep, KeepFunctor keep,
@ -251,21 +250,20 @@ QFuture<typename QtPrivate::ReduceResultType<ReduceFunctor>::ResultType> filtere
ReduceOptions options = ReduceOptions(UnorderedReduce ReduceOptions options = ReduceOptions(UnorderedReduce
| SequentialReduce)) | SequentialReduce))
{ {
return startFilteredReduced<typename QtPrivate::ReduceResultType<ReduceFunctor>::ResultType> return startFilteredReduced<ResultType>(pool, begin, end, keep, reduce, options);
(pool, begin, end, keep, reduce, options);
} }
template <typename Iterator, typename KeepFunctor, typename ReduceFunctor> template <typename Iterator, typename KeepFunctor, typename ReduceFunctor,
QFuture<typename QtPrivate::ReduceResultType<ReduceFunctor>::ResultType> filteredReduced( typename ResultType = typename QtPrivate::ReduceResultType<ReduceFunctor>::ResultType>
Iterator begin, QFuture<ResultType> filteredReduced(Iterator begin,
Iterator end, Iterator end,
KeepFunctor keep, KeepFunctor keep,
ReduceFunctor reduce, ReduceFunctor reduce,
ReduceOptions options = ReduceOptions(UnorderedReduce ReduceOptions options = ReduceOptions(UnorderedReduce
| SequentialReduce)) | SequentialReduce))
{ {
return startFilteredReduced<typename QtPrivate::ReduceResultType<ReduceFunctor>::ResultType> return startFilteredReduced<ResultType>(QThreadPool::globalInstance(),
(QThreadPool::globalInstance(), begin, end, keep, reduce, options); begin, end, keep, reduce, options);
} }
template <typename Iterator, typename KeepFunctor, typename ReduceFunctor, template <typename Iterator, typename KeepFunctor, typename ReduceFunctor,
@ -339,14 +337,16 @@ QFuture<typename qValueType<Iterator>::value_type> filtered(Iterator begin,
template <typename Sequence, typename KeepFunctor> template <typename Sequence, typename KeepFunctor>
void blockingFilter(QThreadPool *pool, Sequence &sequence, KeepFunctor keep) void blockingFilter(QThreadPool *pool, Sequence &sequence, KeepFunctor keep)
{ {
filterInternal(pool, sequence, keep, QtPrivate::PushBackWrapper()).startBlocking(); QFuture<void> future = filterInternal(pool, sequence, keep, QtPrivate::PushBackWrapper());
future.waitForFinished();
} }
template <typename Sequence, typename KeepFunctor> template <typename Sequence, typename KeepFunctor>
void blockingFilter(Sequence &sequence, KeepFunctor keep) void blockingFilter(Sequence &sequence, KeepFunctor keep)
{ {
filterInternal(QThreadPool::globalInstance(), sequence, keep, QtPrivate::PushBackWrapper()) QFuture<void> future = filterInternal(QThreadPool::globalInstance(), sequence, keep,
.startBlocking(); QtPrivate::PushBackWrapper());
future.waitForFinished();
} }
// blocking filteredReduced() on sequences // blocking filteredReduced() on sequences
@ -358,8 +358,9 @@ ResultType blockingFilteredReduced(QThreadPool *pool,
ReduceOptions options = ReduceOptions(UnorderedReduce ReduceOptions options = ReduceOptions(UnorderedReduce
| SequentialReduce)) | SequentialReduce))
{ {
return startFilteredReduced<ResultType>(pool, sequence, keep, reduce, options) QFuture<ResultType> future = startFilteredReduced<ResultType>(pool, sequence, keep,
.startBlocking(); reduce, options);
return future.result();
} }
template <typename ResultType, typename Sequence, typename KeepFunctor, typename ReduceFunctor> template <typename ResultType, typename Sequence, typename KeepFunctor, typename ReduceFunctor>
@ -369,8 +370,9 @@ ResultType blockingFilteredReduced(const Sequence &sequence,
ReduceOptions options = ReduceOptions(UnorderedReduce ReduceOptions options = ReduceOptions(UnorderedReduce
| SequentialReduce)) | SequentialReduce))
{ {
return startFilteredReduced<ResultType>(QThreadPool::globalInstance(), QFuture<ResultType> future = startFilteredReduced<ResultType>(QThreadPool::globalInstance(),
sequence, keep, reduce, options).startBlocking(); sequence, keep, reduce, options);
return future.result();
} }
template <typename ResultType, typename Sequence, typename KeepFunctor, typename ReduceFunctor, template <typename ResultType, typename Sequence, typename KeepFunctor, typename ReduceFunctor,
@ -384,8 +386,9 @@ ResultType blockingFilteredReduced(QThreadPool *pool,
ReduceOptions options = ReduceOptions(UnorderedReduce ReduceOptions options = ReduceOptions(UnorderedReduce
| SequentialReduce)) | SequentialReduce))
{ {
return startFilteredReduced<ResultType>(pool, sequence, keep, reduce, QFuture<ResultType> future = startFilteredReduced<ResultType>(pool, sequence, keep, reduce,
ResultType(std::forward<InitialValueType>(initialValue)), options).startBlocking(); ResultType(std::forward<InitialValueType>(initialValue)), options);
return future.result();
} }
template <typename ResultType, typename Sequence, typename KeepFunctor, typename ReduceFunctor, template <typename ResultType, typename Sequence, typename KeepFunctor, typename ReduceFunctor,
@ -398,34 +401,37 @@ ResultType blockingFilteredReduced(const Sequence &sequence,
ReduceOptions options = ReduceOptions(UnorderedReduce ReduceOptions options = ReduceOptions(UnorderedReduce
| SequentialReduce)) | SequentialReduce))
{ {
return startFilteredReduced<ResultType>(QThreadPool::globalInstance(), sequence, keep, reduce, QFuture<ResultType> future = startFilteredReduced<ResultType>(QThreadPool::globalInstance(),
ResultType(std::forward<InitialValueType>(initialValue)), options).startBlocking(); sequence, keep, reduce, ResultType(std::forward<InitialValueType>(initialValue)), options);
return future.result();
} }
#ifndef Q_CLANG_QDOC #ifndef Q_CLANG_QDOC
template <typename Sequence, typename KeepFunctor, typename ReduceFunctor> template <typename Sequence, typename KeepFunctor, typename ReduceFunctor,
typename QtPrivate::ReduceResultType<ReduceFunctor>::ResultType blockingFilteredReduced( typename ResultType = typename QtPrivate::ReduceResultType<ReduceFunctor>::ResultType>
QThreadPool *pool, ResultType blockingFilteredReduced(QThreadPool *pool,
const Sequence &sequence, const Sequence &sequence,
KeepFunctor keep, KeepFunctor keep,
ReduceFunctor reduce, ReduceFunctor reduce,
ReduceOptions options = ReduceOptions(UnorderedReduce ReduceOptions options = ReduceOptions(UnorderedReduce
| SequentialReduce)) | SequentialReduce))
{ {
return startFilteredReduced<typename QtPrivate::ReduceResultType<ReduceFunctor>::ResultType> QFuture<ResultType> future = startFilteredReduced<ResultType>(pool, sequence, keep,
(pool, sequence, keep, reduce, options).startBlocking(); reduce, options);
return future.result();
} }
template <typename Sequence, typename KeepFunctor, typename ReduceFunctor> template <typename Sequence, typename KeepFunctor, typename ReduceFunctor,
typename QtPrivate::ReduceResultType<ReduceFunctor>::ResultType blockingFilteredReduced( typename ResultType = typename QtPrivate::ReduceResultType<ReduceFunctor>::ResultType>
const Sequence &sequence, ResultType blockingFilteredReduced(const Sequence &sequence,
KeepFunctor keep, KeepFunctor keep,
ReduceFunctor reduce, ReduceFunctor reduce,
ReduceOptions options = ReduceOptions(UnorderedReduce ReduceOptions options = ReduceOptions(UnorderedReduce
| SequentialReduce)) | SequentialReduce))
{ {
return startFilteredReduced<typename QtPrivate::ReduceResultType<ReduceFunctor>::ResultType> QFuture<ResultType> future = startFilteredReduced<ResultType>(QThreadPool::globalInstance(),
(QThreadPool::globalInstance(), sequence, keep, reduce, options).startBlocking(); sequence, keep, reduce, options);
return future.result();
} }
template <typename Sequence, typename KeepFunctor, typename ReduceFunctor, template <typename Sequence, typename KeepFunctor, typename ReduceFunctor,
@ -440,8 +446,9 @@ ResultType blockingFilteredReduced(QThreadPool *pool,
ReduceOptions options = ReduceOptions(UnorderedReduce ReduceOptions options = ReduceOptions(UnorderedReduce
| SequentialReduce)) | SequentialReduce))
{ {
return startFilteredReduced<ResultType>(pool, sequence, keep, reduce, QFuture<ResultType> future = startFilteredReduced<ResultType>(pool, sequence, keep, reduce,
ResultType(std::forward<InitialValueType>(initialValue)), options).startBlocking(); ResultType(std::forward<InitialValueType>(initialValue)), options);
return future.result();
} }
template <typename Sequence, typename KeepFunctor, typename ReduceFunctor, template <typename Sequence, typename KeepFunctor, typename ReduceFunctor,
@ -455,8 +462,9 @@ ResultType blockingFilteredReduced(const Sequence &sequence,
ReduceOptions options = ReduceOptions(UnorderedReduce ReduceOptions options = ReduceOptions(UnorderedReduce
| SequentialReduce)) | SequentialReduce))
{ {
return startFilteredReduced<ResultType>(QThreadPool::globalInstance(), sequence, keep, reduce, QFuture<ResultType> future = startFilteredReduced<ResultType>(QThreadPool::globalInstance(),
ResultType(std::forward<InitialValueType>(initialValue)), options).startBlocking(); sequence, keep, reduce, ResultType(std::forward<InitialValueType>(initialValue)), options);
return future.result();
} }
#endif #endif
@ -470,8 +478,9 @@ ResultType blockingFilteredReduced(QThreadPool *pool,
ReduceOptions options = ReduceOptions(UnorderedReduce ReduceOptions options = ReduceOptions(UnorderedReduce
| SequentialReduce)) | SequentialReduce))
{ {
return startFilteredReduced<ResultType>(pool, begin, end, keep, reduce, options) QFuture<ResultType> future = startFilteredReduced<ResultType>(pool, begin, end, keep,
.startBlocking(); reduce, options);
return future.result();
} }
template <typename ResultType, typename Iterator, typename KeepFunctor, typename ReduceFunctor> template <typename ResultType, typename Iterator, typename KeepFunctor, typename ReduceFunctor>
@ -482,11 +491,11 @@ ResultType blockingFilteredReduced(Iterator begin,
ReduceOptions options = ReduceOptions(UnorderedReduce ReduceOptions options = ReduceOptions(UnorderedReduce
| SequentialReduce)) | SequentialReduce))
{ {
return startFilteredReduced<ResultType>(QThreadPool::globalInstance(), begin, end, keep, QFuture<ResultType> future = startFilteredReduced<ResultType>(QThreadPool::globalInstance(),
reduce, options).startBlocking(); begin, end, keep, reduce, options);
return future.result();
} }
template <typename ResultType, typename Iterator, typename KeepFunctor, typename ReduceFunctor, template <typename ResultType, typename Iterator, typename KeepFunctor, typename ReduceFunctor,
typename InitialValueType, typename InitialValueType,
std::enable_if_t<std::is_convertible_v<InitialValueType, ResultType>, int> = 0> std::enable_if_t<std::is_convertible_v<InitialValueType, ResultType>, int> = 0>
@ -499,8 +508,9 @@ ResultType blockingFilteredReduced(QThreadPool *pool,
ReduceOptions options = ReduceOptions(UnorderedReduce ReduceOptions options = ReduceOptions(UnorderedReduce
| SequentialReduce)) | SequentialReduce))
{ {
return startFilteredReduced<ResultType>(pool, begin, end, keep, reduce, QFuture<ResultType> future = startFilteredReduced<ResultType>(pool, begin, end, keep, reduce,
ResultType(std::forward<InitialValueType>(initialValue)), options).startBlocking(); ResultType(std::forward<InitialValueType>(initialValue)), options);
return future.result();
} }
template <typename ResultType, typename Iterator, typename KeepFunctor, typename ReduceFunctor, template <typename ResultType, typename Iterator, typename KeepFunctor, typename ReduceFunctor,
@ -514,14 +524,15 @@ ResultType blockingFilteredReduced(Iterator begin,
ReduceOptions options = ReduceOptions(UnorderedReduce ReduceOptions options = ReduceOptions(UnorderedReduce
| SequentialReduce)) | SequentialReduce))
{ {
return startFilteredReduced<ResultType>(QThreadPool::globalInstance(), begin, end, keep, reduce, QFuture<ResultType> future = startFilteredReduced<ResultType>(QThreadPool::globalInstance(),
ResultType(std::forward<InitialValueType>(initialValue)), options).startBlocking(); begin, end, keep, reduce, ResultType(std::forward<InitialValueType>(initialValue)), options);
return future.result();
} }
#ifndef Q_CLANG_QDOC #ifndef Q_CLANG_QDOC
template <typename Iterator, typename KeepFunctor, typename ReduceFunctor> template <typename Iterator, typename KeepFunctor, typename ReduceFunctor,
typename QtPrivate::ReduceResultType<ReduceFunctor>::ResultType blockingFilteredReduced( typename ResultType = typename QtPrivate::ReduceResultType<ReduceFunctor>::ResultType>
QThreadPool *pool, ResultType blockingFilteredReduced(QThreadPool *pool,
Iterator begin, Iterator begin,
Iterator end, Iterator end,
KeepFunctor keep, KeepFunctor keep,
@ -529,21 +540,23 @@ typename QtPrivate::ReduceResultType<ReduceFunctor>::ResultType blockingFiltered
ReduceOptions options = ReduceOptions(UnorderedReduce ReduceOptions options = ReduceOptions(UnorderedReduce
| SequentialReduce)) | SequentialReduce))
{ {
return startFilteredReduced<typename QtPrivate::ReduceResultType<ReduceFunctor>::ResultType> QFuture<ResultType> future = startFilteredReduced<ResultType>(pool, begin, end, keep,
(pool, begin, end, keep, reduce, options).startBlocking(); reduce, options);
return future.result();
} }
template <typename Iterator, typename KeepFunctor, typename ReduceFunctor> template <typename Iterator, typename KeepFunctor, typename ReduceFunctor,
typename QtPrivate::ReduceResultType<ReduceFunctor>::ResultType blockingFilteredReduced( typename ResultType = typename QtPrivate::ReduceResultType<ReduceFunctor>::ResultType>
Iterator begin, ResultType blockingFilteredReduced(Iterator begin,
Iterator end, Iterator end,
KeepFunctor keep, KeepFunctor keep,
ReduceFunctor reduce, ReduceFunctor reduce,
ReduceOptions options = ReduceOptions(UnorderedReduce ReduceOptions options = ReduceOptions(UnorderedReduce
| SequentialReduce)) | SequentialReduce))
{ {
return startFilteredReduced<typename QtPrivate::ReduceResultType<ReduceFunctor>::ResultType> QFuture<ResultType> future = startFilteredReduced<ResultType>(QThreadPool::globalInstance(),
(QThreadPool::globalInstance(), begin, end, keep, reduce, options).startBlocking(); begin, end, keep, reduce, options);
return future.result();
} }
template <typename Iterator, typename KeepFunctor, typename ReduceFunctor, template <typename Iterator, typename KeepFunctor, typename ReduceFunctor,
@ -558,8 +571,9 @@ ResultType blockingFilteredReduced(QThreadPool *pool,
ReduceOptions options = ReduceOptions(UnorderedReduce ReduceOptions options = ReduceOptions(UnorderedReduce
| SequentialReduce)) | SequentialReduce))
{ {
return startFilteredReduced<ResultType>(pool, begin, end, keep, reduce, QFuture<ResultType> future = startFilteredReduced<ResultType>(pool, begin, end, keep, reduce,
ResultType(std::forward<InitialValueType>(initialValue)), options).startBlocking(); ResultType(std::forward<InitialValueType>(initialValue)), options);
return future.result();
} }
template <typename Iterator, typename KeepFunctor, typename ReduceFunctor, template <typename Iterator, typename KeepFunctor, typename ReduceFunctor,
@ -574,8 +588,9 @@ ResultType blockingFilteredReduced(Iterator begin,
ReduceOptions options = ReduceOptions(UnorderedReduce ReduceOptions options = ReduceOptions(UnorderedReduce
| SequentialReduce)) | SequentialReduce))
{ {
return startFilteredReduced<ResultType>(QThreadPool::globalInstance(), begin, end, keep, reduce, QFuture<ResultType> future = startFilteredReduced<ResultType>(QThreadPool::globalInstance(),
ResultType(std::forward<InitialValueType>(initialValue)), options).startBlocking(); begin, end, keep, reduce, ResultType(std::forward<InitialValueType>(initialValue)), options);
return future.result();
} }
#endif #endif
@ -583,30 +598,30 @@ ResultType blockingFilteredReduced(Iterator begin,
template <typename Sequence, typename KeepFunctor> template <typename Sequence, typename KeepFunctor>
Sequence blockingFiltered(QThreadPool *pool, const Sequence &sequence, KeepFunctor keep) Sequence blockingFiltered(QThreadPool *pool, const Sequence &sequence, KeepFunctor keep)
{ {
return startFilteredReduced<Sequence>(pool, sequence, keep, QtPrivate::PushBackWrapper(), return blockingFilteredReduced<Sequence>(pool, sequence, keep, QtPrivate::PushBackWrapper(),
OrderedReduce).startBlocking(); OrderedReduce);
} }
template <typename Sequence, typename KeepFunctor> template <typename Sequence, typename KeepFunctor>
Sequence blockingFiltered(const Sequence &sequence, KeepFunctor keep) Sequence blockingFiltered(const Sequence &sequence, KeepFunctor keep)
{ {
return startFilteredReduced<Sequence>(QThreadPool::globalInstance(), sequence, keep, return blockingFilteredReduced<Sequence>(QThreadPool::globalInstance(), sequence, keep,
QtPrivate::PushBackWrapper(), OrderedReduce).startBlocking(); QtPrivate::PushBackWrapper(), OrderedReduce);
} }
// blocking filtered() on iterators // blocking filtered() on iterators
template <typename OutputSequence, typename Iterator, typename KeepFunctor> template <typename OutputSequence, typename Iterator, typename KeepFunctor>
OutputSequence blockingFiltered(QThreadPool *pool, Iterator begin, Iterator end, KeepFunctor keep) OutputSequence blockingFiltered(QThreadPool *pool, Iterator begin, Iterator end, KeepFunctor keep)
{ {
return startFilteredReduced<OutputSequence>(pool, begin, end, keep, return blockingFilteredReduced<OutputSequence>(pool, begin, end, keep,
QtPrivate::PushBackWrapper(), OrderedReduce).startBlocking(); QtPrivate::PushBackWrapper(), OrderedReduce);
} }
template <typename OutputSequence, typename Iterator, typename KeepFunctor> template <typename OutputSequence, typename Iterator, typename KeepFunctor>
OutputSequence blockingFiltered(Iterator begin, Iterator end, KeepFunctor keep) OutputSequence blockingFiltered(Iterator begin, Iterator end, KeepFunctor keep)
{ {
return startFilteredReduced<OutputSequence>(QThreadPool::globalInstance(), begin, end, keep, return blockingFilteredReduced<OutputSequence>(QThreadPool::globalInstance(), begin, end, keep,
QtPrivate::PushBackWrapper(), OrderedReduce).startBlocking(); QtPrivate::PushBackWrapper(), OrderedReduce);
} }
} // namespace QtConcurrent } // namespace QtConcurrent

View File

@ -136,30 +136,29 @@ QFuture<ResultType> mappedReduced(const Sequence &sequence,
ResultType(std::forward<InitialValueType>(initialValue)), options); ResultType(std::forward<InitialValueType>(initialValue)), options);
} }
template <typename Sequence, typename MapFunctor, typename ReduceFunctor> template <typename Sequence, typename MapFunctor, typename ReduceFunctor,
QFuture<typename QtPrivate::ReduceResultType<ReduceFunctor>::ResultType> mappedReduced( typename ResultType = typename QtPrivate::ReduceResultType<ReduceFunctor>::ResultType>
QThreadPool *pool, QFuture<ResultType> mappedReduced(QThreadPool *pool,
const Sequence &sequence, const Sequence &sequence,
MapFunctor map, MapFunctor map,
ReduceFunctor reduce, ReduceFunctor reduce,
ReduceOptions options = ReduceOptions(UnorderedReduce ReduceOptions options = ReduceOptions(UnorderedReduce
| SequentialReduce)) | SequentialReduce))
{ {
return startMappedReduced<QtPrivate::MapResultType<Sequence, MapFunctor>, return startMappedReduced<QtPrivate::MapResultType<Sequence, MapFunctor>, ResultType>
typename QtPrivate::ReduceResultType<ReduceFunctor>::ResultType>
(pool, sequence, map, reduce, options); (pool, sequence, map, reduce, options);
} }
template <typename Sequence, typename MapFunctor, typename ReduceFunctor> template <typename Sequence, typename MapFunctor, typename ReduceFunctor,
QFuture<typename QtPrivate::ReduceResultType<ReduceFunctor>::ResultType> mappedReduced( typename ResultType = typename QtPrivate::ReduceResultType<ReduceFunctor>::ResultType>
QFuture<ResultType> mappedReduced(
const Sequence &sequence, const Sequence &sequence,
MapFunctor map, MapFunctor map,
ReduceFunctor reduce, ReduceFunctor reduce,
ReduceOptions options = ReduceOptions(UnorderedReduce ReduceOptions options = ReduceOptions(UnorderedReduce
| SequentialReduce)) | SequentialReduce))
{ {
return startMappedReduced<QtPrivate::MapResultType<Sequence, MapFunctor>, return startMappedReduced<QtPrivate::MapResultType<Sequence, MapFunctor>, ResultType>
typename QtPrivate::ReduceResultType<ReduceFunctor>::ResultType>
(QThreadPool::globalInstance(), sequence, map, reduce, options); (QThreadPool::globalInstance(), sequence, map, reduce, options);
} }
@ -175,8 +174,7 @@ QFuture<ResultType> mappedReduced(QThreadPool *pool,
ReduceOptions options = ReduceOptions(UnorderedReduce ReduceOptions options = ReduceOptions(UnorderedReduce
| SequentialReduce)) | SequentialReduce))
{ {
return startMappedReduced<QtPrivate::MapResultType<Sequence, MapFunctor>, return startMappedReduced<QtPrivate::MapResultType<Sequence, MapFunctor>, ResultType>
typename QtPrivate::ReduceResultType<ReduceFunctor>::ResultType>
(pool, sequence, map, reduce, ResultType(std::forward<InitialValueType>(initialValue)), (pool, sequence, map, reduce, ResultType(std::forward<InitialValueType>(initialValue)),
options); options);
} }
@ -192,9 +190,7 @@ QFuture<ResultType> mappedReduced(const Sequence &sequence,
ReduceOptions options = ReduceOptions(UnorderedReduce ReduceOptions options = ReduceOptions(UnorderedReduce
| SequentialReduce)) | SequentialReduce))
{ {
return startMappedReduced return startMappedReduced<QtPrivate::MapResultType<Sequence, MapFunctor>, ResultType>
<QtPrivate::MapResultType<Sequence, MapFunctor>,
typename QtPrivate::ReduceResultType<ReduceFunctor>::ResultType>
(QThreadPool::globalInstance(), sequence, map, reduce, (QThreadPool::globalInstance(), sequence, map, reduce,
ResultType(std::forward<InitialValueType>(initialValue)), options); ResultType(std::forward<InitialValueType>(initialValue)), options);
} }
@ -258,9 +254,9 @@ QFuture<ResultType> mappedReduced(Iterator begin,
ResultType(std::forward<InitialValueType>(initialValue)), options); ResultType(std::forward<InitialValueType>(initialValue)), options);
} }
template <typename Iterator, typename MapFunctor, typename ReduceFunctor> template <typename Iterator, typename MapFunctor, typename ReduceFunctor,
QFuture<typename QtPrivate::ReduceResultType<ReduceFunctor>::ResultType> mappedReduced( typename ResultType = typename QtPrivate::ReduceResultType<ReduceFunctor>::ResultType>
QThreadPool *pool, QFuture<ResultType> mappedReduced(QThreadPool *pool,
Iterator begin, Iterator begin,
Iterator end, Iterator end,
MapFunctor map, MapFunctor map,
@ -268,22 +264,20 @@ QFuture<typename QtPrivate::ReduceResultType<ReduceFunctor>::ResultType> mappedR
ReduceOptions options = ReduceOptions(UnorderedReduce ReduceOptions options = ReduceOptions(UnorderedReduce
| SequentialReduce)) | SequentialReduce))
{ {
return startMappedReduced<QtPrivate::MapResultType<Iterator, MapFunctor>, return startMappedReduced<QtPrivate::MapResultType<Iterator, MapFunctor>, ResultType>
typename QtPrivate::ReduceResultType<ReduceFunctor>::ResultType>
(pool, begin, end, map, reduce, options); (pool, begin, end, map, reduce, options);
} }
template <typename Iterator, typename MapFunctor, typename ReduceFunctor> template <typename Iterator, typename MapFunctor, typename ReduceFunctor,
QFuture<typename QtPrivate::ReduceResultType<ReduceFunctor>::ResultType> mappedReduced( typename ResultType = typename QtPrivate::ReduceResultType<ReduceFunctor>::ResultType>
Iterator begin, QFuture<ResultType> mappedReduced(Iterator begin,
Iterator end, Iterator end,
MapFunctor map, MapFunctor map,
ReduceFunctor reduce, ReduceFunctor reduce,
ReduceOptions options = ReduceOptions(UnorderedReduce ReduceOptions options = ReduceOptions(UnorderedReduce
| SequentialReduce)) | SequentialReduce))
{ {
return startMappedReduced<QtPrivate::MapResultType<Iterator, MapFunctor>, return startMappedReduced<QtPrivate::MapResultType<Iterator, MapFunctor>, ResultType>
typename QtPrivate::ReduceResultType<ReduceFunctor>::ResultType>
(QThreadPool::globalInstance(), begin, end, map, reduce, options); (QThreadPool::globalInstance(), begin, end, map, reduce, options);
} }
@ -291,8 +285,7 @@ template <typename Iterator, typename MapFunctor, typename ReduceFunctor,
typename ResultType = typename QtPrivate::ReduceResultType<ReduceFunctor>::ResultType, typename ResultType = typename QtPrivate::ReduceResultType<ReduceFunctor>::ResultType,
typename InitialValueType, typename InitialValueType,
std::enable_if_t<std::is_convertible_v<InitialValueType, ResultType>, int> = 0> std::enable_if_t<std::is_convertible_v<InitialValueType, ResultType>, int> = 0>
QFuture<typename QtPrivate::ReduceResultType<ReduceFunctor>::ResultType> mappedReduced( QFuture<ResultType> mappedReduced(QThreadPool *pool,
QThreadPool *pool,
Iterator begin, Iterator begin,
Iterator end, Iterator end,
MapFunctor map, MapFunctor map,
@ -301,9 +294,7 @@ QFuture<typename QtPrivate::ReduceResultType<ReduceFunctor>::ResultType> mappedR
ReduceOptions options = ReduceOptions(UnorderedReduce ReduceOptions options = ReduceOptions(UnorderedReduce
| SequentialReduce)) | SequentialReduce))
{ {
return startMappedReduced return startMappedReduced<QtPrivate::MapResultType<Iterator, MapFunctor>, ResultType>
<QtPrivate::MapResultType<Iterator, MapFunctor>,
typename QtPrivate::ReduceResultType<ReduceFunctor>::ResultType>
(pool, begin, end, map, reduce, ResultType(std::forward<InitialValueType>(initialValue)), (pool, begin, end, map, reduce, ResultType(std::forward<InitialValueType>(initialValue)),
options); options);
} }
@ -312,8 +303,7 @@ template <typename Iterator, typename MapFunctor, typename ReduceFunctor,
typename ResultType = typename QtPrivate::ReduceResultType<ReduceFunctor>::ResultType, typename ResultType = typename QtPrivate::ReduceResultType<ReduceFunctor>::ResultType,
typename InitialValueType, typename InitialValueType,
std::enable_if_t<std::is_convertible_v<InitialValueType, ResultType>, int> = 0> std::enable_if_t<std::is_convertible_v<InitialValueType, ResultType>, int> = 0>
QFuture<typename QtPrivate::ReduceResultType<ReduceFunctor>::ResultType> mappedReduced( QFuture<ResultType> mappedReduced(Iterator begin,
Iterator begin,
Iterator end, Iterator end,
MapFunctor map, MapFunctor map,
ReduceFunctor reduce, ReduceFunctor reduce,
@ -321,9 +311,7 @@ QFuture<typename QtPrivate::ReduceResultType<ReduceFunctor>::ResultType> mappedR
ReduceOptions options = ReduceOptions(UnorderedReduce ReduceOptions options = ReduceOptions(UnorderedReduce
| SequentialReduce)) | SequentialReduce))
{ {
return startMappedReduced return startMappedReduced<QtPrivate::MapResultType<Iterator, MapFunctor>, ResultType>
<QtPrivate::MapResultType<Iterator, MapFunctor>,
typename QtPrivate::ReduceResultType<ReduceFunctor>::ResultType>
(QThreadPool::globalInstance(), begin, end, map, reduce, (QThreadPool::globalInstance(), begin, end, map, reduce,
ResultType(std::forward<InitialValueType>(initialValue)), options); ResultType(std::forward<InitialValueType>(initialValue)), options);
} }
@ -372,26 +360,30 @@ QFuture<QtPrivate::MapResultType<Iterator, MapFunctor>> mapped(
template <typename Sequence, typename MapFunctor> template <typename Sequence, typename MapFunctor>
void blockingMap(QThreadPool *pool, Sequence &sequence, MapFunctor map) void blockingMap(QThreadPool *pool, Sequence &sequence, MapFunctor map)
{ {
startMap(pool, sequence.begin(), sequence.end(), map).startBlocking(); QFuture<void> future = startMap(pool, sequence.begin(), sequence.end(), map);
future.waitForFinished();
} }
template <typename Sequence, typename MapFunctor> template <typename Sequence, typename MapFunctor>
void blockingMap(Sequence &sequence, MapFunctor map) void blockingMap(Sequence &sequence, MapFunctor map)
{ {
startMap(QThreadPool::globalInstance(), sequence.begin(), sequence.end(), map).startBlocking(); QFuture<void> future = startMap(QThreadPool::globalInstance(), sequence.begin(), sequence.end(), map);
future.waitForFinished();
} }
// blockingMap() for iterator ranges // blockingMap() for iterator ranges
template <typename Iterator, typename MapFunctor> template <typename Iterator, typename MapFunctor>
void blockingMap(QThreadPool *pool, Iterator begin, Iterator end, MapFunctor map) void blockingMap(QThreadPool *pool, Iterator begin, Iterator end, MapFunctor map)
{ {
startMap(pool, begin, end, map).startBlocking(); QFuture<void> future = startMap(pool, begin, end, map);
future.waitForFinished();
} }
template <typename Iterator, typename MapFunctor> template <typename Iterator, typename MapFunctor>
void blockingMap(Iterator begin, Iterator end, MapFunctor map) void blockingMap(Iterator begin, Iterator end, MapFunctor map)
{ {
startMap(QThreadPool::globalInstance(), begin, end, map).startBlocking(); QFuture<void> future = startMap(QThreadPool::globalInstance(), begin, end, map);
future.waitForFinished();
} }
// blockingMappedReduced() for sequences // blockingMappedReduced() for sequences
@ -403,9 +395,10 @@ ResultType blockingMappedReduced(QThreadPool *pool,
ReduceOptions options = ReduceOptions(UnorderedReduce ReduceOptions options = ReduceOptions(UnorderedReduce
| SequentialReduce)) | SequentialReduce))
{ {
return QtConcurrent::startMappedReduced QFuture<ResultType> future = QtConcurrent::startMappedReduced
<QtPrivate::MapResultType<Sequence, MapFunctor>, ResultType> <QtPrivate::MapResultType<Sequence, MapFunctor>, ResultType>
(pool, sequence, map, reduce, options).startBlocking(); (pool, sequence, map, reduce, options);
return future.result();
} }
template <typename ResultType, typename Sequence, typename MapFunctor, typename ReduceFunctor> template <typename ResultType, typename Sequence, typename MapFunctor, typename ReduceFunctor>
@ -415,9 +408,10 @@ ResultType blockingMappedReduced(const Sequence &sequence,
ReduceOptions options = ReduceOptions(UnorderedReduce ReduceOptions options = ReduceOptions(UnorderedReduce
| SequentialReduce)) | SequentialReduce))
{ {
return QtConcurrent::startMappedReduced QFuture<ResultType> future = QtConcurrent::startMappedReduced
<QtPrivate::MapResultType<Sequence, MapFunctor>, ResultType> <QtPrivate::MapResultType<Sequence, MapFunctor>, ResultType>
(QThreadPool::globalInstance(), sequence, map, reduce, options).startBlocking(); (QThreadPool::globalInstance(), sequence, map, reduce, options);
return future.result();
} }
template <typename ResultType, typename Sequence, typename MapFunctor, typename ReduceFunctor, template <typename ResultType, typename Sequence, typename MapFunctor, typename ReduceFunctor,
@ -431,10 +425,11 @@ ResultType blockingMappedReduced(QThreadPool *pool,
ReduceOptions options = ReduceOptions(UnorderedReduce ReduceOptions options = ReduceOptions(UnorderedReduce
| SequentialReduce)) | SequentialReduce))
{ {
return QtConcurrent::startMappedReduced QFuture<ResultType> future = QtConcurrent::startMappedReduced
<QtPrivate::MapResultType<Sequence, MapFunctor>, ResultType> <QtPrivate::MapResultType<Sequence, MapFunctor>, ResultType>
(pool, sequence, map, reduce, ResultType(std::forward<InitialValueType>(initialValue)), (pool, sequence, map, reduce, ResultType(std::forward<InitialValueType>(initialValue)),
options).startBlocking(); options);
return future.result();
} }
template <typename ResultType, typename Sequence, typename MapFunctor, typename ReduceFunctor, template <typename ResultType, typename Sequence, typename MapFunctor, typename ReduceFunctor,
@ -447,48 +442,47 @@ ResultType blockingMappedReduced(const Sequence &sequence,
ReduceOptions options = ReduceOptions(UnorderedReduce ReduceOptions options = ReduceOptions(UnorderedReduce
| SequentialReduce)) | SequentialReduce))
{ {
return QtConcurrent::startMappedReduced QFuture<ResultType> future = QtConcurrent::startMappedReduced
<QtPrivate::MapResultType<Sequence, MapFunctor>, ResultType> <QtPrivate::MapResultType<Sequence, MapFunctor>, ResultType>
(QThreadPool::globalInstance(), sequence, map, reduce, (QThreadPool::globalInstance(), sequence, map, reduce,
ResultType(std::forward<InitialValueType>(initialValue)), options) ResultType(std::forward<InitialValueType>(initialValue)), options);
.startBlocking(); return future.result();
} }
template <typename MapFunctor, typename ReduceFunctor, typename Sequence> template <typename MapFunctor, typename ReduceFunctor, typename Sequence,
typename QtPrivate::ReduceResultType<ReduceFunctor>::ResultType blockingMappedReduced( typename ResultType = typename QtPrivate::ReduceResultType<ReduceFunctor>::ResultType>
QThreadPool *pool, ResultType blockingMappedReduced(QThreadPool *pool,
const Sequence &sequence, const Sequence &sequence,
MapFunctor map, MapFunctor map,
ReduceFunctor reduce, ReduceFunctor reduce,
ReduceOptions options = ReduceOptions(UnorderedReduce ReduceOptions options = ReduceOptions(UnorderedReduce
| SequentialReduce)) | SequentialReduce))
{ {
return QtConcurrent::startMappedReduced QFuture<ResultType> future = QtConcurrent::startMappedReduced
<QtPrivate::MapResultType<Sequence, MapFunctor>, <QtPrivate::MapResultType<Sequence, MapFunctor>, ResultType>
typename QtPrivate::ReduceResultType<ReduceFunctor>::ResultType> (pool, sequence, map, reduce, options);
(pool, sequence, map, reduce, options).startBlocking(); return future.result();
} }
template <typename MapFunctor, typename ReduceFunctor, typename Sequence> template <typename MapFunctor, typename ReduceFunctor, typename Sequence,
typename QtPrivate::ReduceResultType<ReduceFunctor>::ResultType blockingMappedReduced( typename ResultType = typename QtPrivate::ReduceResultType<ReduceFunctor>::ResultType>
const Sequence &sequence, ResultType blockingMappedReduced(const Sequence &sequence,
MapFunctor map, MapFunctor map,
ReduceFunctor reduce, ReduceFunctor reduce,
ReduceOptions options = ReduceOptions(UnorderedReduce ReduceOptions options = ReduceOptions(UnorderedReduce
| SequentialReduce)) | SequentialReduce))
{ {
return QtConcurrent::startMappedReduced QFuture<ResultType> future = QtConcurrent::startMappedReduced
<QtPrivate::MapResultType<Sequence, MapFunctor>, <QtPrivate::MapResultType<Sequence, MapFunctor>, ResultType>
typename QtPrivate::ReduceResultType<ReduceFunctor>::ResultType> (QThreadPool::globalInstance(), sequence, map, reduce, options);
(QThreadPool::globalInstance(), sequence, map, reduce, options).startBlocking(); return future.result();
} }
template <typename MapFunctor, typename ReduceFunctor, typename Sequence, template <typename MapFunctor, typename ReduceFunctor, typename Sequence,
typename ResultType = typename QtPrivate::ReduceResultType<ReduceFunctor>::ResultType, typename ResultType = typename QtPrivate::ReduceResultType<ReduceFunctor>::ResultType,
typename InitialValueType, typename InitialValueType,
std::enable_if_t<std::is_convertible_v<InitialValueType, ResultType>, int> = 0> std::enable_if_t<std::is_convertible_v<InitialValueType, ResultType>, int> = 0>
typename QtPrivate::ReduceResultType<ReduceFunctor>::ResultType blockingMappedReduced( ResultType blockingMappedReduced(QThreadPool *pool,
QThreadPool *pool,
const Sequence &sequence, const Sequence &sequence,
MapFunctor map, MapFunctor map,
ReduceFunctor reduce, ReduceFunctor reduce,
@ -496,30 +490,29 @@ typename QtPrivate::ReduceResultType<ReduceFunctor>::ResultType blockingMappedRe
ReduceOptions options = ReduceOptions(UnorderedReduce ReduceOptions options = ReduceOptions(UnorderedReduce
| SequentialReduce)) | SequentialReduce))
{ {
return QtConcurrent::startMappedReduced QFuture<ResultType> future = QtConcurrent::startMappedReduced
<QtPrivate::MapResultType<Sequence, MapFunctor>, <QtPrivate::MapResultType<Sequence, MapFunctor>, ResultType>
typename QtPrivate::ReduceResultType<ReduceFunctor>::ResultType>
(pool, sequence, map, reduce, ResultType(std::forward<InitialValueType>(initialValue)), (pool, sequence, map, reduce, ResultType(std::forward<InitialValueType>(initialValue)),
options).startBlocking(); options);
return future.result();
} }
template <typename MapFunctor, typename ReduceFunctor, typename Sequence, template <typename MapFunctor, typename ReduceFunctor, typename Sequence,
typename ResultType = typename QtPrivate::ReduceResultType<ReduceFunctor>::ResultType, typename ResultType = typename QtPrivate::ReduceResultType<ReduceFunctor>::ResultType,
typename InitialValueType, typename InitialValueType,
std::enable_if_t<std::is_convertible_v<InitialValueType, ResultType>, int> = 0> std::enable_if_t<std::is_convertible_v<InitialValueType, ResultType>, int> = 0>
typename QtPrivate::ReduceResultType<ReduceFunctor>::ResultType blockingMappedReduced( ResultType blockingMappedReduced(const Sequence &sequence,
const Sequence &sequence,
MapFunctor map, MapFunctor map,
ReduceFunctor reduce, ReduceFunctor reduce,
InitialValueType &&initialValue, InitialValueType &&initialValue,
ReduceOptions options = ReduceOptions(UnorderedReduce ReduceOptions options = ReduceOptions(UnorderedReduce
| SequentialReduce)) | SequentialReduce))
{ {
return QtConcurrent::startMappedReduced QFuture<ResultType> future = QtConcurrent::startMappedReduced
<QtPrivate::MapResultType<Sequence, MapFunctor>, <QtPrivate::MapResultType<Sequence, MapFunctor>, ResultType>
typename QtPrivate::ReduceResultType<ReduceFunctor>::ResultType>
(QThreadPool::globalInstance(), sequence, map, reduce, (QThreadPool::globalInstance(), sequence, map, reduce,
ResultType(std::forward<InitialValueType>(initialValue)), options).startBlocking(); ResultType(std::forward<InitialValueType>(initialValue)), options);
return future.result();
} }
// blockingMappedReduced() for iterator ranges // blockingMappedReduced() for iterator ranges
@ -532,9 +525,10 @@ ResultType blockingMappedReduced(QThreadPool *pool,
ReduceOptions options = ReduceOptions(UnorderedReduce ReduceOptions options = ReduceOptions(UnorderedReduce
| SequentialReduce)) | SequentialReduce))
{ {
return QtConcurrent::startMappedReduced QFuture<ResultType> future = QtConcurrent::startMappedReduced
<QtPrivate::MapResultType<Iterator, MapFunctor>, ResultType> <QtPrivate::MapResultType<Iterator, MapFunctor>, ResultType>
(pool, begin, end, map, reduce, options).startBlocking(); (pool, begin, end, map, reduce, options);
return future.result();
} }
template <typename ResultType, typename Iterator, typename MapFunctor, typename ReduceFunctor> template <typename ResultType, typename Iterator, typename MapFunctor, typename ReduceFunctor>
@ -545,9 +539,10 @@ ResultType blockingMappedReduced(Iterator begin,
ReduceOptions options = ReduceOptions(UnorderedReduce ReduceOptions options = ReduceOptions(UnorderedReduce
| SequentialReduce)) | SequentialReduce))
{ {
return QtConcurrent::startMappedReduced QFuture<ResultType> future = QtConcurrent::startMappedReduced
<QtPrivate::MapResultType<Iterator, MapFunctor>, ResultType> <QtPrivate::MapResultType<Iterator, MapFunctor>, ResultType>
(QThreadPool::globalInstance(), begin, end, map, reduce, options).startBlocking(); (QThreadPool::globalInstance(), begin, end, map, reduce, options);
return future.result();
} }
template <typename ResultType, typename Iterator, typename MapFunctor, typename ReduceFunctor, template <typename ResultType, typename Iterator, typename MapFunctor, typename ReduceFunctor,
@ -562,10 +557,11 @@ ResultType blockingMappedReduced(QThreadPool *pool,
ReduceOptions options = ReduceOptions(UnorderedReduce ReduceOptions options = ReduceOptions(UnorderedReduce
| SequentialReduce)) | SequentialReduce))
{ {
return QtConcurrent::startMappedReduced QFuture<ResultType> future = QtConcurrent::startMappedReduced
<QtPrivate::MapResultType<Iterator, MapFunctor>, ResultType> <QtPrivate::MapResultType<Iterator, MapFunctor>, ResultType>
(pool, begin, end, map, reduce, ResultType(std::forward<InitialValueType>(initialValue)), (pool, begin, end, map, reduce, ResultType(std::forward<InitialValueType>(initialValue)),
options).startBlocking(); options);
return future.result();
} }
template <typename ResultType, typename Iterator, typename MapFunctor, typename ReduceFunctor, template <typename ResultType, typename Iterator, typename MapFunctor, typename ReduceFunctor,
@ -579,15 +575,16 @@ ResultType blockingMappedReduced(Iterator begin,
ReduceOptions options = ReduceOptions(UnorderedReduce ReduceOptions options = ReduceOptions(UnorderedReduce
| SequentialReduce)) | SequentialReduce))
{ {
return QtConcurrent::startMappedReduced QFuture<ResultType> future = QtConcurrent::startMappedReduced
<QtPrivate::MapResultType<Iterator, MapFunctor>, ResultType> <QtPrivate::MapResultType<Iterator, MapFunctor>, ResultType>
(QThreadPool::globalInstance(), begin, end, map, reduce, (QThreadPool::globalInstance(), begin, end, map, reduce,
ResultType(std::forward<InitialValueType>(initialValue)), options).startBlocking(); ResultType(std::forward<InitialValueType>(initialValue)), options);
return future.result();
} }
template <typename Iterator, typename MapFunctor, typename ReduceFunctor> template <typename Iterator, typename MapFunctor, typename ReduceFunctor,
typename QtPrivate::ReduceResultType<ReduceFunctor>::ResultType blockingMappedReduced( typename ResultType = typename QtPrivate::ReduceResultType<ReduceFunctor>::ResultType>
QThreadPool *pool, ResultType blockingMappedReduced(QThreadPool *pool,
Iterator begin, Iterator begin,
Iterator end, Iterator end,
MapFunctor map, MapFunctor map,
@ -595,33 +592,32 @@ typename QtPrivate::ReduceResultType<ReduceFunctor>::ResultType blockingMappedRe
ReduceOptions options = ReduceOptions(UnorderedReduce ReduceOptions options = ReduceOptions(UnorderedReduce
| SequentialReduce)) | SequentialReduce))
{ {
return QtConcurrent::startMappedReduced QFuture<ResultType> future = QtConcurrent::startMappedReduced
<QtPrivate::MapResultType<Iterator, MapFunctor>, <QtPrivate::MapResultType<Iterator, MapFunctor>, ResultType>
typename QtPrivate::ReduceResultType<ReduceFunctor>::ResultType> (pool, begin, end, map, reduce, options);
(pool, begin, end, map, reduce, options).startBlocking(); return future.result();
} }
template <typename Iterator, typename MapFunctor, typename ReduceFunctor> template <typename Iterator, typename MapFunctor, typename ReduceFunctor,
typename QtPrivate::ReduceResultType<ReduceFunctor>::ResultType blockingMappedReduced( typename ResultType = typename QtPrivate::ReduceResultType<ReduceFunctor>::ResultType>
Iterator begin, ResultType blockingMappedReduced(Iterator begin,
Iterator end, Iterator end,
MapFunctor map, MapFunctor map,
ReduceFunctor reduce, ReduceFunctor reduce,
ReduceOptions options = ReduceOptions(UnorderedReduce ReduceOptions options = ReduceOptions(UnorderedReduce
| SequentialReduce)) | SequentialReduce))
{ {
return QtConcurrent::startMappedReduced QFuture<ResultType> future = QtConcurrent::startMappedReduced
<QtPrivate::MapResultType<Iterator, MapFunctor>, <QtPrivate::MapResultType<Iterator, MapFunctor>, ResultType>
typename QtPrivate::ReduceResultType<ReduceFunctor>::ResultType> (QThreadPool::globalInstance(), begin, end, map, reduce, options);
(QThreadPool::globalInstance(), begin, end, map, reduce, options).startBlocking(); return future.result();
} }
template <typename Iterator, typename MapFunctor, typename ReduceFunctor, template <typename Iterator, typename MapFunctor, typename ReduceFunctor,
typename ResultType = typename QtPrivate::ReduceResultType<ReduceFunctor>::ResultType, typename ResultType = typename QtPrivate::ReduceResultType<ReduceFunctor>::ResultType,
typename InitialValueType, typename InitialValueType,
std::enable_if_t<std::is_convertible_v<InitialValueType, ResultType>, int> = 0> std::enable_if_t<std::is_convertible_v<InitialValueType, ResultType>, int> = 0>
typename QtPrivate::ReduceResultType<ReduceFunctor>::ResultType blockingMappedReduced( ResultType blockingMappedReduced(QThreadPool *pool,
QThreadPool *pool,
Iterator begin, Iterator begin,
Iterator end, Iterator end,
MapFunctor map, MapFunctor map,
@ -630,19 +626,18 @@ typename QtPrivate::ReduceResultType<ReduceFunctor>::ResultType blockingMappedRe
ReduceOptions options = ReduceOptions(UnorderedReduce ReduceOptions options = ReduceOptions(UnorderedReduce
| SequentialReduce)) | SequentialReduce))
{ {
return QtConcurrent::startMappedReduced QFuture<ResultType> future = QtConcurrent::startMappedReduced
<QtPrivate::MapResultType<Iterator, MapFunctor>, <QtPrivate::MapResultType<Iterator, MapFunctor>, ResultType>
typename QtPrivate::ReduceResultType<ReduceFunctor>::ResultType>
(pool, begin, end, map, reduce, ResultType(std::forward<InitialValueType>(initialValue)), (pool, begin, end, map, reduce, ResultType(std::forward<InitialValueType>(initialValue)),
options).startBlocking(); options);
return future.result();
} }
template <typename Iterator, typename MapFunctor, typename ReduceFunctor, template <typename Iterator, typename MapFunctor, typename ReduceFunctor,
typename ResultType = typename QtPrivate::ReduceResultType<ReduceFunctor>::ResultType, typename ResultType = typename QtPrivate::ReduceResultType<ReduceFunctor>::ResultType,
typename InitialValueType, typename InitialValueType,
std::enable_if_t<std::is_convertible_v<InitialValueType, ResultType>, int> = 0> std::enable_if_t<std::is_convertible_v<InitialValueType, ResultType>, int> = 0>
typename QtPrivate::ReduceResultType<ReduceFunctor>::ResultType blockingMappedReduced( ResultType blockingMappedReduced(Iterator begin,
Iterator begin,
Iterator end, Iterator end,
MapFunctor map, MapFunctor map,
ReduceFunctor reduce, ReduceFunctor reduce,
@ -650,11 +645,11 @@ typename QtPrivate::ReduceResultType<ReduceFunctor>::ResultType blockingMappedRe
ReduceOptions options = ReduceOptions(UnorderedReduce ReduceOptions options = ReduceOptions(UnorderedReduce
| SequentialReduce)) | SequentialReduce))
{ {
return QtConcurrent::startMappedReduced QFuture<ResultType> future = QtConcurrent::startMappedReduced
<QtPrivate::MapResultType<Iterator, MapFunctor>, <QtPrivate::MapResultType<Iterator, MapFunctor>, ResultType>
typename QtPrivate::ReduceResultType<ReduceFunctor>::ResultType>
(QThreadPool::globalInstance(), begin, end, map, reduce, (QThreadPool::globalInstance(), begin, end, map, reduce,
ResultType(std::forward<InitialValueType>(initialValue)), options).startBlocking(); ResultType(std::forward<InitialValueType>(initialValue)), options);
return future.result();
} }
// mapped() for sequences with a different putput sequence type. // mapped() for sequences with a different putput sequence type.

View File

@ -127,17 +127,15 @@ void testFilterThreadPool(QThreadPool *pool,
FilterObject filterObject) FilterObject filterObject)
{ {
QList<SourceObject> copy1 = sourceObjectList; QList<SourceObject> copy1 = sourceObjectList;
// QList<SourceObject> copy2 = sourceObjectList; QList<SourceObject> copy2 = sourceObjectList;
QtConcurrent::filter(pool, copy1, filterObject).waitForFinished(); QtConcurrent::filter(pool, copy1, filterObject).waitForFinished();
QCOMPARE(copy1, expectedResult); QCOMPARE(copy1, expectedResult);
QCOMPARE(threadCount(), 1); // ensure the only one thread was working QCOMPARE(threadCount(), 1); // ensure the only one thread was working
// TODO: enable when QTBUG-83918 is fixed QtConcurrent::blockingFilter(pool, copy2, filterObject);
QCOMPARE(copy2, expectedResult);
// QtConcurrent::blockingFilter(pool, copy2, filterObject); QCOMPARE(threadCount(), 1); // ensure the only one thread was working
// QCOMPARE(copy2, expectedResult);
// QCOMPARE(threadCount(), 1); // ensure the only one thread was working
} }
class KeepOddIntegers class KeepOddIntegers
@ -244,17 +242,15 @@ void testFilteredThreadPool(QThreadPool *pool,
QCOMPARE(result2, expectedResult); QCOMPARE(result2, expectedResult);
QCOMPARE(threadCount(), 1); // ensure the only one thread was working QCOMPARE(threadCount(), 1); // ensure the only one thread was working
// TODO: enable when QTBUG-83918 is fixed const QList<ResultObject> result3 = QtConcurrent::blockingFiltered(
pool, sourceObjectList, filterObject);
QCOMPARE(result3, expectedResult);
QCOMPARE(threadCount(), 1); // ensure the only one thread was working
// const QList<ResultObject> result3 = QtConcurrent::blockingFiltered( const QList<ResultObject> result4 = QtConcurrent::blockingFiltered<QList<ResultObject>>(
// pool, sourceObjectList, filterObject); pool, sourceObjectList.constBegin(), sourceObjectList.constEnd(), filterObject);
// QCOMPARE(result3, expectedResult); QCOMPARE(result4, expectedResult);
// QCOMPARE(threadCount(), 1); // ensure the only one thread was working QCOMPARE(threadCount(), 1); // ensure the only one thread was working
// const QList<ResultObject> result4 = QtConcurrent::blockingFiltered<QList<ResultObject>>(
// pool, sourceObjectList.constBegin(), sourceObjectList.constEnd(), filterObject);
// QCOMPARE(result4, expectedResult);
// QCOMPARE(threadCount(), 1); // ensure the only one thread was working
} }
void tst_QtConcurrentFilter::filteredThreadPool() void tst_QtConcurrentFilter::filteredThreadPool()
@ -436,18 +432,16 @@ void testFilteredReducedThreadPool(QThreadPool *pool,
QCOMPARE(result2, expectedResult); QCOMPARE(result2, expectedResult);
QCOMPARE(threadCount(), 1); // ensure the only one thread was working QCOMPARE(threadCount(), 1); // ensure the only one thread was working
// TODO: enable when QTBUG-83918 is fixed const ResultObject result3 = QtConcurrent::blockingFilteredReduced<ResultObject>(
pool, sourceObjectList, filterObject, reduceObject);
QCOMPARE(result3, expectedResult);
QCOMPARE(threadCount(), 1); // ensure the only one thread was working
// const ResultObject result3 = QtConcurrent::blockingFilteredReduced<ResultObject>( const ResultObject result4 = QtConcurrent::blockingFilteredReduced<ResultObject>(
// pool, sourceObjectList, filterObject, reduceObject); pool, sourceObjectList.constBegin(), sourceObjectList.constEnd(),
// QCOMPARE(result3, expectedResult); filterObject, reduceObject);
// QCOMPARE(threadCount(), 1); // ensure the only one thread was working QCOMPARE(result4, expectedResult);
QCOMPARE(threadCount(), 1); // ensure the only one thread was working
// const ResultObject result4 = QtConcurrent::blockingFilteredReduced<ResultObject>(
// pool, sourceObjectList.constBegin(), sourceObjectList.constEnd(),
// filterObject, reduceObject);
// QCOMPARE(result4, expectedResult);
// QCOMPARE(threadCount(), 1); // ensure the only one thread was working
} }
void tst_QtConcurrentFilter::filteredReducedThreadPool() void tst_QtConcurrentFilter::filteredReducedThreadPool()
@ -711,18 +705,16 @@ void testFilteredReducedInitialValueThreadPool(QThreadPool *pool,
QCOMPARE(result2, expectedResult); QCOMPARE(result2, expectedResult);
QCOMPARE(threadCount(), 1); // ensure the only one thread was working QCOMPARE(threadCount(), 1); // ensure the only one thread was working
// TODO: enable when QTBUG-83918 is fixed const ResultObject result3 = QtConcurrent::blockingFilteredReduced<ResultObject>(
pool, sourceObjectList, filterObject, reduceObject, initialObject);
QCOMPARE(result3, expectedResult);
QCOMPARE(threadCount(), 1); // ensure the only one thread was working
// const ResultObject result3 = QtConcurrent::blockingFilteredReduced<ResultObject>( const ResultObject result4 = QtConcurrent::blockingFilteredReduced<ResultObject>(
// pool, sourceObjectList, filterObject, reduceObject, initialObject); pool, sourceObjectList.constBegin(), sourceObjectList.constEnd(),
// QCOMPARE(result3, expectedResult); filterObject, reduceObject, initialObject);
// QCOMPARE(threadCount(), 1); // ensure the only one thread was working QCOMPARE(result4, expectedResult);
QCOMPARE(threadCount(), 1); // ensure the only one thread was working
// const ResultObject result4 = QtConcurrent::blockingFilteredReduced<ResultObject>(
// pool, sourceObjectList.constBegin(), sourceObjectList.constEnd(),
// filterObject, reduceObject, initialObject);
// QCOMPARE(result4, expectedResult);
// QCOMPARE(threadCount(), 1); // ensure the only one thread was working
} }
void tst_QtConcurrentFilter::filteredReducedInitialValueThreadPool() void tst_QtConcurrentFilter::filteredReducedInitialValueThreadPool()

View File

@ -483,17 +483,15 @@ void testMappedThreadPool(QThreadPool *pool,
QCOMPARE(result2, expectedResult); QCOMPARE(result2, expectedResult);
QCOMPARE(threadCount(), 1); // ensure the only one thread was working QCOMPARE(threadCount(), 1); // ensure the only one thread was working
// TODO: enable when QTBUG-83918 is fixed const QList<ResultObject> result3 = QtConcurrent::blockingMapped(pool,
sourceObjectList, mapObject);
QCOMPARE(result3, expectedResult);
QCOMPARE(threadCount(), 1); // ensure the only one thread was working
// const QList<ResultObject> result3 = QtConcurrent::blockingMapped(pool, const QList<ResultObject> result4 = QtConcurrent::blockingMapped<QList<ResultObject>>(pool,
// sourceObjectList, mapObject); sourceObjectList.constBegin(), sourceObjectList.constEnd(), mapObject);
// QCOMPARE(result3, expectedResult); QCOMPARE(result4, expectedResult);
// QCOMPARE(threadCount(), 1); // ensure the only one thread was working QCOMPARE(threadCount(), 1); // ensure the only one thread was working
// const QList<ResultObject> result4 = QtConcurrent::blockingMapped<QList<ResultObject>>(pool,
// sourceObjectList.constBegin(), sourceObjectList.constEnd(), mapObject);
// QCOMPARE(result4, expectedResult);
// QCOMPARE(threadCount(), 1); // ensure the only one thread was working
} }
int multiplyBy3(int x) int multiplyBy3(int x)
@ -678,17 +676,15 @@ void testMappedReducedThreadPool(QThreadPool *pool,
QCOMPARE(result2, expectedResult); QCOMPARE(result2, expectedResult);
QCOMPARE(threadCount(), 1); // ensure the only one thread was working QCOMPARE(threadCount(), 1); // ensure the only one thread was working
// TODO: enable when QTBUG-83918 is fixed const ResultObject result3 = QtConcurrent::blockingMappedReduced<ResultObject>(pool,
sourceObjectList, mapObject, reduceObject);
QCOMPARE(result3, expectedResult);
QCOMPARE(threadCount(), 1); // ensure the only one thread was working
// const ResultObject result3 = QtConcurrent::blockingMappedReduced<ResultObject>(pool, const ResultObject result4 = QtConcurrent::blockingMappedReduced<ResultObject>(pool,
// sourceObjectList, mapObject, reduceObject); sourceObjectList.constBegin(), sourceObjectList.constEnd(), mapObject, reduceObject);
// QCOMPARE(result3, expectedResult); QCOMPARE(result4, expectedResult);
// QCOMPARE(threadCount(), 1); // ensure the only one thread was working QCOMPARE(threadCount(), 1); // ensure the only one thread was working
// const ResultObject result4 = QtConcurrent::blockingMappedReduced<ResultObject>(pool,
// sourceObjectList.constBegin(), sourceObjectList.constEnd(), mapObject, reduceObject);
// QCOMPARE(result4, expectedResult);
// QCOMPARE(threadCount(), 1); // ensure the only one thread was working
} }
int intCube(int x) int intCube(int x)
@ -930,18 +926,16 @@ void testMappedReducedInitialValueThreadPool(QThreadPool *pool,
QCOMPARE(result2, expectedResult); QCOMPARE(result2, expectedResult);
QCOMPARE(threadCount(), 1); // ensure the only one thread was working QCOMPARE(threadCount(), 1); // ensure the only one thread was working
// TODO: enable when QTBUG-83918 is fixed const ResultObject result3 = QtConcurrent::blockingMappedReduced<ResultObject>(
pool, sourceObjectList, mapObject, reduceObject, initialObject);
QCOMPARE(result3, expectedResult);
QCOMPARE(threadCount(), 1); // ensure the only one thread was working
// const ResultObject result3 = QtConcurrent::blockingMappedReduced<ResultObject>( const ResultObject result4 = QtConcurrent::blockingMappedReduced<ResultObject>(
// pool, sourceObjectList, mapObject, reduceObject, initialObject); pool, sourceObjectList.constBegin(), sourceObjectList.constEnd(),
// QCOMPARE(result3, expectedResult); mapObject, reduceObject, initialObject);
// QCOMPARE(threadCount(), 1); // ensure the only one thread was working QCOMPARE(result4, expectedResult);
QCOMPARE(threadCount(), 1); // ensure the only one thread was working
// const ResultObject result4 = QtConcurrent::blockingMappedReduced<ResultObject>(
// pool, sourceObjectList.constBegin(), sourceObjectList.constEnd(),
// mapObject, reduceObject, initialObject);
// QCOMPARE(result4, expectedResult);
// QCOMPARE(threadCount(), 1); // ensure the only one thread was working
} }
void tst_QtConcurrentMap::mappedReducedInitialValueThreadPool() void tst_QtConcurrentMap::mappedReducedInitialValueThreadPool()