Update QtConcurrent docs and examples for reductor object usage
After 6ebe3d0f08
users don't have to
specify the result type when using functors for as a reductor.
Task-number: QTBUG-88448
Change-Id: I065fed11c1a66833ba0aac3d18e7ff0545247be1
Reviewed-by: Mårten Nordheim <marten.nordheim@qt.io>
This commit is contained in:
parent
c3a9c1ecbc
commit
bd0d8a3adb
@ -177,9 +177,7 @@ struct StringTransform
|
||||
};
|
||||
|
||||
QFuture<QString> fooString =
|
||||
QtConcurrent::filteredReduced<QString>(strings,
|
||||
StartsWith(QLatin1String("Foo")),
|
||||
StringTransform());
|
||||
QtConcurrent::filteredReduced(strings, StartsWith(QLatin1String("Foo")), StringTransform());
|
||||
//! [14]
|
||||
|
||||
//! [15]
|
||||
@ -196,7 +194,7 @@ QList<int> results = future.results();
|
||||
|
||||
// add up all even integers
|
||||
QList<int> list3 { 1, 2, 3, 4 };
|
||||
int sum = QtConcurrent::filteredReduced<int>(list3,
|
||||
QFuture<int> sum = QtConcurrent::filteredReduced(list3,
|
||||
[](int x) {
|
||||
return (x & 1) == 0;
|
||||
},
|
||||
@ -213,7 +211,7 @@ void intSumReduce(int &sum, int x)
|
||||
}
|
||||
|
||||
QList<int> list { 1, 2, 3, 4 };
|
||||
int sum = QtConcurrent::filteredReduced(list,
|
||||
QFuture<int> sum = QtConcurrent::filteredReduced(list,
|
||||
[] (int x) {
|
||||
return (x & 1) == 0;
|
||||
},
|
||||
@ -228,7 +226,7 @@ bool keepEvenIntegers(int x)
|
||||
}
|
||||
|
||||
QList<int> list { 1, 2, 3, 4 };
|
||||
int sum = QtConcurrent::filteredReduced<int>(list,
|
||||
QFuture<int> sum = QtConcurrent::filteredReduced(list,
|
||||
keepEvenIntegers,
|
||||
[](int &sum, int x) {
|
||||
sum += x;
|
||||
|
@ -165,10 +165,8 @@ struct ImageTransform
|
||||
};
|
||||
|
||||
QFuture<QImage> thumbNails =
|
||||
QtConcurrent::mappedReduced<QImage>(images,
|
||||
Scaled(100),
|
||||
ImageTransform(),
|
||||
QtConcurrent::SequentialReduce);
|
||||
QtConcurrent::mappedReduced(images, Scaled(100), ImageTransform(),
|
||||
QtConcurrent::SequentialReduce);
|
||||
//! [11]
|
||||
|
||||
//! [13]
|
||||
@ -223,7 +221,7 @@ QList<QImage> collage = QtConcurrent::mappedReduced(images,
|
||||
//! [16]
|
||||
|
||||
//! [17]
|
||||
QList<QImage> collage = QtConcurrent::mappedReduced<QImage>(images,
|
||||
QList<QImage> collage = QtConcurrent::mappedReduced(images,
|
||||
[&size](const QImage &image) {
|
||||
return image.scaled(size, size);
|
||||
},
|
||||
|
@ -148,9 +148,7 @@
|
||||
|
||||
\snippet code/src_concurrent_qtconcurrentfilter.cpp 13
|
||||
|
||||
For the reduce function, function objects are not directly
|
||||
supported. Function objects can, however, be used
|
||||
when the type of the reduction result is explicitly specified:
|
||||
Function objects are also supported for the reduce function:
|
||||
|
||||
\snippet code/src_concurrent_qtconcurrentfilter.cpp 14
|
||||
|
||||
@ -168,9 +166,7 @@
|
||||
|
||||
\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:
|
||||
You can also pass a lambda as a reduce object:
|
||||
|
||||
\snippet code/src_concurrent_qtconcurrentfilter.cpp 17
|
||||
|
||||
|
@ -274,9 +274,7 @@
|
||||
|
||||
\snippet code/src_concurrent_qtconcurrentmap.cpp 14
|
||||
|
||||
For the reduce function, function objects are not directly
|
||||
supported. Function objects can, however, be used
|
||||
when the type of the reduction result is explicitly specified:
|
||||
Function objects are also supported for the reduce function:
|
||||
|
||||
\snippet code/src_concurrent_qtconcurrentmap.cpp 11
|
||||
|
||||
@ -294,9 +292,7 @@
|
||||
|
||||
\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:
|
||||
You can also pass a lambda as a reduce object:
|
||||
|
||||
\snippet code/src_concurrent_qtconcurrentmap.cpp 17
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user