summaryrefslogtreecommitdiffstats
path: root/src/concurrent/qtconcurrentfilter.cpp
diff options
context:
space:
mode:
authorKarsten Heimrich <karsten.heimrich@qt.io>2020-03-26 15:47:04 +0100
committerKarsten Heimrich <karsten.heimrich@qt.io>2020-04-14 19:06:27 +0200
commit786b48878f37edafd5eb928ed0f4d046ee1d6bec (patch)
tree7dffd263964b1375dd9814d4edcfc675d7489e84 /src/concurrent/qtconcurrentfilter.cpp
parent678b9f78a5af4513ed4e988de90148584a2ae90d (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/qtconcurrentfilter.cpp')
-rw-r--r--src/concurrent/qtconcurrentfilter.cpp23
1 files changed, 21 insertions, 2 deletions
diff --git a/src/concurrent/qtconcurrentfilter.cpp b/src/concurrent/qtconcurrentfilter.cpp
index bac8ac59fc..789188911e 100644
--- a/src/concurrent/qtconcurrentfilter.cpp
+++ b/src/concurrent/qtconcurrentfilter.cpp
@@ -144,8 +144,7 @@
QtConcurrent::filter(), QtConcurrent::filtered(), and
QtConcurrent::filteredReduced() accept function objects
for the filter 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_qtconcurrentfilter.cpp 13
@@ -155,6 +154,26 @@
\snippet code/src_concurrent_qtconcurrentfilter.cpp 14
+ \section2 Using Lambda Expressions
+
+ QtConcurrent::filter(), QtConcurrent::filtered(), and
+ QtConcurrent::filteredReduced() accept lambda expressions for the filter and
+ reduce function:
+
+ \snippet code/src_concurrent_qtconcurrentfilter.cpp 15
+
+ When using QtConcurrent::filteredReduced() or
+ QtConcurrent::blockingFilteredReduced(), you can mix the use of normal
+ functions, member functions and lambda expressions freely.
+
+ \snippet code/src_concurrent_qtconcurrentfilter.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_qtconcurrentfilter.cpp 17
+
\section2 Wrapping Functions that Take Multiple Arguments
If you want to use a filter function takes more than one argument, you can