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
|
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
|
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
|
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
|
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.
|
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.
|
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
|
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
|
\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.
|
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.
|
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
|
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
|
\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
|
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
|
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
|
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
|
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.
|
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.
|
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
|
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
|
\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.
|
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.
|
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
|
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
|
\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
|
\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
|
\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
|
\internal
|
||||||
*/
|
*/
|
||||||
|
|
||||||
|
@ -77,78 +77,82 @@ QFuture<void> filter(Sequence &sequence, KeepFunctor keep)
|
|||||||
// filteredReduced() on sequences
|
// filteredReduced() on sequences
|
||||||
template <typename ResultType, typename Sequence, typename KeepFunctor, typename ReduceFunctor>
|
template <typename ResultType, typename Sequence, typename KeepFunctor, typename ReduceFunctor>
|
||||||
QFuture<ResultType> filteredReduced(QThreadPool *pool,
|
QFuture<ResultType> filteredReduced(QThreadPool *pool,
|
||||||
const Sequence &sequence,
|
Sequence &&sequence,
|
||||||
KeepFunctor keep,
|
KeepFunctor keep,
|
||||||
ReduceFunctor reduce,
|
ReduceFunctor reduce,
|
||||||
ReduceOptions options = ReduceOptions(UnorderedReduce
|
ReduceOptions options = ReduceOptions(UnorderedReduce
|
||||||
| SequentialReduce))
|
| 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>
|
template <typename ResultType, typename Sequence, typename KeepFunctor, typename ReduceFunctor>
|
||||||
QFuture<ResultType> filteredReduced(const Sequence &sequence,
|
QFuture<ResultType> filteredReduced(Sequence &&sequence,
|
||||||
KeepFunctor keep,
|
KeepFunctor keep,
|
||||||
ReduceFunctor reduce,
|
ReduceFunctor reduce,
|
||||||
ReduceOptions options = ReduceOptions(UnorderedReduce
|
ReduceOptions options = ReduceOptions(UnorderedReduce
|
||||||
| SequentialReduce))
|
| SequentialReduce))
|
||||||
{
|
{
|
||||||
return startFilteredReduced<ResultType>(QThreadPool::globalInstance(),
|
return startFilteredReduced<ResultType>(
|
||||||
sequence, keep, reduce, options);
|
QThreadPool::globalInstance(), std::forward<Sequence>(sequence), keep, reduce, options);
|
||||||
}
|
}
|
||||||
|
|
||||||
template <typename ResultType, typename Sequence, typename KeepFunctor, typename ReduceFunctor,
|
template <typename ResultType, typename Sequence, 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>
|
||||||
QFuture<ResultType> filteredReduced(QThreadPool *pool,
|
QFuture<ResultType> filteredReduced(QThreadPool *pool,
|
||||||
const Sequence &sequence,
|
Sequence &&sequence,
|
||||||
KeepFunctor keep,
|
KeepFunctor keep,
|
||||||
ReduceFunctor reduce,
|
ReduceFunctor reduce,
|
||||||
InitialValueType &&initialValue,
|
InitialValueType &&initialValue,
|
||||||
ReduceOptions options = ReduceOptions(UnorderedReduce
|
ReduceOptions options = ReduceOptions(UnorderedReduce
|
||||||
| SequentialReduce))
|
| SequentialReduce))
|
||||||
{
|
{
|
||||||
return startFilteredReduced<ResultType>(pool, sequence, keep, reduce,
|
return startFilteredReduced<ResultType>(
|
||||||
ResultType(std::forward<InitialValueType>(initialValue)), options);
|
pool, std::forward<Sequence>(sequence), keep, reduce,
|
||||||
|
ResultType(std::forward<InitialValueType>(initialValue)), options);
|
||||||
}
|
}
|
||||||
|
|
||||||
template <typename ResultType, typename Sequence, typename KeepFunctor, typename ReduceFunctor,
|
template <typename ResultType, typename Sequence, 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>
|
||||||
QFuture<ResultType> filteredReduced(const Sequence &sequence,
|
QFuture<ResultType> filteredReduced(Sequence &&sequence,
|
||||||
KeepFunctor keep,
|
KeepFunctor keep,
|
||||||
ReduceFunctor reduce,
|
ReduceFunctor reduce,
|
||||||
InitialValueType &&initialValue,
|
InitialValueType &&initialValue,
|
||||||
ReduceOptions options = ReduceOptions(UnorderedReduce
|
ReduceOptions options = ReduceOptions(UnorderedReduce
|
||||||
| SequentialReduce))
|
| SequentialReduce))
|
||||||
{
|
{
|
||||||
return startFilteredReduced<ResultType>(QThreadPool::globalInstance(), sequence, keep, reduce,
|
return startFilteredReduced<ResultType>(
|
||||||
ResultType(std::forward<InitialValueType>(initialValue)), options);
|
QThreadPool::globalInstance(), std::forward<Sequence>(sequence), keep, reduce,
|
||||||
|
ResultType(std::forward<InitialValueType>(initialValue)), options);
|
||||||
}
|
}
|
||||||
|
|
||||||
#ifndef Q_CLANG_QDOC
|
#ifndef Q_CLANG_QDOC
|
||||||
template <typename Sequence, typename KeepFunctor, typename ReduceFunctor,
|
template <typename Sequence, typename KeepFunctor, typename ReduceFunctor,
|
||||||
typename ResultType = typename QtPrivate::ReduceResultType<ReduceFunctor>::ResultType>
|
typename ResultType = typename QtPrivate::ReduceResultType<ReduceFunctor>::ResultType>
|
||||||
QFuture<ResultType> filteredReduced(QThreadPool *pool,
|
QFuture<ResultType> filteredReduced(QThreadPool *pool,
|
||||||
const Sequence &sequence,
|
Sequence &&sequence,
|
||||||
KeepFunctor keep,
|
KeepFunctor keep,
|
||||||
ReduceFunctor reduce,
|
ReduceFunctor reduce,
|
||||||
ReduceOptions options = ReduceOptions(UnorderedReduce
|
ReduceOptions options = ReduceOptions(UnorderedReduce
|
||||||
| SequentialReduce))
|
| 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,
|
template <typename Sequence, typename KeepFunctor, typename ReduceFunctor,
|
||||||
typename ResultType = typename QtPrivate::ReduceResultType<ReduceFunctor>::ResultType>
|
typename ResultType = typename QtPrivate::ReduceResultType<ReduceFunctor>::ResultType>
|
||||||
QFuture<ResultType> filteredReduced(const Sequence &sequence,
|
QFuture<ResultType> filteredReduced(Sequence &&sequence,
|
||||||
KeepFunctor keep,
|
KeepFunctor keep,
|
||||||
ReduceFunctor reduce,
|
ReduceFunctor reduce,
|
||||||
ReduceOptions options = ReduceOptions(UnorderedReduce
|
ReduceOptions options = ReduceOptions(UnorderedReduce
|
||||||
| SequentialReduce))
|
| SequentialReduce))
|
||||||
{
|
{
|
||||||
return startFilteredReduced<ResultType>(QThreadPool::globalInstance(),
|
return startFilteredReduced<ResultType>(
|
||||||
sequence, keep, reduce, options);
|
QThreadPool::globalInstance(), std::forward<Sequence>(sequence), keep, reduce, options);
|
||||||
}
|
}
|
||||||
|
|
||||||
template <typename Sequence, typename KeepFunctor, typename ReduceFunctor,
|
template <typename Sequence, typename KeepFunctor, typename ReduceFunctor,
|
||||||
@ -156,30 +160,32 @@ template <typename Sequence, 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>
|
||||||
QFuture<ResultType> filteredReduced(QThreadPool *pool,
|
QFuture<ResultType> filteredReduced(QThreadPool *pool,
|
||||||
const Sequence &sequence,
|
Sequence &&sequence,
|
||||||
KeepFunctor keep,
|
KeepFunctor keep,
|
||||||
ReduceFunctor reduce,
|
ReduceFunctor reduce,
|
||||||
InitialValueType &&initialValue,
|
InitialValueType &&initialValue,
|
||||||
ReduceOptions options = ReduceOptions(UnorderedReduce
|
ReduceOptions options = ReduceOptions(UnorderedReduce
|
||||||
| SequentialReduce))
|
| SequentialReduce))
|
||||||
{
|
{
|
||||||
return startFilteredReduced<ResultType>(pool, sequence, keep, reduce,
|
return startFilteredReduced<ResultType>(
|
||||||
ResultType(std::forward<InitialValueType>(initialValue)), options);
|
pool, std::forward<Sequence>(sequence), keep, reduce,
|
||||||
|
ResultType(std::forward<InitialValueType>(initialValue)), options);
|
||||||
}
|
}
|
||||||
|
|
||||||
template <typename Sequence, typename KeepFunctor, typename ReduceFunctor,
|
template <typename Sequence, typename KeepFunctor, 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<ResultType> filteredReduced(const Sequence &sequence,
|
QFuture<ResultType> filteredReduced(Sequence &&sequence,
|
||||||
KeepFunctor keep,
|
KeepFunctor keep,
|
||||||
ReduceFunctor reduce,
|
ReduceFunctor reduce,
|
||||||
InitialValueType &&initialValue,
|
InitialValueType &&initialValue,
|
||||||
ReduceOptions options = ReduceOptions(UnorderedReduce
|
ReduceOptions options = ReduceOptions(UnorderedReduce
|
||||||
| SequentialReduce))
|
| SequentialReduce))
|
||||||
{
|
{
|
||||||
return startFilteredReduced<ResultType>(QThreadPool::globalInstance(), sequence, keep, reduce,
|
return startFilteredReduced<ResultType>(
|
||||||
ResultType(std::forward<InitialValueType>(initialValue)), options);
|
QThreadPool::globalInstance(), std::forward<Sequence>(sequence), keep, reduce,
|
||||||
|
ResultType(std::forward<InitialValueType>(initialValue)), options);
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
@ -302,17 +308,16 @@ QFuture<ResultType> filteredReduced(Iterator begin,
|
|||||||
|
|
||||||
// filtered() on sequences
|
// filtered() on sequences
|
||||||
template <typename Sequence, typename KeepFunctor>
|
template <typename Sequence, typename KeepFunctor>
|
||||||
QFuture<typename Sequence::value_type> filtered(QThreadPool *pool,
|
QFuture<typename std::decay_t<Sequence>::value_type> filtered(QThreadPool *pool,
|
||||||
const Sequence &sequence,
|
Sequence &&sequence, KeepFunctor keep)
|
||||||
KeepFunctor keep)
|
|
||||||
{
|
{
|
||||||
return startFiltered(pool, sequence, keep);
|
return startFiltered(pool, std::forward<Sequence>(sequence), keep);
|
||||||
}
|
}
|
||||||
|
|
||||||
template <typename Sequence, typename KeepFunctor>
|
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
|
// filtered() on iterators
|
||||||
@ -352,26 +357,26 @@ void blockingFilter(Sequence &sequence, KeepFunctor keep)
|
|||||||
// blocking filteredReduced() on sequences
|
// blocking filteredReduced() on sequences
|
||||||
template <typename ResultType, typename Sequence, typename KeepFunctor, typename ReduceFunctor>
|
template <typename ResultType, typename Sequence, typename KeepFunctor, typename ReduceFunctor>
|
||||||
ResultType blockingFilteredReduced(QThreadPool *pool,
|
ResultType blockingFilteredReduced(QThreadPool *pool,
|
||||||
const Sequence &sequence,
|
Sequence &&sequence,
|
||||||
KeepFunctor keep,
|
KeepFunctor keep,
|
||||||
ReduceFunctor reduce,
|
ReduceFunctor reduce,
|
||||||
ReduceOptions options = ReduceOptions(UnorderedReduce
|
ReduceOptions options = ReduceOptions(UnorderedReduce
|
||||||
| SequentialReduce))
|
| SequentialReduce))
|
||||||
{
|
{
|
||||||
QFuture<ResultType> future = startFilteredReduced<ResultType>(pool, sequence, keep,
|
QFuture<ResultType> future = startFilteredReduced<ResultType>(
|
||||||
reduce, options);
|
pool, std::forward<Sequence>(sequence), keep, reduce, options);
|
||||||
return future.result();
|
return future.result();
|
||||||
}
|
}
|
||||||
|
|
||||||
template <typename ResultType, typename Sequence, typename KeepFunctor, typename ReduceFunctor>
|
template <typename ResultType, typename Sequence, typename KeepFunctor, typename ReduceFunctor>
|
||||||
ResultType blockingFilteredReduced(const Sequence &sequence,
|
ResultType blockingFilteredReduced(Sequence &&sequence,
|
||||||
KeepFunctor keep,
|
KeepFunctor keep,
|
||||||
ReduceFunctor reduce,
|
ReduceFunctor reduce,
|
||||||
ReduceOptions options = ReduceOptions(UnorderedReduce
|
ReduceOptions options = ReduceOptions(UnorderedReduce
|
||||||
| SequentialReduce))
|
| SequentialReduce))
|
||||||
{
|
{
|
||||||
QFuture<ResultType> future = startFilteredReduced<ResultType>(QThreadPool::globalInstance(),
|
QFuture<ResultType> future = startFilteredReduced<ResultType>(
|
||||||
sequence, keep, reduce, options);
|
QThreadPool::globalInstance(), std::forward<Sequence>(sequence), keep, reduce, options);
|
||||||
return future.result();
|
return future.result();
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -379,30 +384,32 @@ template <typename ResultType, typename Sequence, typename KeepFunctor, typename
|
|||||||
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>
|
||||||
ResultType blockingFilteredReduced(QThreadPool *pool,
|
ResultType blockingFilteredReduced(QThreadPool *pool,
|
||||||
const Sequence &sequence,
|
Sequence &&sequence,
|
||||||
KeepFunctor keep,
|
KeepFunctor keep,
|
||||||
ReduceFunctor reduce,
|
ReduceFunctor reduce,
|
||||||
InitialValueType &&initialValue,
|
InitialValueType &&initialValue,
|
||||||
ReduceOptions options = ReduceOptions(UnorderedReduce
|
ReduceOptions options = ReduceOptions(UnorderedReduce
|
||||||
| SequentialReduce))
|
| SequentialReduce))
|
||||||
{
|
{
|
||||||
QFuture<ResultType> future = startFilteredReduced<ResultType>(pool, sequence, keep, reduce,
|
QFuture<ResultType> future = startFilteredReduced<ResultType>(
|
||||||
ResultType(std::forward<InitialValueType>(initialValue)), options);
|
pool, std::forward<Sequence>(sequence), keep, reduce,
|
||||||
|
ResultType(std::forward<InitialValueType>(initialValue)), options);
|
||||||
return future.result();
|
return future.result();
|
||||||
}
|
}
|
||||||
|
|
||||||
template <typename ResultType, typename Sequence, typename KeepFunctor, typename ReduceFunctor,
|
template <typename ResultType, typename Sequence, 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>
|
||||||
ResultType blockingFilteredReduced(const Sequence &sequence,
|
ResultType blockingFilteredReduced(Sequence &&sequence,
|
||||||
KeepFunctor keep,
|
KeepFunctor keep,
|
||||||
ReduceFunctor reduce,
|
ReduceFunctor reduce,
|
||||||
InitialValueType &&initialValue,
|
InitialValueType &&initialValue,
|
||||||
ReduceOptions options = ReduceOptions(UnorderedReduce
|
ReduceOptions options = ReduceOptions(UnorderedReduce
|
||||||
| SequentialReduce))
|
| SequentialReduce))
|
||||||
{
|
{
|
||||||
QFuture<ResultType> future = startFilteredReduced<ResultType>(QThreadPool::globalInstance(),
|
QFuture<ResultType> future = startFilteredReduced<ResultType>(
|
||||||
sequence, keep, reduce, ResultType(std::forward<InitialValueType>(initialValue)), options);
|
QThreadPool::globalInstance(), std::forward<Sequence>(sequence), keep, reduce,
|
||||||
|
ResultType(std::forward<InitialValueType>(initialValue)), options);
|
||||||
return future.result();
|
return future.result();
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -410,27 +417,27 @@ ResultType blockingFilteredReduced(const Sequence &sequence,
|
|||||||
template <typename Sequence, typename KeepFunctor, typename ReduceFunctor,
|
template <typename Sequence, typename KeepFunctor, typename ReduceFunctor,
|
||||||
typename ResultType = typename QtPrivate::ReduceResultType<ReduceFunctor>::ResultType>
|
typename ResultType = typename QtPrivate::ReduceResultType<ReduceFunctor>::ResultType>
|
||||||
ResultType blockingFilteredReduced(QThreadPool *pool,
|
ResultType blockingFilteredReduced(QThreadPool *pool,
|
||||||
const Sequence &sequence,
|
Sequence &&sequence,
|
||||||
KeepFunctor keep,
|
KeepFunctor keep,
|
||||||
ReduceFunctor reduce,
|
ReduceFunctor reduce,
|
||||||
ReduceOptions options = ReduceOptions(UnorderedReduce
|
ReduceOptions options = ReduceOptions(UnorderedReduce
|
||||||
| SequentialReduce))
|
| SequentialReduce))
|
||||||
{
|
{
|
||||||
QFuture<ResultType> future = startFilteredReduced<ResultType>(pool, sequence, keep,
|
QFuture<ResultType> future = startFilteredReduced<ResultType>(
|
||||||
reduce, options);
|
pool, std::forward<Sequence>(sequence), keep, reduce, options);
|
||||||
return future.result();
|
return future.result();
|
||||||
}
|
}
|
||||||
|
|
||||||
template <typename Sequence, typename KeepFunctor, typename ReduceFunctor,
|
template <typename Sequence, typename KeepFunctor, typename ReduceFunctor,
|
||||||
typename ResultType = typename QtPrivate::ReduceResultType<ReduceFunctor>::ResultType>
|
typename ResultType = typename QtPrivate::ReduceResultType<ReduceFunctor>::ResultType>
|
||||||
ResultType blockingFilteredReduced(const Sequence &sequence,
|
ResultType blockingFilteredReduced(Sequence &&sequence,
|
||||||
KeepFunctor keep,
|
KeepFunctor keep,
|
||||||
ReduceFunctor reduce,
|
ReduceFunctor reduce,
|
||||||
ReduceOptions options = ReduceOptions(UnorderedReduce
|
ReduceOptions options = ReduceOptions(UnorderedReduce
|
||||||
| SequentialReduce))
|
| SequentialReduce))
|
||||||
{
|
{
|
||||||
QFuture<ResultType> future = startFilteredReduced<ResultType>(QThreadPool::globalInstance(),
|
QFuture<ResultType> future = startFilteredReduced<ResultType>(
|
||||||
sequence, keep, reduce, options);
|
QThreadPool::globalInstance(), std::forward<Sequence>(sequence), keep, reduce, options);
|
||||||
return future.result();
|
return future.result();
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -439,15 +446,16 @@ template <typename Sequence, 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>
|
||||||
ResultType blockingFilteredReduced(QThreadPool *pool,
|
ResultType blockingFilteredReduced(QThreadPool *pool,
|
||||||
const Sequence &sequence,
|
Sequence &&sequence,
|
||||||
KeepFunctor keep,
|
KeepFunctor keep,
|
||||||
ReduceFunctor reduce,
|
ReduceFunctor reduce,
|
||||||
InitialValueType &&initialValue,
|
InitialValueType &&initialValue,
|
||||||
ReduceOptions options = ReduceOptions(UnorderedReduce
|
ReduceOptions options = ReduceOptions(UnorderedReduce
|
||||||
| SequentialReduce))
|
| SequentialReduce))
|
||||||
{
|
{
|
||||||
QFuture<ResultType> future = startFilteredReduced<ResultType>(pool, sequence, keep, reduce,
|
QFuture<ResultType> future = startFilteredReduced<ResultType>(
|
||||||
ResultType(std::forward<InitialValueType>(initialValue)), options);
|
pool, std::forward<Sequence>(sequence), keep, reduce,
|
||||||
|
ResultType(std::forward<InitialValueType>(initialValue)), options);
|
||||||
return future.result();
|
return future.result();
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -455,15 +463,16 @@ template <typename Sequence, typename KeepFunctor, 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>
|
||||||
ResultType blockingFilteredReduced(const Sequence &sequence,
|
ResultType blockingFilteredReduced(Sequence &&sequence,
|
||||||
KeepFunctor keep,
|
KeepFunctor keep,
|
||||||
ReduceFunctor reduce,
|
ReduceFunctor reduce,
|
||||||
InitialValueType &&initialValue,
|
InitialValueType &&initialValue,
|
||||||
ReduceOptions options = ReduceOptions(UnorderedReduce
|
ReduceOptions options = ReduceOptions(UnorderedReduce
|
||||||
| SequentialReduce))
|
| SequentialReduce))
|
||||||
{
|
{
|
||||||
QFuture<ResultType> future = startFilteredReduced<ResultType>(QThreadPool::globalInstance(),
|
QFuture<ResultType> future = startFilteredReduced<ResultType>(
|
||||||
sequence, keep, reduce, ResultType(std::forward<InitialValueType>(initialValue)), options);
|
QThreadPool::globalInstance(), std::forward<Sequence>(sequence), keep, reduce,
|
||||||
|
ResultType(std::forward<InitialValueType>(initialValue)), options);
|
||||||
return future.result();
|
return future.result();
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
@ -596,17 +605,19 @@ ResultType blockingFilteredReduced(Iterator begin,
|
|||||||
|
|
||||||
// blocking filtered() on sequences
|
// blocking filtered() on sequences
|
||||||
template <typename Sequence, typename KeepFunctor>
|
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(),
|
return blockingFilteredReduced<std::decay_t<Sequence>>(
|
||||||
OrderedReduce);
|
pool, std::forward<Sequence>(sequence), keep, QtPrivate::PushBackWrapper(),
|
||||||
|
OrderedReduce);
|
||||||
}
|
}
|
||||||
|
|
||||||
template <typename Sequence, typename KeepFunctor>
|
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,
|
return blockingFilteredReduced<std::decay_t<Sequence>>(
|
||||||
QtPrivate::PushBackWrapper(), OrderedReduce);
|
QThreadPool::globalInstance(), std::forward<Sequence>(sequence), keep,
|
||||||
|
QtPrivate::PushBackWrapper(), OrderedReduce);
|
||||||
}
|
}
|
||||||
|
|
||||||
// blocking filtered() on iterators
|
// blocking filtered() on iterators
|
||||||
|
@ -308,33 +308,35 @@ startFiltered(QThreadPool *pool, Iterator begin, Iterator end, KeepFunctor funct
|
|||||||
|
|
||||||
//! [QtConcurrent-3]
|
//! [QtConcurrent-3]
|
||||||
template <typename Sequence, typename KeepFunctor>
|
template <typename Sequence, typename KeepFunctor>
|
||||||
inline ThreadEngineStarter<typename Sequence::value_type>
|
inline decltype(auto) startFiltered(QThreadPool *pool, Sequence &&sequence, KeepFunctor functor)
|
||||||
startFiltered(QThreadPool *pool, const Sequence &sequence, KeepFunctor functor)
|
|
||||||
{
|
{
|
||||||
typedef SequenceHolder1<Sequence,
|
using DecayedSequence = std::decay_t<Sequence>;
|
||||||
FilteredEachKernel<typename Sequence::const_iterator, KeepFunctor>,
|
typedef SequenceHolder1<DecayedSequence,
|
||||||
|
FilteredEachKernel<typename DecayedSequence::const_iterator, KeepFunctor>,
|
||||||
KeepFunctor>
|
KeepFunctor>
|
||||||
SequenceHolderType;
|
SequenceHolderType;
|
||||||
return startThreadEngine(new SequenceHolderType(pool, sequence, functor));
|
return startThreadEngine(
|
||||||
|
new SequenceHolderType(pool, std::forward<Sequence>(sequence), functor));
|
||||||
}
|
}
|
||||||
|
|
||||||
//! [QtConcurrent-4]
|
//! [QtConcurrent-4]
|
||||||
template <typename ResultType, typename Sequence, typename MapFunctor, typename ReduceFunctor>
|
template <typename ResultType, typename Sequence, typename MapFunctor, typename ReduceFunctor>
|
||||||
inline ThreadEngineStarter<ResultType> startFilteredReduced(QThreadPool *pool,
|
inline ThreadEngineStarter<ResultType> startFilteredReduced(QThreadPool *pool,
|
||||||
const Sequence &sequence,
|
Sequence &&sequence,
|
||||||
MapFunctor mapFunctor,
|
MapFunctor mapFunctor,
|
||||||
ReduceFunctor reduceFunctor,
|
ReduceFunctor reduceFunctor,
|
||||||
ReduceOptions options)
|
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 >
|
typedef ReduceKernel<ReduceFunctor, ResultType, typename qValueType<Iterator>::value_type >
|
||||||
Reducer;
|
Reducer;
|
||||||
typedef FilteredReducedKernel<ResultType, Iterator, MapFunctor, ReduceFunctor, Reducer>
|
typedef FilteredReducedKernel<ResultType, Iterator, MapFunctor, ReduceFunctor, Reducer>
|
||||||
FilteredReduceType;
|
FilteredReduceType;
|
||||||
typedef SequenceHolder2<Sequence, FilteredReduceType, MapFunctor, ReduceFunctor>
|
typedef SequenceHolder2<DecayedSequence, FilteredReduceType, MapFunctor, ReduceFunctor>
|
||||||
SequenceHolderType;
|
SequenceHolderType;
|
||||||
return startThreadEngine(new SequenceHolderType(pool, sequence, mapFunctor,
|
return startThreadEngine(new SequenceHolderType(pool, std::forward<Sequence>(sequence),
|
||||||
reduceFunctor, options));
|
mapFunctor, reduceFunctor, options));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@ -359,21 +361,23 @@ inline ThreadEngineStarter<ResultType> startFilteredReduced(QThreadPool *pool,
|
|||||||
//! [QtConcurrent-6]
|
//! [QtConcurrent-6]
|
||||||
template <typename ResultType, typename Sequence, typename MapFunctor, typename ReduceFunctor>
|
template <typename ResultType, typename Sequence, typename MapFunctor, typename ReduceFunctor>
|
||||||
inline ThreadEngineStarter<ResultType> startFilteredReduced(QThreadPool *pool,
|
inline ThreadEngineStarter<ResultType> startFilteredReduced(QThreadPool *pool,
|
||||||
const Sequence &sequence,
|
Sequence &&sequence,
|
||||||
MapFunctor mapFunctor,
|
MapFunctor mapFunctor,
|
||||||
ReduceFunctor reduceFunctor,
|
ReduceFunctor reduceFunctor,
|
||||||
ResultType &&initialValue,
|
ResultType &&initialValue,
|
||||||
ReduceOptions options)
|
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 >
|
typedef ReduceKernel<ReduceFunctor, ResultType, typename qValueType<Iterator>::value_type >
|
||||||
Reducer;
|
Reducer;
|
||||||
typedef FilteredReducedKernel<ResultType, Iterator, MapFunctor, ReduceFunctor, Reducer>
|
typedef FilteredReducedKernel<ResultType, Iterator, MapFunctor, ReduceFunctor, Reducer>
|
||||||
FilteredReduceType;
|
FilteredReduceType;
|
||||||
typedef SequenceHolder2<Sequence, FilteredReduceType, MapFunctor, ReduceFunctor>
|
typedef SequenceHolder2<DecayedSequence, FilteredReduceType, MapFunctor, ReduceFunctor>
|
||||||
SequenceHolderType;
|
SequenceHolderType;
|
||||||
return startThreadEngine(new SequenceHolderType(pool, sequence, mapFunctor, reduceFunctor,
|
return startThreadEngine(
|
||||||
std::forward<ResultType>(initialValue), options));
|
new SequenceHolderType(pool, std::forward<Sequence>(sequence), mapFunctor,
|
||||||
|
reduceFunctor, std::forward<ResultType>(initialValue), options));
|
||||||
}
|
}
|
||||||
|
|
||||||
//! [QtConcurrent-7]
|
//! [QtConcurrent-7]
|
||||||
|
@ -168,6 +168,7 @@ template<typename Sequence>
|
|||||||
struct SequenceHolder
|
struct SequenceHolder
|
||||||
{
|
{
|
||||||
SequenceHolder(const Sequence &s) : sequence(s) { }
|
SequenceHolder(const Sequence &s) : sequence(s) { }
|
||||||
|
SequenceHolder(Sequence &&s) : sequence(std::move(s)) { }
|
||||||
Sequence sequence;
|
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
|
\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
|
\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
|
\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.
|
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.
|
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
|
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
|
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
|
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
|
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
|
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
|
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.
|
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.
|
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
|
Calls \a mapFunction once for each item in \a sequence. The return value of
|
||||||
each \a mapFunction is passed to \a reduceFunction.
|
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.
|
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.
|
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
|
Calls \a mapFunction once for each item in \a sequence. The return value of
|
||||||
each \a mapFunction is passed to \a reduceFunction.
|
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.
|
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.
|
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
|
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
|
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
|
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
|
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
|
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.
|
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.
|
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.
|
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
|
Calls \a mapFunction once for each item in \a sequence. The return value of
|
||||||
each \a mapFunction is passed to \a reduceFunction.
|
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.
|
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.
|
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
|
Calls \a mapFunction once for each item in \a sequence. The return value of
|
||||||
each \a mapFunction is passed to \a reduceFunction.
|
each \a mapFunction is passed to \a reduceFunction.
|
||||||
|
@ -57,13 +57,13 @@ namespace QtConcurrent {
|
|||||||
|
|
||||||
// map() on sequences
|
// map() on sequences
|
||||||
template <typename Sequence, typename MapFunctor>
|
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);
|
return startMap(pool, sequence.begin(), sequence.end(), map);
|
||||||
}
|
}
|
||||||
|
|
||||||
template <typename Sequence, typename MapFunctor>
|
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);
|
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.
|
// mappedReduced() for sequences.
|
||||||
template <typename ResultType, typename Sequence, typename MapFunctor, typename ReduceFunctor>
|
template <typename ResultType, typename Sequence, typename MapFunctor, typename ReduceFunctor>
|
||||||
QFuture<ResultType> mappedReduced(QThreadPool *pool,
|
QFuture<ResultType> mappedReduced(QThreadPool *pool,
|
||||||
const Sequence &sequence,
|
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>, ResultType>
|
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>
|
template <typename ResultType, typename Sequence, typename MapFunctor, typename ReduceFunctor>
|
||||||
QFuture<ResultType> mappedReduced(const Sequence &sequence,
|
QFuture<ResultType> mappedReduced(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>, ResultType>
|
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,
|
template <typename ResultType, typename Sequence, typename MapFunctor, 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>
|
||||||
QFuture<ResultType> mappedReduced(QThreadPool *pool,
|
QFuture<ResultType> mappedReduced(QThreadPool *pool,
|
||||||
const Sequence &sequence,
|
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 startMappedReduced<QtPrivate::MapResultType<Sequence, MapFunctor>, ResultType>
|
return startMappedReduced<QtPrivate::MapResultType<Sequence, MapFunctor>, ResultType>(
|
||||||
(pool, sequence, map, reduce, ResultType(std::forward<InitialValueType>(initialValue)),
|
pool, std::forward<Sequence>(sequence), map, reduce,
|
||||||
options);
|
ResultType(std::forward<InitialValueType>(initialValue)), options);
|
||||||
}
|
}
|
||||||
|
|
||||||
template <typename ResultType, typename Sequence, typename MapFunctor, typename ReduceFunctor,
|
template <typename ResultType, typename Sequence, typename MapFunctor, 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>
|
||||||
QFuture<ResultType> mappedReduced(const Sequence &sequence,
|
QFuture<ResultType> mappedReduced(Sequence &&sequence,
|
||||||
MapFunctor map,
|
MapFunctor map,
|
||||||
ReduceFunctor reduce,
|
ReduceFunctor reduce,
|
||||||
InitialValueType &&initialValue,
|
InitialValueType &&initialValue,
|
||||||
@ -132,34 +132,34 @@ QFuture<ResultType> mappedReduced(const Sequence &sequence,
|
|||||||
| SequentialReduce))
|
| SequentialReduce))
|
||||||
{
|
{
|
||||||
return startMappedReduced<QtPrivate::MapResultType<Sequence, MapFunctor>, ResultType>
|
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);
|
ResultType(std::forward<InitialValueType>(initialValue)), options);
|
||||||
}
|
}
|
||||||
|
|
||||||
template <typename Sequence, typename MapFunctor, typename ReduceFunctor,
|
template <typename Sequence, typename MapFunctor, typename ReduceFunctor,
|
||||||
typename ResultType = typename QtPrivate::ReduceResultType<ReduceFunctor>::ResultType>
|
typename ResultType = typename QtPrivate::ReduceResultType<ReduceFunctor>::ResultType>
|
||||||
QFuture<ResultType> mappedReduced(QThreadPool *pool,
|
QFuture<ResultType> mappedReduced(QThreadPool *pool,
|
||||||
const Sequence &sequence,
|
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>, ResultType>
|
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,
|
template <typename Sequence, typename MapFunctor, typename ReduceFunctor,
|
||||||
typename ResultType = typename QtPrivate::ReduceResultType<ReduceFunctor>::ResultType>
|
typename ResultType = typename QtPrivate::ReduceResultType<ReduceFunctor>::ResultType>
|
||||||
QFuture<ResultType> mappedReduced(
|
QFuture<ResultType> mappedReduced(
|
||||||
const Sequence &sequence,
|
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>, ResultType>
|
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,
|
template <typename Sequence, typename MapFunctor, typename ReduceFunctor,
|
||||||
@ -167,23 +167,23 @@ template <typename Sequence, typename MapFunctor, 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>
|
||||||
QFuture<ResultType> mappedReduced(QThreadPool *pool,
|
QFuture<ResultType> mappedReduced(QThreadPool *pool,
|
||||||
const Sequence &sequence,
|
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 startMappedReduced<QtPrivate::MapResultType<Sequence, MapFunctor>, ResultType>
|
return startMappedReduced<QtPrivate::MapResultType<Sequence, MapFunctor>, ResultType>(
|
||||||
(pool, sequence, map, reduce, ResultType(std::forward<InitialValueType>(initialValue)),
|
pool, std::forward<Sequence>(sequence), map, reduce,
|
||||||
options);
|
ResultType(std::forward<InitialValueType>(initialValue)), options);
|
||||||
}
|
}
|
||||||
|
|
||||||
template <typename Sequence, typename MapFunctor, typename ReduceFunctor,
|
template <typename Sequence, 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<ResultType> mappedReduced(const Sequence &sequence,
|
QFuture<ResultType> mappedReduced(Sequence &&sequence,
|
||||||
MapFunctor map,
|
MapFunctor map,
|
||||||
ReduceFunctor reduce,
|
ReduceFunctor reduce,
|
||||||
InitialValueType &&initialValue,
|
InitialValueType &&initialValue,
|
||||||
@ -191,7 +191,7 @@ QFuture<ResultType> mappedReduced(const Sequence &sequence,
|
|||||||
| SequentialReduce))
|
| SequentialReduce))
|
||||||
{
|
{
|
||||||
return startMappedReduced<QtPrivate::MapResultType<Sequence, MapFunctor>, ResultType>
|
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);
|
ResultType(std::forward<InitialValueType>(initialValue)), options);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -320,19 +320,20 @@ QFuture<ResultType> mappedReduced(Iterator begin,
|
|||||||
template <typename Sequence, typename MapFunctor>
|
template <typename Sequence, typename MapFunctor>
|
||||||
QFuture<QtPrivate::MapResultType<Sequence, MapFunctor>> mapped(
|
QFuture<QtPrivate::MapResultType<Sequence, MapFunctor>> mapped(
|
||||||
QThreadPool *pool,
|
QThreadPool *pool,
|
||||||
const Sequence &sequence,
|
Sequence &&sequence,
|
||||||
MapFunctor map)
|
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>
|
template <typename Sequence, typename MapFunctor>
|
||||||
QFuture<QtPrivate::MapResultType<Sequence, MapFunctor>> mapped(
|
QFuture<QtPrivate::MapResultType<Sequence, MapFunctor>> mapped(
|
||||||
const Sequence &sequence,
|
Sequence &&sequence,
|
||||||
MapFunctor map)
|
MapFunctor map)
|
||||||
{
|
{
|
||||||
return startMapped<QtPrivate::MapResultType<Sequence, MapFunctor>>
|
return startMapped<QtPrivate::MapResultType<Sequence, MapFunctor>>
|
||||||
(QThreadPool::globalInstance(), sequence, map);
|
(QThreadPool::globalInstance(), std::forward<Sequence>(sequence), map);
|
||||||
}
|
}
|
||||||
|
|
||||||
// mapped() for iterator ranges.
|
// mapped() for iterator ranges.
|
||||||
@ -358,14 +359,14 @@ QFuture<QtPrivate::MapResultType<Iterator, MapFunctor>> mapped(
|
|||||||
|
|
||||||
// blockingMap() for sequences
|
// blockingMap() for sequences
|
||||||
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)
|
||||||
{
|
{
|
||||||
QFuture<void> future = startMap(pool, sequence.begin(), sequence.end(), map);
|
QFuture<void> future = startMap(pool, sequence.begin(), sequence.end(), map);
|
||||||
future.waitForFinished();
|
future.waitForFinished();
|
||||||
}
|
}
|
||||||
|
|
||||||
template <typename Sequence, typename MapFunctor>
|
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);
|
QFuture<void> future = startMap(QThreadPool::globalInstance(), sequence.begin(), sequence.end(), map);
|
||||||
future.waitForFinished();
|
future.waitForFinished();
|
||||||
@ -389,7 +390,7 @@ void blockingMap(Iterator begin, Iterator end, MapFunctor map)
|
|||||||
// blockingMappedReduced() for sequences
|
// blockingMappedReduced() for sequences
|
||||||
template <typename ResultType, typename Sequence, typename MapFunctor, typename ReduceFunctor>
|
template <typename ResultType, typename Sequence, typename MapFunctor, typename ReduceFunctor>
|
||||||
ResultType blockingMappedReduced(QThreadPool *pool,
|
ResultType blockingMappedReduced(QThreadPool *pool,
|
||||||
const Sequence &sequence,
|
Sequence &&sequence,
|
||||||
MapFunctor map,
|
MapFunctor map,
|
||||||
ReduceFunctor reduce,
|
ReduceFunctor reduce,
|
||||||
ReduceOptions options = ReduceOptions(UnorderedReduce
|
ReduceOptions options = ReduceOptions(UnorderedReduce
|
||||||
@ -397,12 +398,12 @@ ResultType blockingMappedReduced(QThreadPool *pool,
|
|||||||
{
|
{
|
||||||
QFuture<ResultType> future = QtConcurrent::startMappedReduced
|
QFuture<ResultType> future = QtConcurrent::startMappedReduced
|
||||||
<QtPrivate::MapResultType<Sequence, MapFunctor>, ResultType>
|
<QtPrivate::MapResultType<Sequence, MapFunctor>, ResultType>
|
||||||
(pool, sequence, map, reduce, options);
|
(pool, std::forward<Sequence>(sequence), map, reduce, options);
|
||||||
return future.result();
|
return future.result();
|
||||||
}
|
}
|
||||||
|
|
||||||
template <typename ResultType, typename Sequence, typename MapFunctor, typename ReduceFunctor>
|
template <typename ResultType, typename Sequence, typename MapFunctor, typename ReduceFunctor>
|
||||||
ResultType blockingMappedReduced(const Sequence &sequence,
|
ResultType blockingMappedReduced(Sequence &&sequence,
|
||||||
MapFunctor map,
|
MapFunctor map,
|
||||||
ReduceFunctor reduce,
|
ReduceFunctor reduce,
|
||||||
ReduceOptions options = ReduceOptions(UnorderedReduce
|
ReduceOptions options = ReduceOptions(UnorderedReduce
|
||||||
@ -410,7 +411,7 @@ ResultType blockingMappedReduced(const Sequence &sequence,
|
|||||||
{
|
{
|
||||||
QFuture<ResultType> future = QtConcurrent::startMappedReduced
|
QFuture<ResultType> future = QtConcurrent::startMappedReduced
|
||||||
<QtPrivate::MapResultType<Sequence, MapFunctor>, ResultType>
|
<QtPrivate::MapResultType<Sequence, MapFunctor>, ResultType>
|
||||||
(QThreadPool::globalInstance(), sequence, map, reduce, options);
|
(QThreadPool::globalInstance(), std::forward<Sequence>(sequence), map, reduce, options);
|
||||||
return future.result();
|
return future.result();
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -418,7 +419,7 @@ template <typename ResultType, typename Sequence, typename MapFunctor, typename
|
|||||||
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>
|
||||||
ResultType blockingMappedReduced(QThreadPool *pool,
|
ResultType blockingMappedReduced(QThreadPool *pool,
|
||||||
const Sequence &sequence,
|
Sequence &&sequence,
|
||||||
MapFunctor map,
|
MapFunctor map,
|
||||||
ReduceFunctor reduce,
|
ReduceFunctor reduce,
|
||||||
InitialValueType &&initialValue,
|
InitialValueType &&initialValue,
|
||||||
@ -426,16 +427,16 @@ ResultType blockingMappedReduced(QThreadPool *pool,
|
|||||||
| SequentialReduce))
|
| SequentialReduce))
|
||||||
{
|
{
|
||||||
QFuture<ResultType> future = 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, std::forward<Sequence>(sequence), map, reduce,
|
||||||
options);
|
ResultType(std::forward<InitialValueType>(initialValue)), options);
|
||||||
return future.result();
|
return future.result();
|
||||||
}
|
}
|
||||||
|
|
||||||
template <typename ResultType, typename Sequence, typename MapFunctor, typename ReduceFunctor,
|
template <typename ResultType, typename Sequence, typename MapFunctor, 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>
|
||||||
ResultType blockingMappedReduced(const Sequence &sequence,
|
ResultType blockingMappedReduced(Sequence &&sequence,
|
||||||
MapFunctor map,
|
MapFunctor map,
|
||||||
ReduceFunctor reduce,
|
ReduceFunctor reduce,
|
||||||
InitialValueType &&initialValue,
|
InitialValueType &&initialValue,
|
||||||
@ -444,7 +445,7 @@ ResultType blockingMappedReduced(const Sequence &sequence,
|
|||||||
{
|
{
|
||||||
QFuture<ResultType> future = QtConcurrent::startMappedReduced
|
QFuture<ResultType> future = QtConcurrent::startMappedReduced
|
||||||
<QtPrivate::MapResultType<Sequence, MapFunctor>, ResultType>
|
<QtPrivate::MapResultType<Sequence, MapFunctor>, ResultType>
|
||||||
(QThreadPool::globalInstance(), sequence, map, reduce,
|
(QThreadPool::globalInstance(), std::forward<Sequence>(sequence), map, reduce,
|
||||||
ResultType(std::forward<InitialValueType>(initialValue)), options);
|
ResultType(std::forward<InitialValueType>(initialValue)), options);
|
||||||
return future.result();
|
return future.result();
|
||||||
}
|
}
|
||||||
@ -452,7 +453,7 @@ ResultType blockingMappedReduced(const Sequence &sequence,
|
|||||||
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>
|
||||||
ResultType blockingMappedReduced(QThreadPool *pool,
|
ResultType blockingMappedReduced(QThreadPool *pool,
|
||||||
const Sequence &sequence,
|
Sequence &&sequence,
|
||||||
MapFunctor map,
|
MapFunctor map,
|
||||||
ReduceFunctor reduce,
|
ReduceFunctor reduce,
|
||||||
ReduceOptions options = ReduceOptions(UnorderedReduce
|
ReduceOptions options = ReduceOptions(UnorderedReduce
|
||||||
@ -460,13 +461,13 @@ ResultType blockingMappedReduced(QThreadPool *pool,
|
|||||||
{
|
{
|
||||||
QFuture<ResultType> future = QtConcurrent::startMappedReduced
|
QFuture<ResultType> future = QtConcurrent::startMappedReduced
|
||||||
<QtPrivate::MapResultType<Sequence, MapFunctor>, ResultType>
|
<QtPrivate::MapResultType<Sequence, MapFunctor>, ResultType>
|
||||||
(pool, sequence, map, reduce, options);
|
(pool, std::forward<Sequence>(sequence), map, reduce, options);
|
||||||
return future.result();
|
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>
|
||||||
ResultType blockingMappedReduced(const Sequence &sequence,
|
ResultType blockingMappedReduced(Sequence &&sequence,
|
||||||
MapFunctor map,
|
MapFunctor map,
|
||||||
ReduceFunctor reduce,
|
ReduceFunctor reduce,
|
||||||
ReduceOptions options = ReduceOptions(UnorderedReduce
|
ReduceOptions options = ReduceOptions(UnorderedReduce
|
||||||
@ -474,7 +475,7 @@ ResultType blockingMappedReduced(const Sequence &sequence,
|
|||||||
{
|
{
|
||||||
QFuture<ResultType> future = QtConcurrent::startMappedReduced
|
QFuture<ResultType> future = QtConcurrent::startMappedReduced
|
||||||
<QtPrivate::MapResultType<Sequence, MapFunctor>, ResultType>
|
<QtPrivate::MapResultType<Sequence, MapFunctor>, ResultType>
|
||||||
(QThreadPool::globalInstance(), sequence, map, reduce, options);
|
(QThreadPool::globalInstance(), std::forward<Sequence>(sequence), map, reduce, options);
|
||||||
return future.result();
|
return future.result();
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -483,7 +484,7 @@ template <typename MapFunctor, typename ReduceFunctor, typename Sequence,
|
|||||||
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>
|
||||||
ResultType blockingMappedReduced(QThreadPool *pool,
|
ResultType blockingMappedReduced(QThreadPool *pool,
|
||||||
const Sequence &sequence,
|
Sequence &&sequence,
|
||||||
MapFunctor map,
|
MapFunctor map,
|
||||||
ReduceFunctor reduce,
|
ReduceFunctor reduce,
|
||||||
InitialValueType &&initialValue,
|
InitialValueType &&initialValue,
|
||||||
@ -492,8 +493,8 @@ ResultType blockingMappedReduced(QThreadPool *pool,
|
|||||||
{
|
{
|
||||||
QFuture<ResultType> future = 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, std::forward<Sequence>(sequence), map, reduce,
|
||||||
options);
|
ResultType(std::forward<InitialValueType>(initialValue)), options);
|
||||||
return future.result();
|
return future.result();
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -501,7 +502,7 @@ 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>
|
||||||
ResultType blockingMappedReduced(const Sequence &sequence,
|
ResultType blockingMappedReduced(Sequence &&sequence,
|
||||||
MapFunctor map,
|
MapFunctor map,
|
||||||
ReduceFunctor reduce,
|
ReduceFunctor reduce,
|
||||||
InitialValueType &&initialValue,
|
InitialValueType &&initialValue,
|
||||||
@ -510,7 +511,7 @@ ResultType blockingMappedReduced(const Sequence &sequence,
|
|||||||
{
|
{
|
||||||
QFuture<ResultType> future = QtConcurrent::startMappedReduced
|
QFuture<ResultType> future = QtConcurrent::startMappedReduced
|
||||||
<QtPrivate::MapResultType<Sequence, MapFunctor>, ResultType>
|
<QtPrivate::MapResultType<Sequence, MapFunctor>, ResultType>
|
||||||
(QThreadPool::globalInstance(), sequence, map, reduce,
|
(QThreadPool::globalInstance(), std::forward<Sequence>(sequence), map, reduce,
|
||||||
ResultType(std::forward<InitialValueType>(initialValue)), options);
|
ResultType(std::forward<InitialValueType>(initialValue)), options);
|
||||||
return future.result();
|
return future.result();
|
||||||
}
|
}
|
||||||
@ -654,35 +655,37 @@ ResultType blockingMappedReduced(Iterator begin,
|
|||||||
|
|
||||||
// mapped() for sequences with a different putput sequence type.
|
// mapped() for sequences with a different putput sequence type.
|
||||||
template <typename OutputSequence, typename InputSequence, typename MapFunctor>
|
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);
|
QtPrivate::PushBackWrapper(), OrderedReduce);
|
||||||
}
|
}
|
||||||
|
|
||||||
template <typename OutputSequence, typename InputSequence, typename MapFunctor>
|
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,
|
return blockingMappedReduced<OutputSequence>(QThreadPool::globalInstance(),
|
||||||
QtPrivate::PushBackWrapper(), OrderedReduce);
|
std::forward<InputSequence>(sequence), map,
|
||||||
|
QtPrivate::PushBackWrapper(), OrderedReduce);
|
||||||
}
|
}
|
||||||
|
|
||||||
template <typename MapFunctor, typename InputSequence>
|
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,
|
using OutputSequence = typename QtPrivate::MapSequenceResultType<std::decay_t<InputSequence>,
|
||||||
MapFunctor>::ResultType;
|
MapFunctor>::ResultType;
|
||||||
return blockingMappedReduced<OutputSequence>(pool, sequence, map, QtPrivate::PushBackWrapper(),
|
return blockingMappedReduced<OutputSequence>(pool, std::forward<InputSequence>(sequence), map,
|
||||||
OrderedReduce);
|
QtPrivate::PushBackWrapper(), OrderedReduce);
|
||||||
}
|
}
|
||||||
|
|
||||||
template <typename MapFunctor, typename InputSequence>
|
template <typename MapFunctor, typename InputSequence>
|
||||||
auto blockingMapped(const InputSequence &sequence, MapFunctor map)
|
auto blockingMapped(InputSequence &&sequence, MapFunctor map)
|
||||||
{
|
{
|
||||||
using OutputSequence = typename QtPrivate::MapSequenceResultType<InputSequence,
|
using OutputSequence = typename QtPrivate::MapSequenceResultType<std::decay_t<InputSequence>,
|
||||||
MapFunctor>::ResultType;
|
MapFunctor>::ResultType;
|
||||||
return blockingMappedReduced<OutputSequence>(QThreadPool::globalInstance(), sequence, map,
|
return blockingMappedReduced<OutputSequence>(QThreadPool::globalInstance(),
|
||||||
QtPrivate::PushBackWrapper(), OrderedReduce);
|
std::forward<InputSequence>(sequence), map,
|
||||||
|
QtPrivate::PushBackWrapper(), OrderedReduce);
|
||||||
}
|
}
|
||||||
|
|
||||||
// mapped() for iterator ranges
|
// mapped() for iterator ranges
|
||||||
|
@ -221,6 +221,11 @@ inline ThreadEngineStarter<T> startMapped(QThreadPool *pool, Iterator begin,
|
|||||||
template <typename Sequence, typename Base, typename Functor>
|
template <typename Sequence, typename Base, typename Functor>
|
||||||
struct SequenceHolder1 : private QtPrivate::SequenceHolder<Sequence>, public Base
|
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)
|
SequenceHolder1(QThreadPool *pool, const Sequence &_sequence, Functor functor)
|
||||||
: QtPrivate::SequenceHolder<Sequence>(_sequence),
|
: QtPrivate::SequenceHolder<Sequence>(_sequence),
|
||||||
Base(pool, this->sequence.cbegin(), this->sequence.cend(), functor)
|
Base(pool, this->sequence.cbegin(), this->sequence.cend(), functor)
|
||||||
@ -237,33 +242,37 @@ struct SequenceHolder1 : private QtPrivate::SequenceHolder<Sequence>, public Bas
|
|||||||
|
|
||||||
//! [qtconcurrentmapkernel-3]
|
//! [qtconcurrentmapkernel-3]
|
||||||
template <typename T, typename Sequence, typename Functor>
|
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)
|
Functor functor)
|
||||||
{
|
{
|
||||||
typedef SequenceHolder1<Sequence,
|
using DecayedSequence = std::decay_t<Sequence>;
|
||||||
MappedEachKernel<typename Sequence::const_iterator , Functor>, Functor>
|
typedef SequenceHolder1<DecayedSequence,
|
||||||
SequenceHolderType;
|
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]
|
//! [qtconcurrentmapkernel-4]
|
||||||
template <typename IntermediateType, typename ResultType, typename Sequence, typename MapFunctor,
|
template <typename IntermediateType, typename ResultType, typename Sequence, typename MapFunctor,
|
||||||
typename ReduceFunctor>
|
typename ReduceFunctor>
|
||||||
inline ThreadEngineStarter<ResultType> startMappedReduced(QThreadPool *pool,
|
inline ThreadEngineStarter<ResultType> startMappedReduced(QThreadPool *pool,
|
||||||
const Sequence & sequence,
|
Sequence &&sequence,
|
||||||
MapFunctor mapFunctor,
|
MapFunctor mapFunctor,
|
||||||
ReduceFunctor reduceFunctor,
|
ReduceFunctor reduceFunctor,
|
||||||
ReduceOptions options)
|
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 ReduceKernel<ReduceFunctor, ResultType, IntermediateType> Reducer;
|
||||||
typedef MappedReducedKernel<ResultType, Iterator, MapFunctor, ReduceFunctor, Reducer>
|
typedef MappedReducedKernel<ResultType, Iterator, MapFunctor, ReduceFunctor, Reducer>
|
||||||
MappedReduceType;
|
MappedReduceType;
|
||||||
typedef SequenceHolder2<Sequence, MappedReduceType, MapFunctor, ReduceFunctor>
|
typedef SequenceHolder2<DecayedSequence, MappedReduceType, MapFunctor, ReduceFunctor>
|
||||||
SequenceHolderType;
|
SequenceHolderType;
|
||||||
return startThreadEngine(new SequenceHolderType(pool, sequence, mapFunctor, reduceFunctor,
|
return startThreadEngine(new SequenceHolderType(pool, std::forward<Sequence>(sequence),
|
||||||
options));
|
mapFunctor, reduceFunctor, options));
|
||||||
}
|
}
|
||||||
|
|
||||||
//! [qtconcurrentmapkernel-5]
|
//! [qtconcurrentmapkernel-5]
|
||||||
@ -287,21 +296,22 @@ inline ThreadEngineStarter<ResultType> startMappedReduced(QThreadPool *pool,
|
|||||||
template <typename IntermediateType, typename ResultType, typename Sequence, typename MapFunctor,
|
template <typename IntermediateType, typename ResultType, typename Sequence, typename MapFunctor,
|
||||||
typename ReduceFunctor>
|
typename ReduceFunctor>
|
||||||
inline ThreadEngineStarter<ResultType> startMappedReduced(QThreadPool *pool,
|
inline ThreadEngineStarter<ResultType> startMappedReduced(QThreadPool *pool,
|
||||||
const Sequence &sequence,
|
Sequence &&sequence,
|
||||||
MapFunctor mapFunctor,
|
MapFunctor mapFunctor,
|
||||||
ReduceFunctor reduceFunctor,
|
ReduceFunctor reduceFunctor,
|
||||||
ResultType &&initialValue,
|
ResultType &&initialValue,
|
||||||
ReduceOptions options)
|
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 ReduceKernel<ReduceFunctor, ResultType, IntermediateType> Reducer;
|
||||||
typedef MappedReducedKernel<ResultType, Iterator, MapFunctor, ReduceFunctor, Reducer>
|
typedef MappedReducedKernel<ResultType, Iterator, MapFunctor, ReduceFunctor, Reducer>
|
||||||
MappedReduceType;
|
MappedReduceType;
|
||||||
typedef SequenceHolder2<Sequence, MappedReduceType, MapFunctor, ReduceFunctor>
|
typedef SequenceHolder2<DecayedSequence, MappedReduceType, MapFunctor, ReduceFunctor>
|
||||||
SequenceHolderType;
|
SequenceHolderType;
|
||||||
return startThreadEngine(new SequenceHolderType(
|
return startThreadEngine(
|
||||||
pool, sequence, mapFunctor, reduceFunctor, std::forward<ResultType>(initialValue),
|
new SequenceHolderType(pool, std::forward<Sequence>(sequence), mapFunctor,
|
||||||
options));
|
reduceFunctor, std::forward<ResultType>(initialValue), options));
|
||||||
}
|
}
|
||||||
|
|
||||||
//! [qtconcurrentmapkernel-7]
|
//! [qtconcurrentmapkernel-7]
|
||||||
|
@ -232,6 +232,13 @@ struct SequenceHolder2 : private QtPrivate::SequenceHolder<Sequence>, public Bas
|
|||||||
reduceOptions)
|
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>
|
template<typename InitialValueType>
|
||||||
SequenceHolder2(QThreadPool *pool, const Sequence &_sequence, Functor1 functor1,
|
SequenceHolder2(QThreadPool *pool, const Sequence &_sequence, Functor1 functor1,
|
||||||
Functor2 functor2, InitialValueType &&initialValue, ReduceOptions reduceOptions)
|
Functor2 functor2, InitialValueType &&initialValue, ReduceOptions reduceOptions)
|
||||||
@ -240,6 +247,14 @@ struct SequenceHolder2 : private QtPrivate::SequenceHolder<Sequence>, public Bas
|
|||||||
std::forward<InitialValueType>(initialValue), reduceOptions)
|
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
|
void finish() override
|
||||||
{
|
{
|
||||||
Base::finish();
|
Base::finish();
|
||||||
|
@ -41,7 +41,8 @@ class tst_QtConcurrentMap : public QObject
|
|||||||
Q_OBJECT
|
Q_OBJECT
|
||||||
private slots:
|
private slots:
|
||||||
void map();
|
void map();
|
||||||
void blocking_map();
|
void blockingMap();
|
||||||
|
void mapOnRvalue();
|
||||||
void mapped();
|
void mapped();
|
||||||
void mappedThreadPool();
|
void mappedThreadPool();
|
||||||
void mappedReduced();
|
void mappedReduced();
|
||||||
@ -211,7 +212,7 @@ void tst_QtConcurrentMap::map()
|
|||||||
#endif
|
#endif
|
||||||
}
|
}
|
||||||
|
|
||||||
void tst_QtConcurrentMap::blocking_map()
|
void tst_QtConcurrentMap::blockingMap()
|
||||||
{
|
{
|
||||||
// functors take arguments by reference, modifying the sequence in place
|
// functors take arguments by reference, modifying the sequence in place
|
||||||
{
|
{
|
||||||
@ -323,6 +324,54 @@ void tst_QtConcurrentMap::blocking_map()
|
|||||||
#endif
|
#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 multiplyBy2(int x)
|
||||||
{
|
{
|
||||||
int y = x * 2;
|
int y = x * 2;
|
||||||
|
Loading…
x
Reference in New Issue
Block a user