diff options
author | Sona Kurazyan <sona.kurazyan@qt.io> | 2021-07-22 18:49:45 +0200 |
---|---|---|
committer | Sona Kurazyan <sona.kurazyan@qt.io> | 2021-08-18 22:31:17 +0200 |
commit | 8aefbe67bf445d51f41c16ec00bc5ce3ec18ded5 (patch) | |
tree | 5485d33e6d07b3d19b8dfd794b799fb223321bfb /src/concurrent | |
parent | 96810e3863272eb5463ba5c07d82544810bdb3f8 (diff) |
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.
Pick-to: 6.1 6.2
Change-Id: If438caa6d705d9036dae45278fb26e080918da89
Reviewed-by: Karsten Heimrich <karsten.heimrich@qt.io>
Reviewed-by: MÃ¥rten Nordheim <marten.nordheim@qt.io>
Diffstat (limited to 'src/concurrent')
4 files changed, 18 insertions, 8 deletions
diff --git a/src/concurrent/doc/snippets/code/src_concurrent_qtconcurrentfilter.cpp b/src/concurrent/doc/snippets/code/src_concurrent_qtconcurrentfilter.cpp index b9ff35c798..30bbf0af0a 100644 --- a/src/concurrent/doc/snippets/code/src_concurrent_qtconcurrentfilter.cpp +++ b/src/concurrent/doc/snippets/code/src_concurrent_qtconcurrentfilter.cpp @@ -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); diff --git a/src/concurrent/doc/snippets/code/src_concurrent_qtconcurrentmap.cpp b/src/concurrent/doc/snippets/code/src_concurrent_qtconcurrentmap.cpp index 9c91715ac0..c57f3bf6db 100644 --- a/src/concurrent/doc/snippets/code/src_concurrent_qtconcurrentmap.cpp +++ b/src/concurrent/doc/snippets/code/src_concurrent_qtconcurrentmap.cpp @@ -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] diff --git a/src/concurrent/qtconcurrentfilter.cpp b/src/concurrent/qtconcurrentfilter.cpp index 663507be35..ae913a839e 100644 --- a/src/concurrent/qtconcurrentfilter.cpp +++ b/src/concurrent/qtconcurrentfilter.cpp @@ -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 diff --git a/src/concurrent/qtconcurrentmap.cpp b/src/concurrent/qtconcurrentmap.cpp index 8abfec4baf..26f84cf054 100644 --- a/src/concurrent/qtconcurrentmap.cpp +++ b/src/concurrent/qtconcurrentmap.cpp @@ -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 |