diff options
author | Karsten Heimrich <karsten.heimrich@qt.io> | 2020-03-26 15:47:04 +0100 |
---|---|---|
committer | Karsten Heimrich <karsten.heimrich@qt.io> | 2020-04-14 19:06:27 +0200 |
commit | 786b48878f37edafd5eb928ed0f4d046ee1d6bec (patch) | |
tree | 7dffd263964b1375dd9814d4edcfc675d7489e84 /src/concurrent/qtconcurrentmap.cpp | |
parent | 678b9f78a5af4513ed4e988de90148584a2ae90d (diff) |
Improve Map|Map-Reduce and Filter|Filter-Reduce implementation
* support lambda expressions
* remove the need to specify result_type
* use std::invoke to apply map|filter function
* remove usage of FunctionWrapper* and createFunctionWrapper
Task-number: QTBUG-33735
Task-number: QTBUG-82646
Change-Id: Ibcbe4278f0742c29182bd506081db0abb516f85f
Reviewed-by: MÃ¥rten Nordheim <marten.nordheim@qt.io>
Reviewed-by: Sona Kurazyan <sona.kurazyan@qt.io>
Diffstat (limited to 'src/concurrent/qtconcurrentmap.cpp')
-rw-r--r-- | src/concurrent/qtconcurrentmap.cpp | 51 |
1 files changed, 23 insertions, 28 deletions
diff --git a/src/concurrent/qtconcurrentmap.cpp b/src/concurrent/qtconcurrentmap.cpp index 92fe7a98f2..2ad5483540 100644 --- a/src/concurrent/qtconcurrentmap.cpp +++ b/src/concurrent/qtconcurrentmap.cpp @@ -270,8 +270,7 @@ QtConcurrent::map(), QtConcurrent::mapped(), and QtConcurrent::mappedReduced() accept function objects for the map function. These function objects can be used to - add state to a function call. The result_type typedef must define the - result type of the function call operator: + add state to a function call: \snippet code/src_concurrent_qtconcurrentmap.cpp 14 @@ -281,6 +280,26 @@ \snippet code/src_concurrent_qtconcurrentmap.cpp 11 + \section2 Using Lambda Expressions + + QtConcurrent::map(), QtConcurrent::mapped(), and + QtConcurrent::mappedReduced() accept lambda expressions for the map and + reduce function: + + \snippet code/src_concurrent_qtconcurrentmap.cpp 15 + + When using QtConcurrent::mappedReduced() or + QtConcurrent::blockingMappedReduced(), you can mix the use of normal + functions, member functions and lambda expressions freely. + + \snippet code/src_concurrent_qtconcurrentmap.cpp 16 + + For the reduce function, lambda expressions are not directly supported. + Lambda expressions can, however, be used when the type of the reduction + result is explicitly specified: + + \snippet code/src_concurrent_qtconcurrentmap.cpp 17 + \section2 Wrapping Functions that Take Multiple Arguments If you want to use a map function that takes more than one argument you can @@ -321,7 +340,7 @@ */ /*! - \fn template <typename Sequence, typename MapFunctor> QFuture<typename QtPrivate::MapResultType<void, MapFunctor>::ResultType> QtConcurrent::mapped(const Sequence &sequence, MapFunctor function) + \fn template <typename Sequence, typename MapFunctor> QFuture<QtPrivate::MapResultType<Sequence, MapFunctor>> QtConcurrent::mapped(const Sequence &sequence, MapFunctor function) Calls \a function once for each item in \a sequence and returns a future with each mapped item as a result. You can use QFuture::const_iterator or @@ -331,7 +350,7 @@ */ /*! - \fn template <typename Iterator, typename MapFunctor> QFuture<typename QtPrivate::MapResultType<void, MapFunctor>::ResultType> QtConcurrent::mapped(Iterator begin, Iterator end, MapFunctor function) + \fn template <typename Iterator, typename MapFunctor> QFuture<QtPrivate::MapResultType<Iterator, MapFunctor>> QtConcurrent::mapped(Iterator begin, Iterator end, MapFunctor function) Calls \a function once for each item from \a begin to \a end and returns a future with each mapped item as a result. You can use @@ -522,27 +541,3 @@ \sa blockingMappedReduced(), {Concurrent Map and Map-Reduce} */ - -/*! - \class QtConcurrent::FunctionWrapper1 - \inmodule QtConcurrent - \internal -*/ - -/*! - \class QtConcurrent::MemberFunctionWrapper - \inmodule QtConcurrent - \internal -*/ - -/*! - \class QtConcurrent::MemberFunctionWrapper1 - \inmodule QtConcurrent - \internal -*/ - -/*! - \class QtConcurrent::ConstMemberFunctionWrapper - \inmodule QtConcurrent - \internal -*/ |