summaryrefslogtreecommitdiffstats
path: root/src/corelib/doc/snippets/code
diff options
context:
space:
mode:
authorGiuseppe D'Angelo <giuseppe.dangelo@kdab.com>2019-06-30 12:02:24 +0200
committerGiuseppe D'Angelo <giuseppe.dangelo@kdab.com>2019-07-04 09:22:19 +0200
commit656117100b52bb404828d02106fd0dee760b6019 (patch)
tree51144d7f3baa735bfdede4c0ba047fc4c1496478 /src/corelib/doc/snippets/code
parent1bddb4ad7d33ba92ce4387bcaba55c2489dc6615 (diff)
QSet docs: don't use std::find for lookups
That code would normally call for QSet::find instead (Uniform Container Find cannot come soon enough). Since the code is showcasing a STL algorithm usage, port it to std::find_if to showcase a real use case. As a drive-by: fix the usage of endl with std::cout. (Ok, it's just a variable called "cout", and I'd argue that in example code "cout" is not the name of a QTextStream). Change-Id: I8686178b33c31552eb4d909a4089453d60994b79 Reviewed-by: Marc Mutz <marc.mutz@kdab.com>
Diffstat (limited to 'src/corelib/doc/snippets/code')
-rw-r--r--src/corelib/doc/snippets/code/doc_src_qset.cpp10
1 files changed, 6 insertions, 4 deletions
diff --git a/src/corelib/doc/snippets/code/doc_src_qset.cpp b/src/corelib/doc/snippets/code/doc_src_qset.cpp
index 4248c49642..96ef07738b 100644
--- a/src/corelib/doc/snippets/code/doc_src_qset.cpp
+++ b/src/corelib/doc/snippets/code/doc_src_qset.cpp
@@ -131,9 +131,10 @@ while (i != set.end()) {
//! [10]
QSet<QString> set;
...
-QSet<QString>::iterator it = std::find(set.begin(), set.end(), "Jeanette");
+const auto predicate = [](const QString &s) { return s.compare("Jeanette", Qt::CaseInsensitive) == 0; };
+QSet<QString>::iterator it = std::find_if(set.begin(), set.end(), predicate);
if (it != set.end())
- cout << "Found Jeanette" << Qt::endl;
+ cout << "Found Jeanette" << endl;
//! [10]
@@ -150,9 +151,10 @@ for (i = set.begin(); i != set.end(); ++i)
//! [12]
QSet<QString> set;
...
-QSet<QString>::iterator it = std::find(set.begin(), set.end(), "Jeanette");
+const auto predicate = [](const QString &s) { return s.compare("Jeanette", Qt::CaseInsensitive) == 0; };
+QSet<QString>::const_iterator it = std::find_if(set.cbegin(), set.cend(), predicate);
if (it != set.constEnd())
- cout << "Found Jeanette" << Qt::endl;
+ cout << "Found Jeanette" << endl;
//! [12]