QtConcurrent: fix examples of overloaded methods in docs

Wrap the overloaded methods in qOverload(), to make the examples
compile.

Also remove the extra whitespaces when declaring nested templates.

Change-Id: If438caa6d705d9036dae45278fb26e080918da89
Reviewed-by: Karsten Heimrich <karsten.heimrich@qt.io>
Reviewed-by: Mårten Nordheim <marten.nordheim@qt.io>
(cherry picked from commit 8aefbe67bf445d51f41c16ec00bc5ce3ec18ded5)
Reviewed-by: Qt Cherry-pick Bot <cherrypick_bot@qt-project.org>
This commit is contained in:
Sona Kurazyan 2021-07-22 18:49:45 +02:00 committed by Qt Cherry-pick Bot
parent 88373a370a
commit bcc7a9dd7a
4 changed files with 18 additions and 8 deletions

View File

@ -82,7 +82,7 @@ void addToDictionary(QSet<QString> &dictionary, const QString &string)
}
QStringList strings = ...;
QFuture<QSet<QString> > dictionary = QtConcurrent::filteredReduced(strings, allLowerCase, addToDictionary);
QFuture<QSet<QString>> dictionary = QtConcurrent::filteredReduced(strings, allLowerCase, addToDictionary);
//! [4]
@ -93,7 +93,7 @@ QFuture<QString> lowerCaseStrings = QtConcurrent::filtered(strings.constBegin(),
// filter in-place only works on non-const iterators
QFuture<void> future = QtConcurrent::filter(strings.begin(), strings.end(), allLowerCase);
QFuture<QSet<QString> > dictionary = QtConcurrent::filteredReduced(strings.constBegin(), strings.constEnd(), allLowerCase, addToDictionary);
QFuture<QSet<QString>> dictionary = QtConcurrent::filteredReduced(strings.constBegin(), strings.constEnd(), allLowerCase, addToDictionary);
//! [5]
@ -121,7 +121,8 @@ QFuture<QImage> grayscaleImages = QtConcurrent::filtered(images, &QImage::isGray
// create a set of all printable characters
QList<QChar> characters = ...;
QFuture<QSet<QChar> > set = QtConcurrent::filteredReduced(characters, &QChar::isPrint, &QSet<QChar>::insert);
QFuture<QSet<QChar>> set = QtConcurrent::filteredReduced(characters, qOverload<>(&QChar::isPrint),
qOverload<const QChar&>(&QSet<QChar>::insert));
//! [7]
@ -131,7 +132,8 @@ QFuture<QSet<QChar> > set = QtConcurrent::filteredReduced(characters, &QChar::is
// create a dictionary of all lower cased strings
extern bool allLowerCase(const QString &string);
QStringList strings = ...;
QFuture<QSet<int> > averageWordLength = QtConcurrent::filteredReduced(strings, allLowerCase, QSet<QString>::insert);
QFuture<QSet<QString>> lowerCase = QtConcurrent::filteredReduced(strings, allLowerCase,
qOverload<const QString&>(&QSet<QString>::insert));
// create a collage of all gray scale images
extern void addToCollage(QImage &collage, const QImage &grayscaleImage);

View File

@ -135,7 +135,8 @@ QFuture<QImage> bgrImages = QtConcurrent::mapped(images,
// Create a set of the lengths of all strings in a list.
QStringList strings = ...;
QFuture<QSet<int> > wordLengths = QtConcurrent::mappedReduced(strings, &QString::length, &QSet<int>::insert);
QFuture<QSet<int>> wordLengths = QtConcurrent::mappedReduced(strings, &QString::length,
qOverload<const int&>(&QSet<int>::insert));
//! [8]
@ -150,7 +151,8 @@ QFuture<int> averageWordLength = QtConcurrent::mappedReduced(strings, &QString::
// Create a set of the color distribution of all images in a list.
extern int colorDistribution(const QImage &string);
QList<QImage> images = ...;
QFuture<QSet<int> > totalColorDistribution = QtConcurrent::mappedReduced(images, colorDistribution, QSet<int>::insert);
QFuture<QSet<int>> totalColorDistribution = QtConcurrent::mappedReduced(images, colorDistribution,
qOverload<const int&>(&QSet<int>::insert));
//! [9]

View File

@ -134,7 +134,10 @@
\snippet code/src_concurrent_qtconcurrentfilter.cpp 7
Note that when using QtConcurrent::filteredReduced(), you can mix the use of
Note the use of qOverload. It is needed to resolve the ambiguity for the
methods, that have multiple overloads.
Also note that when using QtConcurrent::filteredReduced(), you can mix the use of
normal and member functions freely:
\snippet code/src_concurrent_qtconcurrentfilter.cpp 8

View File

@ -260,7 +260,10 @@
\snippet code/src_concurrent_qtconcurrentmap.cpp 8
Note that when using QtConcurrent::mappedReduced(), you can mix the use of
Note the use of qOverload. It is needed to resolve the ambiguity for the
methods, that have multiple overloads.
Also note that when using QtConcurrent::mappedReduced(), you can mix the use of
normal and member functions freely:
\snippet code/src_concurrent_qtconcurrentmap.cpp 9