Use universal references in QtConcurrent
Changed QtConcurrent algorithms to take the passed sequences as universal references, where it makes sense. In addition to avoiding to create extra copies when passing rvalues, this change allows passing temporary container adaptors to QtConcurrent::map (e.g. see the example in the ticket and the new test-cases). Task-number: QTBUG-83170 Change-Id: Ia7c0833f4ec1d860294fa5214cd53934b65ff084 Reviewed-by: Andrei Golubev <andrei.golubev@qt.io> Reviewed-by: Jarek Kobus <jaroslaw.kobus@qt.io> Reviewed-by: Mårten Nordheim <marten.nordheim@qt.io>
This commit is contained in:
parent
5c7307775d
commit
2e27b98cff
@ -263,7 +263,7 @@
|
||||
*/
|
||||
|
||||
/*!
|
||||
\fn template <typename Sequence, typename KeepFunctor> QFuture<Sequence::value_type> QtConcurrent::filtered(QThreadPool *pool, const Sequence &sequence, KeepFunctor filterFunction)
|
||||
\fn template <typename Sequence, typename KeepFunctor> QFuture<Sequence::value_type> QtConcurrent::filtered(QThreadPool *pool, Sequence &&sequence, KeepFunctor filterFunction)
|
||||
|
||||
Calls \a filterFunction once for each item in \a sequence and returns a
|
||||
new Sequence of kept items. All calls to \a filterFunction are invoked from the threads
|
||||
@ -275,7 +275,7 @@
|
||||
*/
|
||||
|
||||
/*!
|
||||
\fn template <typename Sequence, typename KeepFunctor> QFuture<Sequence::value_type> QtConcurrent::filtered(const Sequence &sequence, KeepFunctor filterFunction)
|
||||
\fn template <typename Sequence, typename KeepFunctor> QFuture<Sequence::value_type> QtConcurrent::filtered(Sequence &&sequence, KeepFunctor filterFunction)
|
||||
|
||||
Calls \a filterFunction once for each item in \a sequence and returns a
|
||||
new Sequence of kept items. If \a filterFunction returns \c true, a copy of
|
||||
@ -309,7 +309,7 @@
|
||||
*/
|
||||
|
||||
/*!
|
||||
\fn template <typename ResultType, typename Sequence, typename KeepFunctor, typename ReduceFunctor> QFuture<ResultType> QtConcurrent::filteredReduced(QThreadPool *pool, const Sequence &sequence, KeepFunctor filterFunction, ReduceFunctor reduceFunction, QtConcurrent::ReduceOptions reduceOptions)
|
||||
\fn template <typename ResultType, typename Sequence, typename KeepFunctor, typename ReduceFunctor> QFuture<ResultType> QtConcurrent::filteredReduced(QThreadPool *pool, Sequence &&sequence, KeepFunctor filterFunction, ReduceFunctor reduceFunction, QtConcurrent::ReduceOptions reduceOptions)
|
||||
|
||||
Calls \a filterFunction once for each item in \a sequence.
|
||||
All calls to \a filterFunction are invoked from the threads taken from the QThreadPool \a pool.
|
||||
@ -328,7 +328,7 @@
|
||||
*/
|
||||
|
||||
/*!
|
||||
\fn template <typename ResultType, typename Sequence, typename KeepFunctor, typename ReduceFunctor> QFuture<ResultType> QtConcurrent::filteredReduced(const Sequence &sequence, KeepFunctor filterFunction, ReduceFunctor reduceFunction, QtConcurrent::ReduceOptions reduceOptions)
|
||||
\fn template <typename ResultType, typename Sequence, typename KeepFunctor, typename ReduceFunctor> QFuture<ResultType> QtConcurrent::filteredReduced(Sequence &&sequence, KeepFunctor filterFunction, ReduceFunctor reduceFunction, QtConcurrent::ReduceOptions reduceOptions)
|
||||
|
||||
Calls \a filterFunction once for each item in \a sequence. If
|
||||
\a filterFunction returns \c true for an item, that item is then passed to
|
||||
@ -346,7 +346,7 @@
|
||||
*/
|
||||
|
||||
/*!
|
||||
\fn template <typename ResultType, typename Sequence, typename KeepFunctor, typename ReduceFunctor, typename InitialValueType> QFuture<ResultType> QtConcurrent::filteredReduced(QThreadPool *pool, const Sequence &sequence, KeepFunctor filterFunction, ReduceFunctor reduceFunction, InitialValueType &&initialValue, QtConcurrent::ReduceOptions reduceOptions)
|
||||
\fn template <typename ResultType, typename Sequence, typename KeepFunctor, typename ReduceFunctor, typename InitialValueType> QFuture<ResultType> QtConcurrent::filteredReduced(QThreadPool *pool, Sequence &&sequence, KeepFunctor filterFunction, ReduceFunctor reduceFunction, InitialValueType &&initialValue, QtConcurrent::ReduceOptions reduceOptions)
|
||||
|
||||
Calls \a filterFunction once for each item in \a sequence.
|
||||
All calls to \a filterFunction are invoked from the threads taken from the QThreadPool \a pool.
|
||||
@ -368,7 +368,7 @@
|
||||
*/
|
||||
|
||||
/*!
|
||||
\fn template <typename ResultType, typename Sequence, typename KeepFunctor, typename ReduceFunctor, typename InitialValueType> QFuture<ResultType> QtConcurrent::filteredReduced(const Sequence &sequence, KeepFunctor filterFunction, ReduceFunctor reduceFunction, InitialValueType &&initialValue, QtConcurrent::ReduceOptions reduceOptions)
|
||||
\fn template <typename ResultType, typename Sequence, typename KeepFunctor, typename ReduceFunctor, typename InitialValueType> QFuture<ResultType> QtConcurrent::filteredReduced(Sequence &&sequence, KeepFunctor filterFunction, ReduceFunctor reduceFunction, InitialValueType &&initialValue, QtConcurrent::ReduceOptions reduceOptions)
|
||||
|
||||
Calls \a filterFunction once for each item in \a sequence. If
|
||||
\a filterFunction returns \c true for an item, that item is then passed to
|
||||
@ -500,7 +500,7 @@
|
||||
*/
|
||||
|
||||
/*!
|
||||
\fn template <typename Sequence, typename KeepFunctor> Sequence QtConcurrent::blockingFiltered(QThreadPool *pool, const Sequence &sequence, KeepFunctor filterFunction)
|
||||
\fn template <typename Sequence, typename KeepFunctor> Sequence QtConcurrent::blockingFiltered(QThreadPool *pool, Sequence &&sequence, KeepFunctor filterFunction)
|
||||
|
||||
Calls \a filterFunction once for each item in \a sequence and returns a
|
||||
new Sequence of kept items. All calls to \a filterFunction are invoked from the threads
|
||||
@ -514,7 +514,7 @@
|
||||
*/
|
||||
|
||||
/*!
|
||||
\fn template <typename Sequence, typename KeepFunctor> Sequence QtConcurrent::blockingFiltered(const Sequence &sequence, KeepFunctor filterFunction)
|
||||
\fn template <typename Sequence, typename KeepFunctor> Sequence QtConcurrent::blockingFiltered(Sequence &&sequence, KeepFunctor filterFunction)
|
||||
|
||||
Calls \a filterFunction once for each item in \a sequence and returns a
|
||||
new Sequence of kept items. If \a filterFunction returns \c true, a copy of
|
||||
@ -556,7 +556,7 @@
|
||||
*/
|
||||
|
||||
/*!
|
||||
\fn template <typename ResultType, typename Sequence, typename KeepFunctor, typename ReduceFunctor> ResultType QtConcurrent::blockingFilteredReduced(QThreadPool *pool, const Sequence &sequence, KeepFunctor filterFunction, ReduceFunctor reduceFunction, QtConcurrent::ReduceOptions reduceOptions)
|
||||
\fn template <typename ResultType, typename Sequence, typename KeepFunctor, typename ReduceFunctor> ResultType QtConcurrent::blockingFilteredReduced(QThreadPool *pool, Sequence &&sequence, KeepFunctor filterFunction, ReduceFunctor reduceFunction, QtConcurrent::ReduceOptions reduceOptions)
|
||||
|
||||
Calls \a filterFunction once for each item in \a sequence.
|
||||
All calls to \a filterFunction are invoked from the threads taken from the QThreadPool \a pool.
|
||||
@ -577,7 +577,7 @@
|
||||
*/
|
||||
|
||||
/*!
|
||||
\fn template <typename ResultType, typename Sequence, typename KeepFunctor, typename ReduceFunctor> ResultType QtConcurrent::blockingFilteredReduced(const Sequence &sequence, KeepFunctor filterFunction, ReduceFunctor reduceFunction, QtConcurrent::ReduceOptions reduceOptions)
|
||||
\fn template <typename ResultType, typename Sequence, typename KeepFunctor, typename ReduceFunctor> ResultType QtConcurrent::blockingFilteredReduced(Sequence &&sequence, KeepFunctor filterFunction, ReduceFunctor reduceFunction, QtConcurrent::ReduceOptions reduceOptions)
|
||||
|
||||
Calls \a filterFunction once for each item in \a sequence. If
|
||||
\a filterFunction returns \c true for an item, that item is then passed to
|
||||
@ -597,7 +597,7 @@
|
||||
*/
|
||||
|
||||
/*!
|
||||
\fn template <typename ResultType, typename Sequence, typename KeepFunctor, typename ReduceFunctor, typename InitialValueType> ResultType QtConcurrent::blockingFilteredReduced(QThreadPool *pool, const Sequence &sequence, KeepFunctor filterFunction, ReduceFunctor reduceFunction, InitialValueType &&initialValue, QtConcurrent::ReduceOptions reduceOptions)
|
||||
\fn template <typename ResultType, typename Sequence, typename KeepFunctor, typename ReduceFunctor, typename InitialValueType> ResultType QtConcurrent::blockingFilteredReduced(QThreadPool *pool, Sequence &&sequence, KeepFunctor filterFunction, ReduceFunctor reduceFunction, InitialValueType &&initialValue, QtConcurrent::ReduceOptions reduceOptions)
|
||||
|
||||
Calls \a filterFunction once for each item in \a sequence.
|
||||
All calls to \a filterFunction are invoked from the threads taken from the QThreadPool \a pool.
|
||||
@ -621,7 +621,7 @@
|
||||
*/
|
||||
|
||||
/*!
|
||||
\fn template <typename ResultType, typename Sequence, typename KeepFunctor, typename ReduceFunctor, typename InitialValueType> ResultType QtConcurrent::blockingFilteredReduced(const Sequence &sequence, KeepFunctor filterFunction, ReduceFunctor reduceFunction, InitialValueType &&initialValue, QtConcurrent::ReduceOptions reduceOptions)
|
||||
\fn template <typename ResultType, typename Sequence, typename KeepFunctor, typename ReduceFunctor, typename InitialValueType> ResultType QtConcurrent::blockingFilteredReduced(Sequence &&sequence, KeepFunctor filterFunction, ReduceFunctor reduceFunction, InitialValueType &&initialValue, QtConcurrent::ReduceOptions reduceOptions)
|
||||
|
||||
Calls \a filterFunction once for each item in \a sequence. If
|
||||
\a filterFunction returns \c true for an item, that item is then passed to
|
||||
@ -741,12 +741,12 @@
|
||||
*/
|
||||
|
||||
/*!
|
||||
\fn [QtConcurrent-3] ThreadEngineStarter<typename Sequence::value_type> QtConcurrent::startFiltered(QThreadPool *pool, const Sequence &sequence, KeepFunctor functor)
|
||||
\fn [QtConcurrent-3] ThreadEngineStarter<typename Sequence::value_type> QtConcurrent::startFiltered(QThreadPool *pool, Sequence &&sequence, KeepFunctor functor)
|
||||
\internal
|
||||
*/
|
||||
|
||||
/*!
|
||||
\fn [QtConcurrent-4] ThreadEngineStarter<ResultType> QtConcurrent::startFilteredReduced(QThreadPool *pool, const Sequence &sequence, MapFunctor mapFunctor, ReduceFunctor reduceFunctor, ReduceOptions options)
|
||||
\fn [QtConcurrent-4] ThreadEngineStarter<ResultType> QtConcurrent::startFilteredReduced(QThreadPool *pool, Sequence &&sequence, MapFunctor mapFunctor, ReduceFunctor reduceFunctor, ReduceOptions options)
|
||||
\internal
|
||||
*/
|
||||
|
||||
@ -756,7 +756,7 @@
|
||||
*/
|
||||
|
||||
/*!
|
||||
\fn [QtConcurrent-6] ThreadEngineStarter<ResultType> QtConcurrent::startFilteredReduced(QThreadPool *pool, const Sequence &sequence, MapFunctor mapFunctor, ReduceFunctor reduceFunctor, ResultType initialValue, ReduceOptions options)
|
||||
\fn [QtConcurrent-6] ThreadEngineStarter<ResultType> QtConcurrent::startFilteredReduced(QThreadPool *pool, Sequence &&sequence, MapFunctor mapFunctor, ReduceFunctor reduceFunctor, ResultType initialValue, ReduceOptions options)
|
||||
\internal
|
||||
*/
|
||||
|
||||
|
@ -77,78 +77,82 @@ QFuture<void> filter(Sequence &sequence, KeepFunctor keep)
|
||||
// filteredReduced() on sequences
|
||||
template <typename ResultType, typename Sequence, typename KeepFunctor, typename ReduceFunctor>
|
||||
QFuture<ResultType> filteredReduced(QThreadPool *pool,
|
||||
const Sequence &sequence,
|
||||
Sequence &&sequence,
|
||||
KeepFunctor keep,
|
||||
ReduceFunctor reduce,
|
||||
ReduceOptions options = ReduceOptions(UnorderedReduce
|
||||
| SequentialReduce))
|
||||
{
|
||||
return startFilteredReduced<ResultType>(pool, sequence, keep, reduce, options);
|
||||
return startFilteredReduced<ResultType>(pool, std::forward<Sequence>(sequence), keep, reduce,
|
||||
options);
|
||||
}
|
||||
|
||||
template <typename ResultType, typename Sequence, typename KeepFunctor, typename ReduceFunctor>
|
||||
QFuture<ResultType> filteredReduced(const Sequence &sequence,
|
||||
QFuture<ResultType> filteredReduced(Sequence &&sequence,
|
||||
KeepFunctor keep,
|
||||
ReduceFunctor reduce,
|
||||
ReduceOptions options = ReduceOptions(UnorderedReduce
|
||||
| SequentialReduce))
|
||||
{
|
||||
return startFilteredReduced<ResultType>(QThreadPool::globalInstance(),
|
||||
sequence, keep, reduce, options);
|
||||
return startFilteredReduced<ResultType>(
|
||||
QThreadPool::globalInstance(), std::forward<Sequence>(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(QThreadPool *pool,
|
||||
const Sequence &sequence,
|
||||
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);
|
||||
return startFilteredReduced<ResultType>(
|
||||
pool, std::forward<Sequence>(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,
|
||||
QFuture<ResultType> filteredReduced(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);
|
||||
return startFilteredReduced<ResultType>(
|
||||
QThreadPool::globalInstance(), std::forward<Sequence>(sequence), keep, reduce,
|
||||
ResultType(std::forward<InitialValueType>(initialValue)), options);
|
||||
}
|
||||
|
||||
#ifndef Q_CLANG_QDOC
|
||||
template <typename Sequence, typename KeepFunctor, typename ReduceFunctor,
|
||||
typename ResultType = typename QtPrivate::ReduceResultType<ReduceFunctor>::ResultType>
|
||||
QFuture<ResultType> filteredReduced(QThreadPool *pool,
|
||||
const Sequence &sequence,
|
||||
Sequence &&sequence,
|
||||
KeepFunctor keep,
|
||||
ReduceFunctor reduce,
|
||||
ReduceOptions options = ReduceOptions(UnorderedReduce
|
||||
| SequentialReduce))
|
||||
{
|
||||
return startFilteredReduced<ResultType>(pool, sequence, keep, reduce, options);
|
||||
return startFilteredReduced<ResultType>(pool, std::forward<Sequence>(sequence), keep, reduce,
|
||||
options);
|
||||
}
|
||||
|
||||
template <typename Sequence, typename KeepFunctor, typename ReduceFunctor,
|
||||
typename ResultType = typename QtPrivate::ReduceResultType<ReduceFunctor>::ResultType>
|
||||
QFuture<ResultType> filteredReduced(const Sequence &sequence,
|
||||
QFuture<ResultType> filteredReduced(Sequence &&sequence,
|
||||
KeepFunctor keep,
|
||||
ReduceFunctor reduce,
|
||||
ReduceOptions options = ReduceOptions(UnorderedReduce
|
||||
| SequentialReduce))
|
||||
{
|
||||
return startFilteredReduced<ResultType>(QThreadPool::globalInstance(),
|
||||
sequence, keep, reduce, options);
|
||||
return startFilteredReduced<ResultType>(
|
||||
QThreadPool::globalInstance(), std::forward<Sequence>(sequence), keep, reduce, options);
|
||||
}
|
||||
|
||||
template <typename Sequence, typename KeepFunctor, typename ReduceFunctor,
|
||||
@ -156,30 +160,32 @@ template <typename Sequence, typename KeepFunctor, typename ReduceFunctor,
|
||||
typename InitialValueType,
|
||||
std::enable_if_t<std::is_convertible_v<InitialValueType, ResultType>, int> = 0>
|
||||
QFuture<ResultType> filteredReduced(QThreadPool *pool,
|
||||
const Sequence &sequence,
|
||||
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);
|
||||
return startFilteredReduced<ResultType>(
|
||||
pool, std::forward<Sequence>(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,
|
||||
QFuture<ResultType> filteredReduced(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);
|
||||
return startFilteredReduced<ResultType>(
|
||||
QThreadPool::globalInstance(), std::forward<Sequence>(sequence), keep, reduce,
|
||||
ResultType(std::forward<InitialValueType>(initialValue)), options);
|
||||
}
|
||||
#endif
|
||||
|
||||
@ -302,17 +308,16 @@ QFuture<ResultType> filteredReduced(Iterator begin,
|
||||
|
||||
// filtered() on sequences
|
||||
template <typename Sequence, typename KeepFunctor>
|
||||
QFuture<typename Sequence::value_type> filtered(QThreadPool *pool,
|
||||
const Sequence &sequence,
|
||||
KeepFunctor keep)
|
||||
QFuture<typename std::decay_t<Sequence>::value_type> filtered(QThreadPool *pool,
|
||||
Sequence &&sequence, KeepFunctor keep)
|
||||
{
|
||||
return startFiltered(pool, sequence, keep);
|
||||
return startFiltered(pool, std::forward<Sequence>(sequence), keep);
|
||||
}
|
||||
|
||||
template <typename Sequence, typename KeepFunctor>
|
||||
QFuture<typename Sequence::value_type> filtered(const Sequence &sequence, KeepFunctor keep)
|
||||
QFuture<typename std::decay_t<Sequence>::value_type> filtered(Sequence &&sequence, KeepFunctor keep)
|
||||
{
|
||||
return startFiltered(QThreadPool::globalInstance(), sequence, keep);
|
||||
return startFiltered(QThreadPool::globalInstance(), std::forward<Sequence>(sequence), keep);
|
||||
}
|
||||
|
||||
// filtered() on iterators
|
||||
@ -352,26 +357,26 @@ void blockingFilter(Sequence &sequence, KeepFunctor keep)
|
||||
// blocking filteredReduced() on sequences
|
||||
template <typename ResultType, typename Sequence, typename KeepFunctor, typename ReduceFunctor>
|
||||
ResultType blockingFilteredReduced(QThreadPool *pool,
|
||||
const Sequence &sequence,
|
||||
Sequence &&sequence,
|
||||
KeepFunctor keep,
|
||||
ReduceFunctor reduce,
|
||||
ReduceOptions options = ReduceOptions(UnorderedReduce
|
||||
| SequentialReduce))
|
||||
{
|
||||
QFuture<ResultType> future = startFilteredReduced<ResultType>(pool, sequence, keep,
|
||||
reduce, options);
|
||||
QFuture<ResultType> future = startFilteredReduced<ResultType>(
|
||||
pool, std::forward<Sequence>(sequence), keep, reduce, options);
|
||||
return future.result();
|
||||
}
|
||||
|
||||
template <typename ResultType, typename Sequence, typename KeepFunctor, typename ReduceFunctor>
|
||||
ResultType blockingFilteredReduced(const Sequence &sequence,
|
||||
ResultType blockingFilteredReduced(Sequence &&sequence,
|
||||
KeepFunctor keep,
|
||||
ReduceFunctor reduce,
|
||||
ReduceOptions options = ReduceOptions(UnorderedReduce
|
||||
| SequentialReduce))
|
||||
{
|
||||
QFuture<ResultType> future = startFilteredReduced<ResultType>(QThreadPool::globalInstance(),
|
||||
sequence, keep, reduce, options);
|
||||
QFuture<ResultType> future = startFilteredReduced<ResultType>(
|
||||
QThreadPool::globalInstance(), std::forward<Sequence>(sequence), keep, reduce, options);
|
||||
return future.result();
|
||||
}
|
||||
|
||||
@ -379,30 +384,32 @@ template <typename ResultType, typename Sequence, typename KeepFunctor, typename
|
||||
typename InitialValueType,
|
||||
std::enable_if_t<std::is_convertible_v<InitialValueType, ResultType>, int> = 0>
|
||||
ResultType blockingFilteredReduced(QThreadPool *pool,
|
||||
const Sequence &sequence,
|
||||
Sequence &&sequence,
|
||||
KeepFunctor keep,
|
||||
ReduceFunctor reduce,
|
||||
InitialValueType &&initialValue,
|
||||
ReduceOptions options = ReduceOptions(UnorderedReduce
|
||||
| SequentialReduce))
|
||||
{
|
||||
QFuture<ResultType> future = startFilteredReduced<ResultType>(pool, sequence, keep, reduce,
|
||||
ResultType(std::forward<InitialValueType>(initialValue)), options);
|
||||
QFuture<ResultType> future = startFilteredReduced<ResultType>(
|
||||
pool, std::forward<Sequence>(sequence), keep, reduce,
|
||||
ResultType(std::forward<InitialValueType>(initialValue)), options);
|
||||
return future.result();
|
||||
}
|
||||
|
||||
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,
|
||||
ResultType blockingFilteredReduced(Sequence &&sequence,
|
||||
KeepFunctor keep,
|
||||
ReduceFunctor reduce,
|
||||
InitialValueType &&initialValue,
|
||||
ReduceOptions options = ReduceOptions(UnorderedReduce
|
||||
| SequentialReduce))
|
||||
{
|
||||
QFuture<ResultType> future = startFilteredReduced<ResultType>(QThreadPool::globalInstance(),
|
||||
sequence, keep, reduce, ResultType(std::forward<InitialValueType>(initialValue)), options);
|
||||
QFuture<ResultType> future = startFilteredReduced<ResultType>(
|
||||
QThreadPool::globalInstance(), std::forward<Sequence>(sequence), keep, reduce,
|
||||
ResultType(std::forward<InitialValueType>(initialValue)), options);
|
||||
return future.result();
|
||||
}
|
||||
|
||||
@ -410,27 +417,27 @@ ResultType blockingFilteredReduced(const Sequence &sequence,
|
||||
template <typename Sequence, typename KeepFunctor, typename ReduceFunctor,
|
||||
typename ResultType = typename QtPrivate::ReduceResultType<ReduceFunctor>::ResultType>
|
||||
ResultType blockingFilteredReduced(QThreadPool *pool,
|
||||
const Sequence &sequence,
|
||||
Sequence &&sequence,
|
||||
KeepFunctor keep,
|
||||
ReduceFunctor reduce,
|
||||
ReduceOptions options = ReduceOptions(UnorderedReduce
|
||||
| SequentialReduce))
|
||||
{
|
||||
QFuture<ResultType> future = startFilteredReduced<ResultType>(pool, sequence, keep,
|
||||
reduce, options);
|
||||
QFuture<ResultType> future = startFilteredReduced<ResultType>(
|
||||
pool, std::forward<Sequence>(sequence), keep, reduce, options);
|
||||
return future.result();
|
||||
}
|
||||
|
||||
template <typename Sequence, typename KeepFunctor, typename ReduceFunctor,
|
||||
typename ResultType = typename QtPrivate::ReduceResultType<ReduceFunctor>::ResultType>
|
||||
ResultType blockingFilteredReduced(const Sequence &sequence,
|
||||
ResultType blockingFilteredReduced(Sequence &&sequence,
|
||||
KeepFunctor keep,
|
||||
ReduceFunctor reduce,
|
||||
ReduceOptions options = ReduceOptions(UnorderedReduce
|
||||
| SequentialReduce))
|
||||
{
|
||||
QFuture<ResultType> future = startFilteredReduced<ResultType>(QThreadPool::globalInstance(),
|
||||
sequence, keep, reduce, options);
|
||||
QFuture<ResultType> future = startFilteredReduced<ResultType>(
|
||||
QThreadPool::globalInstance(), std::forward<Sequence>(sequence), keep, reduce, options);
|
||||
return future.result();
|
||||
}
|
||||
|
||||
@ -439,15 +446,16 @@ template <typename Sequence, typename KeepFunctor, typename ReduceFunctor,
|
||||
typename InitialValueType,
|
||||
std::enable_if_t<std::is_convertible_v<InitialValueType, ResultType>, int> = 0>
|
||||
ResultType blockingFilteredReduced(QThreadPool *pool,
|
||||
const Sequence &sequence,
|
||||
Sequence &&sequence,
|
||||
KeepFunctor keep,
|
||||
ReduceFunctor reduce,
|
||||
InitialValueType &&initialValue,
|
||||
ReduceOptions options = ReduceOptions(UnorderedReduce
|
||||
| SequentialReduce))
|
||||
{
|
||||
QFuture<ResultType> future = startFilteredReduced<ResultType>(pool, sequence, keep, reduce,
|
||||
ResultType(std::forward<InitialValueType>(initialValue)), options);
|
||||
QFuture<ResultType> future = startFilteredReduced<ResultType>(
|
||||
pool, std::forward<Sequence>(sequence), keep, reduce,
|
||||
ResultType(std::forward<InitialValueType>(initialValue)), options);
|
||||
return future.result();
|
||||
}
|
||||
|
||||
@ -455,15 +463,16 @@ 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,
|
||||
ResultType blockingFilteredReduced(Sequence &&sequence,
|
||||
KeepFunctor keep,
|
||||
ReduceFunctor reduce,
|
||||
InitialValueType &&initialValue,
|
||||
ReduceOptions options = ReduceOptions(UnorderedReduce
|
||||
| SequentialReduce))
|
||||
{
|
||||
QFuture<ResultType> future = startFilteredReduced<ResultType>(QThreadPool::globalInstance(),
|
||||
sequence, keep, reduce, ResultType(std::forward<InitialValueType>(initialValue)), options);
|
||||
QFuture<ResultType> future = startFilteredReduced<ResultType>(
|
||||
QThreadPool::globalInstance(), std::forward<Sequence>(sequence), keep, reduce,
|
||||
ResultType(std::forward<InitialValueType>(initialValue)), options);
|
||||
return future.result();
|
||||
}
|
||||
#endif
|
||||
@ -596,17 +605,19 @@ ResultType blockingFilteredReduced(Iterator begin,
|
||||
|
||||
// blocking filtered() on sequences
|
||||
template <typename Sequence, typename KeepFunctor>
|
||||
Sequence blockingFiltered(QThreadPool *pool, const Sequence &sequence, KeepFunctor keep)
|
||||
auto blockingFiltered(QThreadPool *pool, Sequence &&sequence, KeepFunctor keep)
|
||||
{
|
||||
return blockingFilteredReduced<Sequence>(pool, sequence, keep, QtPrivate::PushBackWrapper(),
|
||||
OrderedReduce);
|
||||
return blockingFilteredReduced<std::decay_t<Sequence>>(
|
||||
pool, std::forward<Sequence>(sequence), keep, QtPrivate::PushBackWrapper(),
|
||||
OrderedReduce);
|
||||
}
|
||||
|
||||
template <typename Sequence, typename KeepFunctor>
|
||||
Sequence blockingFiltered(const Sequence &sequence, KeepFunctor keep)
|
||||
auto blockingFiltered(Sequence &&sequence, KeepFunctor keep)
|
||||
{
|
||||
return blockingFilteredReduced<Sequence>(QThreadPool::globalInstance(), sequence, keep,
|
||||
QtPrivate::PushBackWrapper(), OrderedReduce);
|
||||
return blockingFilteredReduced<std::decay_t<Sequence>>(
|
||||
QThreadPool::globalInstance(), std::forward<Sequence>(sequence), keep,
|
||||
QtPrivate::PushBackWrapper(), OrderedReduce);
|
||||
}
|
||||
|
||||
// blocking filtered() on iterators
|
||||
|
@ -308,33 +308,35 @@ startFiltered(QThreadPool *pool, Iterator begin, Iterator end, KeepFunctor funct
|
||||
|
||||
//! [QtConcurrent-3]
|
||||
template <typename Sequence, typename KeepFunctor>
|
||||
inline ThreadEngineStarter<typename Sequence::value_type>
|
||||
startFiltered(QThreadPool *pool, const Sequence &sequence, KeepFunctor functor)
|
||||
inline decltype(auto) startFiltered(QThreadPool *pool, Sequence &&sequence, KeepFunctor functor)
|
||||
{
|
||||
typedef SequenceHolder1<Sequence,
|
||||
FilteredEachKernel<typename Sequence::const_iterator, KeepFunctor>,
|
||||
using DecayedSequence = std::decay_t<Sequence>;
|
||||
typedef SequenceHolder1<DecayedSequence,
|
||||
FilteredEachKernel<typename DecayedSequence::const_iterator, KeepFunctor>,
|
||||
KeepFunctor>
|
||||
SequenceHolderType;
|
||||
return startThreadEngine(new SequenceHolderType(pool, sequence, functor));
|
||||
SequenceHolderType;
|
||||
return startThreadEngine(
|
||||
new SequenceHolderType(pool, std::forward<Sequence>(sequence), functor));
|
||||
}
|
||||
|
||||
//! [QtConcurrent-4]
|
||||
template <typename ResultType, typename Sequence, typename MapFunctor, typename ReduceFunctor>
|
||||
inline ThreadEngineStarter<ResultType> startFilteredReduced(QThreadPool *pool,
|
||||
const Sequence &sequence,
|
||||
Sequence &&sequence,
|
||||
MapFunctor mapFunctor,
|
||||
ReduceFunctor reduceFunctor,
|
||||
ReduceOptions options)
|
||||
{
|
||||
typedef typename Sequence::const_iterator Iterator;
|
||||
using DecayedSequence = std::decay_t<Sequence>;
|
||||
typedef typename DecayedSequence::const_iterator Iterator;
|
||||
typedef ReduceKernel<ReduceFunctor, ResultType, typename qValueType<Iterator>::value_type >
|
||||
Reducer;
|
||||
typedef FilteredReducedKernel<ResultType, Iterator, MapFunctor, ReduceFunctor, Reducer>
|
||||
FilteredReduceType;
|
||||
typedef SequenceHolder2<Sequence, FilteredReduceType, MapFunctor, ReduceFunctor>
|
||||
typedef SequenceHolder2<DecayedSequence, FilteredReduceType, MapFunctor, ReduceFunctor>
|
||||
SequenceHolderType;
|
||||
return startThreadEngine(new SequenceHolderType(pool, sequence, mapFunctor,
|
||||
reduceFunctor, options));
|
||||
return startThreadEngine(new SequenceHolderType(pool, std::forward<Sequence>(sequence),
|
||||
mapFunctor, reduceFunctor, options));
|
||||
}
|
||||
|
||||
|
||||
@ -359,21 +361,23 @@ inline ThreadEngineStarter<ResultType> startFilteredReduced(QThreadPool *pool,
|
||||
//! [QtConcurrent-6]
|
||||
template <typename ResultType, typename Sequence, typename MapFunctor, typename ReduceFunctor>
|
||||
inline ThreadEngineStarter<ResultType> startFilteredReduced(QThreadPool *pool,
|
||||
const Sequence &sequence,
|
||||
Sequence &&sequence,
|
||||
MapFunctor mapFunctor,
|
||||
ReduceFunctor reduceFunctor,
|
||||
ResultType &&initialValue,
|
||||
ReduceOptions options)
|
||||
{
|
||||
typedef typename Sequence::const_iterator Iterator;
|
||||
using DecayedSequence = std::decay_t<Sequence>;
|
||||
typedef typename DecayedSequence::const_iterator Iterator;
|
||||
typedef ReduceKernel<ReduceFunctor, ResultType, typename qValueType<Iterator>::value_type >
|
||||
Reducer;
|
||||
typedef FilteredReducedKernel<ResultType, Iterator, MapFunctor, ReduceFunctor, Reducer>
|
||||
FilteredReduceType;
|
||||
typedef SequenceHolder2<Sequence, FilteredReduceType, MapFunctor, ReduceFunctor>
|
||||
typedef SequenceHolder2<DecayedSequence, FilteredReduceType, MapFunctor, ReduceFunctor>
|
||||
SequenceHolderType;
|
||||
return startThreadEngine(new SequenceHolderType(pool, sequence, mapFunctor, reduceFunctor,
|
||||
std::forward<ResultType>(initialValue), options));
|
||||
return startThreadEngine(
|
||||
new SequenceHolderType(pool, std::forward<Sequence>(sequence), mapFunctor,
|
||||
reduceFunctor, std::forward<ResultType>(initialValue), options));
|
||||
}
|
||||
|
||||
//! [QtConcurrent-7]
|
||||
|
@ -168,6 +168,7 @@ template<typename Sequence>
|
||||
struct SequenceHolder
|
||||
{
|
||||
SequenceHolder(const Sequence &s) : sequence(s) { }
|
||||
SequenceHolder(Sequence &&s) : sequence(std::move(s)) { }
|
||||
Sequence sequence;
|
||||
};
|
||||
|
||||
|
@ -104,12 +104,12 @@
|
||||
*/
|
||||
|
||||
/*!
|
||||
\fn [qtconcurrentmapkernel-3] ThreadEngineStarter<T> QtConcurrent::startMapped(const Sequence &sequence, Functor functor)
|
||||
\fn [qtconcurrentmapkernel-3] ThreadEngineStarter<T> QtConcurrent::startMapped(Sequence &&sequence, Functor functor)
|
||||
\internal
|
||||
*/
|
||||
|
||||
/*!
|
||||
\fn [qtconcurrentmapkernel-4] ThreadEngineStarter<ResultType> QtConcurrent::startMappedReduced(const Sequence & sequence, MapFunctor mapFunctor, ReduceFunctor reduceFunctor, ReduceOptions options)
|
||||
\fn [qtconcurrentmapkernel-4] ThreadEngineStarter<ResultType> QtConcurrent::startMappedReduced(Sequence && sequence, MapFunctor mapFunctor, ReduceFunctor reduceFunctor, ReduceOptions options)
|
||||
\internal
|
||||
*/
|
||||
|
||||
@ -119,7 +119,7 @@
|
||||
*/
|
||||
|
||||
/*!
|
||||
\fn [qtconcurrentmapkernel-6] ThreadEngineStarter<ResultType> QtConcurrent::startMappedReduced(const Sequence & sequence, MapFunctor mapFunctor, ReduceFunctor reduceFunctor, ResultType &&initialValue, ReduceOptions options)
|
||||
\fn [qtconcurrentmapkernel-6] ThreadEngineStarter<ResultType> QtConcurrent::startMappedReduced(Sequence && sequence, MapFunctor mapFunctor, ReduceFunctor reduceFunctor, ResultType &&initialValue, ReduceOptions options)
|
||||
\internal
|
||||
*/
|
||||
|
||||
@ -320,7 +320,7 @@
|
||||
*/
|
||||
|
||||
/*!
|
||||
\fn template <typename Sequence, typename MapFunctor> QFuture<void> QtConcurrent::map(QThreadPool *pool, Sequence &sequence, MapFunctor function)
|
||||
\fn template <typename Sequence, typename MapFunctor> QFuture<void> QtConcurrent::map(QThreadPool *pool, Sequence &&sequence, MapFunctor function)
|
||||
|
||||
Calls \a function once for each item in \a sequence.
|
||||
All calls to \a function are invoked from the threads taken from the QThreadPool \a pool.
|
||||
@ -331,7 +331,7 @@
|
||||
*/
|
||||
|
||||
/*!
|
||||
\fn template <typename Sequence, typename MapFunctor> QFuture<void> QtConcurrent::map(Sequence &sequence, MapFunctor function)
|
||||
\fn template <typename Sequence, typename MapFunctor> QFuture<void> QtConcurrent::map(Sequence &&sequence, MapFunctor function)
|
||||
|
||||
Calls \a function once for each item in \a sequence. The \a function takes
|
||||
a reference to the item, so that any modifications done to the item
|
||||
@ -362,7 +362,7 @@
|
||||
*/
|
||||
|
||||
/*!
|
||||
\fn template <typename Sequence, typename MapFunctor> QFuture<QtPrivate::MapResultType<Sequence, MapFunctor>> QtConcurrent::mapped(QThreadPool *pool, const Sequence &sequence, MapFunctor function)
|
||||
\fn template <typename Sequence, typename MapFunctor> QFuture<QtPrivate::MapResultType<Sequence, MapFunctor>> QtConcurrent::mapped(QThreadPool *pool, Sequence &&sequence, MapFunctor function)
|
||||
|
||||
Calls \a function once for each item in \a sequence and returns a future
|
||||
with each mapped item as a result. All calls to \a function are invoked from the
|
||||
@ -373,7 +373,7 @@
|
||||
*/
|
||||
|
||||
/*!
|
||||
\fn template <typename Sequence, typename MapFunctor> QFuture<QtPrivate::MapResultType<Sequence, MapFunctor>> QtConcurrent::mapped(const Sequence &sequence, MapFunctor function)
|
||||
\fn template <typename Sequence, typename MapFunctor> QFuture<QtPrivate::MapResultType<Sequence, MapFunctor>> QtConcurrent::mapped(Sequence &&sequence, MapFunctor function)
|
||||
|
||||
Calls \a function once for each item in \a sequence and returns a future
|
||||
with each mapped item as a result. You can use QFuture::const_iterator or
|
||||
@ -404,7 +404,7 @@
|
||||
*/
|
||||
|
||||
/*!
|
||||
\fn template <typename ResultType, typename Sequence, typename MapFunctor, typename ReduceFunctor> QFuture<ResultType> QtConcurrent::mappedReduced(QThreadPool *pool, const Sequence &sequence, MapFunctor mapFunction, ReduceFunctor reduceFunction, QtConcurrent::ReduceOptions reduceOptions)
|
||||
\fn template <typename ResultType, typename Sequence, typename MapFunctor, typename ReduceFunctor> QFuture<ResultType> QtConcurrent::mappedReduced(QThreadPool *pool, Sequence &&sequence, MapFunctor mapFunction, ReduceFunctor reduceFunction, QtConcurrent::ReduceOptions reduceOptions)
|
||||
|
||||
Calls \a mapFunction once for each item in \a sequence.
|
||||
All calls to \a mapFunction are invoked from the threads taken from the QThreadPool \a pool.
|
||||
@ -418,7 +418,7 @@
|
||||
*/
|
||||
|
||||
/*!
|
||||
\fn template <typename ResultType, typename Sequence, typename MapFunctor, typename ReduceFunctor> QFuture<ResultType> QtConcurrent::mappedReduced(const Sequence &sequence, MapFunctor mapFunction, ReduceFunctor reduceFunction, QtConcurrent::ReduceOptions reduceOptions)
|
||||
\fn template <typename ResultType, typename Sequence, typename MapFunctor, typename ReduceFunctor> QFuture<ResultType> QtConcurrent::mappedReduced(Sequence &&sequence, MapFunctor mapFunction, ReduceFunctor reduceFunction, QtConcurrent::ReduceOptions reduceOptions)
|
||||
|
||||
Calls \a mapFunction once for each item in \a sequence. The return value of
|
||||
each \a mapFunction is passed to \a reduceFunction.
|
||||
@ -431,7 +431,7 @@
|
||||
*/
|
||||
|
||||
/*!
|
||||
\fn template <typename ResultType, typename Sequence, typename MapFunctor, typename ReduceFunctor, typename InitialValueType> QFuture<ResultType> QtConcurrent::mappedReduced(QThreadPool *pool, const Sequence &sequence, MapFunctor mapFunction, ReduceFunctor reduceFunction, InitialValueType &&initialValue, QtConcurrent::ReduceOptions reduceOptions)
|
||||
\fn template <typename ResultType, typename Sequence, typename MapFunctor, typename ReduceFunctor, typename InitialValueType> QFuture<ResultType> QtConcurrent::mappedReduced(QThreadPool *pool, Sequence &&sequence, MapFunctor mapFunction, ReduceFunctor reduceFunction, InitialValueType &&initialValue, QtConcurrent::ReduceOptions reduceOptions)
|
||||
|
||||
Calls \a mapFunction once for each item in \a sequence.
|
||||
All calls to \a mapFunction are invoked from the threads taken from the QThreadPool \a pool.
|
||||
@ -448,7 +448,7 @@
|
||||
*/
|
||||
|
||||
/*!
|
||||
\fn template <typename ResultType, typename Sequence, typename MapFunctor, typename ReduceFunctor, typename InitialValueType> QFuture<ResultType> QtConcurrent::mappedReduced(const Sequence &sequence, MapFunctor mapFunction, ReduceFunctor reduceFunction, InitialValueType &&initialValue, QtConcurrent::ReduceOptions reduceOptions)
|
||||
\fn template <typename ResultType, typename Sequence, typename MapFunctor, typename ReduceFunctor, typename InitialValueType> QFuture<ResultType> QtConcurrent::mappedReduced(Sequence &&sequence, MapFunctor mapFunction, ReduceFunctor reduceFunction, InitialValueType &&initialValue, QtConcurrent::ReduceOptions reduceOptions)
|
||||
|
||||
Calls \a mapFunction once for each item in \a sequence. The return value of
|
||||
each \a mapFunction is passed to \a reduceFunction.
|
||||
@ -532,7 +532,7 @@
|
||||
*/
|
||||
|
||||
/*!
|
||||
\fn template <typename Sequence, typename MapFunctor> void QtConcurrent::blockingMap(QThreadPool *pool, Sequence &sequence, MapFunctor function)
|
||||
\fn template <typename Sequence, typename MapFunctor> void QtConcurrent::blockingMap(QThreadPool *pool, Sequence &&sequence, MapFunctor function)
|
||||
|
||||
Calls \a function once for each item in \a sequence.
|
||||
All calls to \a function are invoked from the threads taken from the QThreadPool \a pool.
|
||||
@ -545,7 +545,7 @@
|
||||
*/
|
||||
|
||||
/*!
|
||||
\fn template <typename Sequence, typename MapFunctor> void QtConcurrent::blockingMap(Sequence &sequence, MapFunctor function)
|
||||
\fn template <typename Sequence, typename MapFunctor> void QtConcurrent::blockingMap(Sequence &&sequence, MapFunctor function)
|
||||
|
||||
Calls \a function once for each item in \a sequence. The \a function takes
|
||||
a reference to the item, so that any modifications done to the item
|
||||
@ -584,7 +584,7 @@
|
||||
*/
|
||||
|
||||
/*!
|
||||
\fn template <typename OutputSequence, typename InputSequence, typename MapFunctor> OutputSequence QtConcurrent::blockingMapped(QThreadPool *pool, const InputSequence &sequence, MapFunctor function)
|
||||
\fn template <typename OutputSequence, typename InputSequence, typename MapFunctor> OutputSequence QtConcurrent::blockingMapped(QThreadPool *pool, InputSequence &&sequence, MapFunctor function)
|
||||
|
||||
Calls \a function once for each item in \a sequence and returns an OutputSequence containing
|
||||
the results. All calls to \a function are invoked from the threads taken from the QThreadPool
|
||||
@ -596,7 +596,7 @@
|
||||
*/
|
||||
|
||||
/*!
|
||||
\fn template <typename OutputSequence, typename InputSequence, typename MapFunctor> OutputSequence QtConcurrent::blockingMapped(const InputSequence &sequence, MapFunctor function)
|
||||
\fn template <typename OutputSequence, typename InputSequence, typename MapFunctor> OutputSequence QtConcurrent::blockingMapped(const InputSequence &&sequence, MapFunctor function)
|
||||
|
||||
Calls \a function once for each item in \a sequence and returns an OutputSequence containing
|
||||
the results. The type of the results will match the type returned my the MapFunctor.
|
||||
@ -642,7 +642,7 @@
|
||||
*/
|
||||
|
||||
/*!
|
||||
\fn template <typename ResultType, typename Sequence, typename MapFunctor, typename ReduceFunctor> ResultType QtConcurrent::blockingMappedReduced(QThreadPool *pool, const Sequence &sequence, MapFunctor mapFunction, ReduceFunctor reduceFunction, QtConcurrent::ReduceOptions reduceOptions)
|
||||
\fn template <typename ResultType, typename Sequence, typename MapFunctor, typename ReduceFunctor> ResultType QtConcurrent::blockingMappedReduced(QThreadPool *pool, Sequence &&sequence, MapFunctor mapFunction, ReduceFunctor reduceFunction, QtConcurrent::ReduceOptions reduceOptions)
|
||||
|
||||
Calls \a mapFunction once for each item in \a sequence.
|
||||
All calls to \a mapFunction are invoked from the threads taken from the QThreadPool \a pool.
|
||||
@ -658,7 +658,7 @@
|
||||
*/
|
||||
|
||||
/*!
|
||||
\fn template <typename ResultType, typename Sequence, typename MapFunctor, typename ReduceFunctor> ResultType QtConcurrent::blockingMappedReduced(const Sequence &sequence, MapFunctor mapFunction, ReduceFunctor reduceFunction, QtConcurrent::ReduceOptions reduceOptions)
|
||||
\fn template <typename ResultType, typename Sequence, typename MapFunctor, typename ReduceFunctor> ResultType QtConcurrent::blockingMappedReduced(Sequence &&sequence, MapFunctor mapFunction, ReduceFunctor reduceFunction, QtConcurrent::ReduceOptions reduceOptions)
|
||||
|
||||
Calls \a mapFunction once for each item in \a sequence. The return value of
|
||||
each \a mapFunction is passed to \a reduceFunction.
|
||||
@ -673,7 +673,7 @@
|
||||
*/
|
||||
|
||||
/*!
|
||||
\fn template <typename ResultType, typename Sequence, typename MapFunctor, typename ReduceFunctor, typename InitialValueType> ResultType QtConcurrent::blockingMappedReduced(QThreadPool *pool, const Sequence &sequence, MapFunctor mapFunction, ReduceFunctor reduceFunction, InitialValueType &&initialValue, QtConcurrent::ReduceOptions reduceOptions)
|
||||
\fn template <typename ResultType, typename Sequence, typename MapFunctor, typename ReduceFunctor, typename InitialValueType> ResultType QtConcurrent::blockingMappedReduced(QThreadPool *pool, Sequence &&sequence, MapFunctor mapFunction, ReduceFunctor reduceFunction, InitialValueType &&initialValue, QtConcurrent::ReduceOptions reduceOptions)
|
||||
|
||||
Calls \a mapFunction once for each item in \a sequence.
|
||||
All calls to \a mapFunction are invoked from the threads taken from the QThreadPool \a pool.
|
||||
@ -692,7 +692,7 @@
|
||||
*/
|
||||
|
||||
/*!
|
||||
\fn template <typename ResultType, typename Sequence, typename MapFunctor, typename ReduceFunctor, typename InitialValueType> ResultType QtConcurrent::blockingMappedReduced(const Sequence &sequence, MapFunctor mapFunction, ReduceFunctor reduceFunction, InitialValueType &&initialValue, QtConcurrent::ReduceOptions reduceOptions)
|
||||
\fn template <typename ResultType, typename Sequence, typename MapFunctor, typename ReduceFunctor, typename InitialValueType> ResultType QtConcurrent::blockingMappedReduced(Sequence &&sequence, MapFunctor mapFunction, ReduceFunctor reduceFunction, InitialValueType &&initialValue, QtConcurrent::ReduceOptions reduceOptions)
|
||||
|
||||
Calls \a mapFunction once for each item in \a sequence. The return value of
|
||||
each \a mapFunction is passed to \a reduceFunction.
|
||||
|
@ -57,13 +57,13 @@ namespace QtConcurrent {
|
||||
|
||||
// map() on sequences
|
||||
template <typename Sequence, typename MapFunctor>
|
||||
QFuture<void> map(QThreadPool *pool, Sequence &sequence, MapFunctor map)
|
||||
QFuture<void> map(QThreadPool *pool, Sequence &&sequence, MapFunctor map)
|
||||
{
|
||||
return startMap(pool, sequence.begin(), sequence.end(), map);
|
||||
}
|
||||
|
||||
template <typename Sequence, typename MapFunctor>
|
||||
QFuture<void> map(Sequence &sequence, MapFunctor map)
|
||||
QFuture<void> map(Sequence &&sequence, MapFunctor map)
|
||||
{
|
||||
return startMap(QThreadPool::globalInstance(), sequence.begin(), sequence.end(), map);
|
||||
}
|
||||
@ -84,47 +84,47 @@ QFuture<void> map(Iterator begin, Iterator end, MapFunctor map)
|
||||
// mappedReduced() for sequences.
|
||||
template <typename ResultType, typename Sequence, typename MapFunctor, typename ReduceFunctor>
|
||||
QFuture<ResultType> mappedReduced(QThreadPool *pool,
|
||||
const Sequence &sequence,
|
||||
Sequence &&sequence,
|
||||
MapFunctor map,
|
||||
ReduceFunctor reduce,
|
||||
ReduceOptions options = ReduceOptions(UnorderedReduce
|
||||
| SequentialReduce))
|
||||
{
|
||||
return startMappedReduced<QtPrivate::MapResultType<Sequence, MapFunctor>, ResultType>
|
||||
(pool, sequence, map, reduce, options);
|
||||
(pool, std::forward<Sequence>(sequence), map, reduce, options);
|
||||
}
|
||||
|
||||
template <typename ResultType, typename Sequence, typename MapFunctor, typename ReduceFunctor>
|
||||
QFuture<ResultType> mappedReduced(const Sequence &sequence,
|
||||
QFuture<ResultType> mappedReduced(Sequence &&sequence,
|
||||
MapFunctor map,
|
||||
ReduceFunctor reduce,
|
||||
ReduceOptions options = ReduceOptions(UnorderedReduce
|
||||
| SequentialReduce))
|
||||
{
|
||||
return startMappedReduced<QtPrivate::MapResultType<Sequence, MapFunctor>, ResultType>
|
||||
(QThreadPool::globalInstance(), sequence, map, reduce, options);
|
||||
(QThreadPool::globalInstance(), std::forward<Sequence>(sequence), map, reduce, options);
|
||||
}
|
||||
|
||||
template <typename ResultType, typename Sequence, typename MapFunctor, typename ReduceFunctor,
|
||||
typename InitialValueType,
|
||||
std::enable_if_t<std::is_convertible_v<InitialValueType, ResultType>, int> = 0>
|
||||
QFuture<ResultType> mappedReduced(QThreadPool *pool,
|
||||
const Sequence &sequence,
|
||||
Sequence &&sequence,
|
||||
MapFunctor map,
|
||||
ReduceFunctor reduce,
|
||||
InitialValueType &&initialValue,
|
||||
ReduceOptions options = ReduceOptions(UnorderedReduce
|
||||
| SequentialReduce))
|
||||
{
|
||||
return startMappedReduced<QtPrivate::MapResultType<Sequence, MapFunctor>, ResultType>
|
||||
(pool, sequence, map, reduce, ResultType(std::forward<InitialValueType>(initialValue)),
|
||||
options);
|
||||
return startMappedReduced<QtPrivate::MapResultType<Sequence, MapFunctor>, ResultType>(
|
||||
pool, std::forward<Sequence>(sequence), map, reduce,
|
||||
ResultType(std::forward<InitialValueType>(initialValue)), options);
|
||||
}
|
||||
|
||||
template <typename ResultType, typename Sequence, typename MapFunctor, typename ReduceFunctor,
|
||||
typename InitialValueType,
|
||||
std::enable_if_t<std::is_convertible_v<InitialValueType, ResultType>, int> = 0>
|
||||
QFuture<ResultType> mappedReduced(const Sequence &sequence,
|
||||
QFuture<ResultType> mappedReduced(Sequence &&sequence,
|
||||
MapFunctor map,
|
||||
ReduceFunctor reduce,
|
||||
InitialValueType &&initialValue,
|
||||
@ -132,34 +132,34 @@ QFuture<ResultType> mappedReduced(const Sequence &sequence,
|
||||
| SequentialReduce))
|
||||
{
|
||||
return startMappedReduced<QtPrivate::MapResultType<Sequence, MapFunctor>, ResultType>
|
||||
(QThreadPool::globalInstance(), sequence, map, reduce,
|
||||
(QThreadPool::globalInstance(), std::forward<Sequence>(sequence), map, reduce,
|
||||
ResultType(std::forward<InitialValueType>(initialValue)), options);
|
||||
}
|
||||
|
||||
template <typename Sequence, typename MapFunctor, typename ReduceFunctor,
|
||||
typename ResultType = typename QtPrivate::ReduceResultType<ReduceFunctor>::ResultType>
|
||||
QFuture<ResultType> mappedReduced(QThreadPool *pool,
|
||||
const Sequence &sequence,
|
||||
Sequence &&sequence,
|
||||
MapFunctor map,
|
||||
ReduceFunctor reduce,
|
||||
ReduceOptions options = ReduceOptions(UnorderedReduce
|
||||
| SequentialReduce))
|
||||
{
|
||||
return startMappedReduced<QtPrivate::MapResultType<Sequence, MapFunctor>, ResultType>
|
||||
(pool, sequence, map, reduce, options);
|
||||
(pool, std::forward<Sequence>(sequence), map, reduce, options);
|
||||
}
|
||||
|
||||
template <typename Sequence, typename MapFunctor, typename ReduceFunctor,
|
||||
typename ResultType = typename QtPrivate::ReduceResultType<ReduceFunctor>::ResultType>
|
||||
QFuture<ResultType> mappedReduced(
|
||||
const Sequence &sequence,
|
||||
Sequence &&sequence,
|
||||
MapFunctor map,
|
||||
ReduceFunctor reduce,
|
||||
ReduceOptions options = ReduceOptions(UnorderedReduce
|
||||
| SequentialReduce))
|
||||
{
|
||||
return startMappedReduced<QtPrivate::MapResultType<Sequence, MapFunctor>, ResultType>
|
||||
(QThreadPool::globalInstance(), sequence, map, reduce, options);
|
||||
(QThreadPool::globalInstance(), std::forward<Sequence>(sequence), map, reduce, options);
|
||||
}
|
||||
|
||||
template <typename Sequence, typename MapFunctor, typename ReduceFunctor,
|
||||
@ -167,23 +167,23 @@ template <typename Sequence, typename MapFunctor, typename ReduceFunctor,
|
||||
typename InitialValueType,
|
||||
std::enable_if_t<std::is_convertible_v<InitialValueType, ResultType>, int> = 0>
|
||||
QFuture<ResultType> mappedReduced(QThreadPool *pool,
|
||||
const Sequence &sequence,
|
||||
Sequence &&sequence,
|
||||
MapFunctor map,
|
||||
ReduceFunctor reduce,
|
||||
InitialValueType &&initialValue,
|
||||
ReduceOptions options = ReduceOptions(UnorderedReduce
|
||||
| SequentialReduce))
|
||||
{
|
||||
return startMappedReduced<QtPrivate::MapResultType<Sequence, MapFunctor>, ResultType>
|
||||
(pool, sequence, map, reduce, ResultType(std::forward<InitialValueType>(initialValue)),
|
||||
options);
|
||||
return startMappedReduced<QtPrivate::MapResultType<Sequence, MapFunctor>, ResultType>(
|
||||
pool, std::forward<Sequence>(sequence), map, reduce,
|
||||
ResultType(std::forward<InitialValueType>(initialValue)), options);
|
||||
}
|
||||
|
||||
template <typename Sequence, typename MapFunctor, 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> mappedReduced(const Sequence &sequence,
|
||||
QFuture<ResultType> mappedReduced(Sequence &&sequence,
|
||||
MapFunctor map,
|
||||
ReduceFunctor reduce,
|
||||
InitialValueType &&initialValue,
|
||||
@ -191,7 +191,7 @@ QFuture<ResultType> mappedReduced(const Sequence &sequence,
|
||||
| SequentialReduce))
|
||||
{
|
||||
return startMappedReduced<QtPrivate::MapResultType<Sequence, MapFunctor>, ResultType>
|
||||
(QThreadPool::globalInstance(), sequence, map, reduce,
|
||||
(QThreadPool::globalInstance(), std::forward<Sequence>(sequence), map, reduce,
|
||||
ResultType(std::forward<InitialValueType>(initialValue)), options);
|
||||
}
|
||||
|
||||
@ -320,19 +320,20 @@ QFuture<ResultType> mappedReduced(Iterator begin,
|
||||
template <typename Sequence, typename MapFunctor>
|
||||
QFuture<QtPrivate::MapResultType<Sequence, MapFunctor>> mapped(
|
||||
QThreadPool *pool,
|
||||
const Sequence &sequence,
|
||||
Sequence &&sequence,
|
||||
MapFunctor map)
|
||||
{
|
||||
return startMapped<QtPrivate::MapResultType<Sequence, MapFunctor>>(pool, sequence, map);
|
||||
return startMapped<QtPrivate::MapResultType<Sequence, MapFunctor>>(
|
||||
pool, std::forward<Sequence>(sequence), map);
|
||||
}
|
||||
|
||||
template <typename Sequence, typename MapFunctor>
|
||||
QFuture<QtPrivate::MapResultType<Sequence, MapFunctor>> mapped(
|
||||
const Sequence &sequence,
|
||||
Sequence &&sequence,
|
||||
MapFunctor map)
|
||||
{
|
||||
return startMapped<QtPrivate::MapResultType<Sequence, MapFunctor>>
|
||||
(QThreadPool::globalInstance(), sequence, map);
|
||||
(QThreadPool::globalInstance(), std::forward<Sequence>(sequence), map);
|
||||
}
|
||||
|
||||
// mapped() for iterator ranges.
|
||||
@ -358,14 +359,14 @@ QFuture<QtPrivate::MapResultType<Iterator, MapFunctor>> mapped(
|
||||
|
||||
// blockingMap() for sequences
|
||||
template <typename Sequence, typename MapFunctor>
|
||||
void blockingMap(QThreadPool *pool, Sequence &sequence, MapFunctor map)
|
||||
void blockingMap(QThreadPool *pool, Sequence &&sequence, MapFunctor map)
|
||||
{
|
||||
QFuture<void> future = startMap(pool, sequence.begin(), sequence.end(), map);
|
||||
future.waitForFinished();
|
||||
}
|
||||
|
||||
template <typename Sequence, typename MapFunctor>
|
||||
void blockingMap(Sequence &sequence, MapFunctor map)
|
||||
void blockingMap(Sequence &&sequence, MapFunctor map)
|
||||
{
|
||||
QFuture<void> future = startMap(QThreadPool::globalInstance(), sequence.begin(), sequence.end(), map);
|
||||
future.waitForFinished();
|
||||
@ -389,7 +390,7 @@ void blockingMap(Iterator begin, Iterator end, MapFunctor map)
|
||||
// blockingMappedReduced() for sequences
|
||||
template <typename ResultType, typename Sequence, typename MapFunctor, typename ReduceFunctor>
|
||||
ResultType blockingMappedReduced(QThreadPool *pool,
|
||||
const Sequence &sequence,
|
||||
Sequence &&sequence,
|
||||
MapFunctor map,
|
||||
ReduceFunctor reduce,
|
||||
ReduceOptions options = ReduceOptions(UnorderedReduce
|
||||
@ -397,12 +398,12 @@ ResultType blockingMappedReduced(QThreadPool *pool,
|
||||
{
|
||||
QFuture<ResultType> future = QtConcurrent::startMappedReduced
|
||||
<QtPrivate::MapResultType<Sequence, MapFunctor>, ResultType>
|
||||
(pool, sequence, map, reduce, options);
|
||||
(pool, std::forward<Sequence>(sequence), map, reduce, options);
|
||||
return future.result();
|
||||
}
|
||||
|
||||
template <typename ResultType, typename Sequence, typename MapFunctor, typename ReduceFunctor>
|
||||
ResultType blockingMappedReduced(const Sequence &sequence,
|
||||
ResultType blockingMappedReduced(Sequence &&sequence,
|
||||
MapFunctor map,
|
||||
ReduceFunctor reduce,
|
||||
ReduceOptions options = ReduceOptions(UnorderedReduce
|
||||
@ -410,7 +411,7 @@ ResultType blockingMappedReduced(const Sequence &sequence,
|
||||
{
|
||||
QFuture<ResultType> future = QtConcurrent::startMappedReduced
|
||||
<QtPrivate::MapResultType<Sequence, MapFunctor>, ResultType>
|
||||
(QThreadPool::globalInstance(), sequence, map, reduce, options);
|
||||
(QThreadPool::globalInstance(), std::forward<Sequence>(sequence), map, reduce, options);
|
||||
return future.result();
|
||||
}
|
||||
|
||||
@ -418,7 +419,7 @@ template <typename ResultType, typename Sequence, typename MapFunctor, typename
|
||||
typename InitialValueType,
|
||||
std::enable_if_t<std::is_convertible_v<InitialValueType, ResultType>, int> = 0>
|
||||
ResultType blockingMappedReduced(QThreadPool *pool,
|
||||
const Sequence &sequence,
|
||||
Sequence &&sequence,
|
||||
MapFunctor map,
|
||||
ReduceFunctor reduce,
|
||||
InitialValueType &&initialValue,
|
||||
@ -426,16 +427,16 @@ ResultType blockingMappedReduced(QThreadPool *pool,
|
||||
| SequentialReduce))
|
||||
{
|
||||
QFuture<ResultType> future = QtConcurrent::startMappedReduced
|
||||
<QtPrivate::MapResultType<Sequence, MapFunctor>, ResultType>
|
||||
(pool, sequence, map, reduce, ResultType(std::forward<InitialValueType>(initialValue)),
|
||||
options);
|
||||
<QtPrivate::MapResultType<Sequence, MapFunctor>, ResultType>
|
||||
(pool, std::forward<Sequence>(sequence), map, reduce,
|
||||
ResultType(std::forward<InitialValueType>(initialValue)), options);
|
||||
return future.result();
|
||||
}
|
||||
|
||||
template <typename ResultType, typename Sequence, typename MapFunctor, typename ReduceFunctor,
|
||||
typename InitialValueType,
|
||||
std::enable_if_t<std::is_convertible_v<InitialValueType, ResultType>, int> = 0>
|
||||
ResultType blockingMappedReduced(const Sequence &sequence,
|
||||
ResultType blockingMappedReduced(Sequence &&sequence,
|
||||
MapFunctor map,
|
||||
ReduceFunctor reduce,
|
||||
InitialValueType &&initialValue,
|
||||
@ -444,7 +445,7 @@ ResultType blockingMappedReduced(const Sequence &sequence,
|
||||
{
|
||||
QFuture<ResultType> future = QtConcurrent::startMappedReduced
|
||||
<QtPrivate::MapResultType<Sequence, MapFunctor>, ResultType>
|
||||
(QThreadPool::globalInstance(), sequence, map, reduce,
|
||||
(QThreadPool::globalInstance(), std::forward<Sequence>(sequence), map, reduce,
|
||||
ResultType(std::forward<InitialValueType>(initialValue)), options);
|
||||
return future.result();
|
||||
}
|
||||
@ -452,7 +453,7 @@ ResultType blockingMappedReduced(const Sequence &sequence,
|
||||
template <typename MapFunctor, typename ReduceFunctor, typename Sequence,
|
||||
typename ResultType = typename QtPrivate::ReduceResultType<ReduceFunctor>::ResultType>
|
||||
ResultType blockingMappedReduced(QThreadPool *pool,
|
||||
const Sequence &sequence,
|
||||
Sequence &&sequence,
|
||||
MapFunctor map,
|
||||
ReduceFunctor reduce,
|
||||
ReduceOptions options = ReduceOptions(UnorderedReduce
|
||||
@ -460,13 +461,13 @@ ResultType blockingMappedReduced(QThreadPool *pool,
|
||||
{
|
||||
QFuture<ResultType> future = QtConcurrent::startMappedReduced
|
||||
<QtPrivate::MapResultType<Sequence, MapFunctor>, ResultType>
|
||||
(pool, sequence, map, reduce, options);
|
||||
(pool, std::forward<Sequence>(sequence), map, reduce, options);
|
||||
return future.result();
|
||||
}
|
||||
|
||||
template <typename MapFunctor, typename ReduceFunctor, typename Sequence,
|
||||
typename ResultType = typename QtPrivate::ReduceResultType<ReduceFunctor>::ResultType>
|
||||
ResultType blockingMappedReduced(const Sequence &sequence,
|
||||
ResultType blockingMappedReduced(Sequence &&sequence,
|
||||
MapFunctor map,
|
||||
ReduceFunctor reduce,
|
||||
ReduceOptions options = ReduceOptions(UnorderedReduce
|
||||
@ -474,7 +475,7 @@ ResultType blockingMappedReduced(const Sequence &sequence,
|
||||
{
|
||||
QFuture<ResultType> future = QtConcurrent::startMappedReduced
|
||||
<QtPrivate::MapResultType<Sequence, MapFunctor>, ResultType>
|
||||
(QThreadPool::globalInstance(), sequence, map, reduce, options);
|
||||
(QThreadPool::globalInstance(), std::forward<Sequence>(sequence), map, reduce, options);
|
||||
return future.result();
|
||||
}
|
||||
|
||||
@ -483,7 +484,7 @@ template <typename MapFunctor, typename ReduceFunctor, typename Sequence,
|
||||
typename InitialValueType,
|
||||
std::enable_if_t<std::is_convertible_v<InitialValueType, ResultType>, int> = 0>
|
||||
ResultType blockingMappedReduced(QThreadPool *pool,
|
||||
const Sequence &sequence,
|
||||
Sequence &&sequence,
|
||||
MapFunctor map,
|
||||
ReduceFunctor reduce,
|
||||
InitialValueType &&initialValue,
|
||||
@ -492,8 +493,8 @@ ResultType blockingMappedReduced(QThreadPool *pool,
|
||||
{
|
||||
QFuture<ResultType> future = QtConcurrent::startMappedReduced
|
||||
<QtPrivate::MapResultType<Sequence, MapFunctor>, ResultType>
|
||||
(pool, sequence, map, reduce, ResultType(std::forward<InitialValueType>(initialValue)),
|
||||
options);
|
||||
(pool, std::forward<Sequence>(sequence), map, reduce,
|
||||
ResultType(std::forward<InitialValueType>(initialValue)), options);
|
||||
return future.result();
|
||||
}
|
||||
|
||||
@ -501,7 +502,7 @@ template <typename MapFunctor, typename ReduceFunctor, typename Sequence,
|
||||
typename ResultType = typename QtPrivate::ReduceResultType<ReduceFunctor>::ResultType,
|
||||
typename InitialValueType,
|
||||
std::enable_if_t<std::is_convertible_v<InitialValueType, ResultType>, int> = 0>
|
||||
ResultType blockingMappedReduced(const Sequence &sequence,
|
||||
ResultType blockingMappedReduced(Sequence &&sequence,
|
||||
MapFunctor map,
|
||||
ReduceFunctor reduce,
|
||||
InitialValueType &&initialValue,
|
||||
@ -510,7 +511,7 @@ ResultType blockingMappedReduced(const Sequence &sequence,
|
||||
{
|
||||
QFuture<ResultType> future = QtConcurrent::startMappedReduced
|
||||
<QtPrivate::MapResultType<Sequence, MapFunctor>, ResultType>
|
||||
(QThreadPool::globalInstance(), sequence, map, reduce,
|
||||
(QThreadPool::globalInstance(), std::forward<Sequence>(sequence), map, reduce,
|
||||
ResultType(std::forward<InitialValueType>(initialValue)), options);
|
||||
return future.result();
|
||||
}
|
||||
@ -654,35 +655,37 @@ ResultType blockingMappedReduced(Iterator begin,
|
||||
|
||||
// mapped() for sequences with a different putput sequence type.
|
||||
template <typename OutputSequence, typename InputSequence, typename MapFunctor>
|
||||
OutputSequence blockingMapped(QThreadPool *pool, const InputSequence &sequence, MapFunctor map)
|
||||
OutputSequence blockingMapped(QThreadPool *pool, InputSequence &&sequence, MapFunctor map)
|
||||
{
|
||||
return blockingMappedReduced<OutputSequence>(pool, sequence, map,
|
||||
return blockingMappedReduced<OutputSequence>(pool, std::forward<InputSequence>(sequence), map,
|
||||
QtPrivate::PushBackWrapper(), OrderedReduce);
|
||||
}
|
||||
|
||||
template <typename OutputSequence, typename InputSequence, typename MapFunctor>
|
||||
OutputSequence blockingMapped(const InputSequence &sequence, MapFunctor map)
|
||||
OutputSequence blockingMapped(InputSequence &&sequence, MapFunctor map)
|
||||
{
|
||||
return blockingMappedReduced<OutputSequence>(QThreadPool::globalInstance(), sequence, map,
|
||||
QtPrivate::PushBackWrapper(), OrderedReduce);
|
||||
return blockingMappedReduced<OutputSequence>(QThreadPool::globalInstance(),
|
||||
std::forward<InputSequence>(sequence), map,
|
||||
QtPrivate::PushBackWrapper(), OrderedReduce);
|
||||
}
|
||||
|
||||
template <typename MapFunctor, typename InputSequence>
|
||||
auto blockingMapped(QThreadPool *pool, const InputSequence &sequence, MapFunctor map)
|
||||
auto blockingMapped(QThreadPool *pool, InputSequence &&sequence, MapFunctor map)
|
||||
{
|
||||
using OutputSequence = typename QtPrivate::MapSequenceResultType<InputSequence,
|
||||
MapFunctor>::ResultType;
|
||||
return blockingMappedReduced<OutputSequence>(pool, sequence, map, QtPrivate::PushBackWrapper(),
|
||||
OrderedReduce);
|
||||
using OutputSequence = typename QtPrivate::MapSequenceResultType<std::decay_t<InputSequence>,
|
||||
MapFunctor>::ResultType;
|
||||
return blockingMappedReduced<OutputSequence>(pool, std::forward<InputSequence>(sequence), map,
|
||||
QtPrivate::PushBackWrapper(), OrderedReduce);
|
||||
}
|
||||
|
||||
template <typename MapFunctor, typename InputSequence>
|
||||
auto blockingMapped(const InputSequence &sequence, MapFunctor map)
|
||||
auto blockingMapped(InputSequence &&sequence, MapFunctor map)
|
||||
{
|
||||
using OutputSequence = typename QtPrivate::MapSequenceResultType<InputSequence,
|
||||
MapFunctor>::ResultType;
|
||||
return blockingMappedReduced<OutputSequence>(QThreadPool::globalInstance(), sequence, map,
|
||||
QtPrivate::PushBackWrapper(), OrderedReduce);
|
||||
using OutputSequence = typename QtPrivate::MapSequenceResultType<std::decay_t<InputSequence>,
|
||||
MapFunctor>::ResultType;
|
||||
return blockingMappedReduced<OutputSequence>(QThreadPool::globalInstance(),
|
||||
std::forward<InputSequence>(sequence), map,
|
||||
QtPrivate::PushBackWrapper(), OrderedReduce);
|
||||
}
|
||||
|
||||
// mapped() for iterator ranges
|
||||
|
@ -221,6 +221,11 @@ inline ThreadEngineStarter<T> startMapped(QThreadPool *pool, Iterator begin,
|
||||
template <typename Sequence, typename Base, typename Functor>
|
||||
struct SequenceHolder1 : private QtPrivate::SequenceHolder<Sequence>, public Base
|
||||
{
|
||||
SequenceHolder1(QThreadPool *pool, Sequence &&_sequence, Functor functor)
|
||||
: QtPrivate::SequenceHolder<Sequence>(std::move(_sequence)),
|
||||
Base(pool, this->sequence.cbegin(), this->sequence.cend(), functor)
|
||||
{ }
|
||||
|
||||
SequenceHolder1(QThreadPool *pool, const Sequence &_sequence, Functor functor)
|
||||
: QtPrivate::SequenceHolder<Sequence>(_sequence),
|
||||
Base(pool, this->sequence.cbegin(), this->sequence.cend(), functor)
|
||||
@ -237,33 +242,37 @@ struct SequenceHolder1 : private QtPrivate::SequenceHolder<Sequence>, public Bas
|
||||
|
||||
//! [qtconcurrentmapkernel-3]
|
||||
template <typename T, typename Sequence, typename Functor>
|
||||
inline ThreadEngineStarter<T> startMapped(QThreadPool *pool, const Sequence &sequence,
|
||||
inline ThreadEngineStarter<T> startMapped(QThreadPool *pool, Sequence &&sequence,
|
||||
Functor functor)
|
||||
{
|
||||
typedef SequenceHolder1<Sequence,
|
||||
MappedEachKernel<typename Sequence::const_iterator , Functor>, Functor>
|
||||
SequenceHolderType;
|
||||
using DecayedSequence = std::decay_t<Sequence>;
|
||||
typedef SequenceHolder1<DecayedSequence,
|
||||
MappedEachKernel<typename DecayedSequence::const_iterator, Functor>,
|
||||
Functor>
|
||||
SequenceHolderType;
|
||||
|
||||
return startThreadEngine(new SequenceHolderType(pool, sequence, functor));
|
||||
return startThreadEngine(
|
||||
new SequenceHolderType(pool, std::forward<Sequence>(sequence), functor));
|
||||
}
|
||||
|
||||
//! [qtconcurrentmapkernel-4]
|
||||
template <typename IntermediateType, typename ResultType, typename Sequence, typename MapFunctor,
|
||||
typename ReduceFunctor>
|
||||
inline ThreadEngineStarter<ResultType> startMappedReduced(QThreadPool *pool,
|
||||
const Sequence & sequence,
|
||||
Sequence &&sequence,
|
||||
MapFunctor mapFunctor,
|
||||
ReduceFunctor reduceFunctor,
|
||||
ReduceOptions options)
|
||||
{
|
||||
typedef typename Sequence::const_iterator Iterator;
|
||||
using DecayedSequence = std::decay_t<Sequence>;
|
||||
typedef typename DecayedSequence::const_iterator Iterator;
|
||||
typedef ReduceKernel<ReduceFunctor, ResultType, IntermediateType> Reducer;
|
||||
typedef MappedReducedKernel<ResultType, Iterator, MapFunctor, ReduceFunctor, Reducer>
|
||||
MappedReduceType;
|
||||
typedef SequenceHolder2<Sequence, MappedReduceType, MapFunctor, ReduceFunctor>
|
||||
typedef SequenceHolder2<DecayedSequence, MappedReduceType, MapFunctor, ReduceFunctor>
|
||||
SequenceHolderType;
|
||||
return startThreadEngine(new SequenceHolderType(pool, sequence, mapFunctor, reduceFunctor,
|
||||
options));
|
||||
return startThreadEngine(new SequenceHolderType(pool, std::forward<Sequence>(sequence),
|
||||
mapFunctor, reduceFunctor, options));
|
||||
}
|
||||
|
||||
//! [qtconcurrentmapkernel-5]
|
||||
@ -287,21 +296,22 @@ inline ThreadEngineStarter<ResultType> startMappedReduced(QThreadPool *pool,
|
||||
template <typename IntermediateType, typename ResultType, typename Sequence, typename MapFunctor,
|
||||
typename ReduceFunctor>
|
||||
inline ThreadEngineStarter<ResultType> startMappedReduced(QThreadPool *pool,
|
||||
const Sequence &sequence,
|
||||
Sequence &&sequence,
|
||||
MapFunctor mapFunctor,
|
||||
ReduceFunctor reduceFunctor,
|
||||
ResultType &&initialValue,
|
||||
ReduceOptions options)
|
||||
{
|
||||
typedef typename Sequence::const_iterator Iterator;
|
||||
using DecayedSequence = std::decay_t<Sequence>;
|
||||
typedef typename DecayedSequence::const_iterator Iterator;
|
||||
typedef ReduceKernel<ReduceFunctor, ResultType, IntermediateType> Reducer;
|
||||
typedef MappedReducedKernel<ResultType, Iterator, MapFunctor, ReduceFunctor, Reducer>
|
||||
MappedReduceType;
|
||||
typedef SequenceHolder2<Sequence, MappedReduceType, MapFunctor, ReduceFunctor>
|
||||
typedef SequenceHolder2<DecayedSequence, MappedReduceType, MapFunctor, ReduceFunctor>
|
||||
SequenceHolderType;
|
||||
return startThreadEngine(new SequenceHolderType(
|
||||
pool, sequence, mapFunctor, reduceFunctor, std::forward<ResultType>(initialValue),
|
||||
options));
|
||||
return startThreadEngine(
|
||||
new SequenceHolderType(pool, std::forward<Sequence>(sequence), mapFunctor,
|
||||
reduceFunctor, std::forward<ResultType>(initialValue), options));
|
||||
}
|
||||
|
||||
//! [qtconcurrentmapkernel-7]
|
||||
|
@ -232,6 +232,13 @@ struct SequenceHolder2 : private QtPrivate::SequenceHolder<Sequence>, public Bas
|
||||
reduceOptions)
|
||||
{ }
|
||||
|
||||
SequenceHolder2(QThreadPool *pool, Sequence &&_sequence, Functor1 functor1, Functor2 functor2,
|
||||
ReduceOptions reduceOptions)
|
||||
: QtPrivate::SequenceHolder<Sequence>(std::move(_sequence)),
|
||||
Base(pool, this->sequence.cbegin(), this->sequence.cend(), functor1, functor2,
|
||||
reduceOptions)
|
||||
{ }
|
||||
|
||||
template<typename InitialValueType>
|
||||
SequenceHolder2(QThreadPool *pool, const Sequence &_sequence, Functor1 functor1,
|
||||
Functor2 functor2, InitialValueType &&initialValue, ReduceOptions reduceOptions)
|
||||
@ -240,6 +247,14 @@ struct SequenceHolder2 : private QtPrivate::SequenceHolder<Sequence>, public Bas
|
||||
std::forward<InitialValueType>(initialValue), reduceOptions)
|
||||
{ }
|
||||
|
||||
template<typename InitialValueType>
|
||||
SequenceHolder2(QThreadPool *pool, Sequence &&_sequence, Functor1 functor1, Functor2 functor2,
|
||||
InitialValueType &&initialValue, ReduceOptions reduceOptions)
|
||||
: QtPrivate::SequenceHolder<Sequence>(std::move(_sequence)),
|
||||
Base(pool, this->sequence.cbegin(), this->sequence.cend(), functor1, functor2,
|
||||
std::forward<InitialValueType>(initialValue), reduceOptions)
|
||||
{ }
|
||||
|
||||
void finish() override
|
||||
{
|
||||
Base::finish();
|
||||
|
@ -41,7 +41,8 @@ class tst_QtConcurrentMap : public QObject
|
||||
Q_OBJECT
|
||||
private slots:
|
||||
void map();
|
||||
void blocking_map();
|
||||
void blockingMap();
|
||||
void mapOnRvalue();
|
||||
void mapped();
|
||||
void mappedThreadPool();
|
||||
void mappedReduced();
|
||||
@ -211,7 +212,7 @@ void tst_QtConcurrentMap::map()
|
||||
#endif
|
||||
}
|
||||
|
||||
void tst_QtConcurrentMap::blocking_map()
|
||||
void tst_QtConcurrentMap::blockingMap()
|
||||
{
|
||||
// functors take arguments by reference, modifying the sequence in place
|
||||
{
|
||||
@ -323,6 +324,54 @@ void tst_QtConcurrentMap::blocking_map()
|
||||
#endif
|
||||
}
|
||||
|
||||
void tst_QtConcurrentMap::mapOnRvalue()
|
||||
{
|
||||
struct ListRange
|
||||
{
|
||||
using iterator = QList<int>::iterator;
|
||||
ListRange(iterator b, iterator e) : m_begin(b), m_end(e) { }
|
||||
|
||||
iterator begin() const { return m_begin; }
|
||||
iterator end() const { return m_end; }
|
||||
|
||||
private:
|
||||
iterator m_begin;
|
||||
iterator m_end;
|
||||
};
|
||||
|
||||
const QList expected { 1, 4, 6, 4 };
|
||||
{
|
||||
QList list { 1, 2, 3, 4 };
|
||||
auto future =
|
||||
QtConcurrent::map(ListRange(list.begin() + 1, list.end() - 1), multiplyBy2InPlace);
|
||||
future.waitForFinished();
|
||||
QCOMPARE(list, expected);
|
||||
}
|
||||
|
||||
{
|
||||
QList list { 1, 2, 3, 4 };
|
||||
QThreadPool pool;
|
||||
auto future = QtConcurrent::map(&pool, ListRange(list.begin() + 1, list.end() - 1),
|
||||
multiplyBy2InPlace);
|
||||
future.waitForFinished();
|
||||
QCOMPARE(list, expected);
|
||||
}
|
||||
|
||||
{
|
||||
QList list { 1, 2, 3, 4 };
|
||||
QtConcurrent::blockingMap(ListRange(list.begin() + 1, list.end() - 1), multiplyBy2InPlace);
|
||||
QCOMPARE(list, expected);
|
||||
}
|
||||
|
||||
{
|
||||
QList list { 1, 2, 3, 4 };
|
||||
QThreadPool pool;
|
||||
QtConcurrent::blockingMap(&pool, ListRange(list.begin() + 1, list.end() - 1),
|
||||
multiplyBy2InPlace);
|
||||
QCOMPARE(list, expected);
|
||||
}
|
||||
}
|
||||
|
||||
int multiplyBy2(int x)
|
||||
{
|
||||
int y = x * 2;
|
||||
|
Loading…
Reference in New Issue
Block a user