From 656117100b52bb404828d02106fd0dee760b6019 Mon Sep 17 00:00:00 2001 From: Giuseppe D'Angelo Date: Sun, 30 Jun 2019 12:02:24 +0200 Subject: 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 --- src/corelib/doc/snippets/code/doc_src_qset.cpp | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) (limited to 'src/corelib/doc') 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 set; ... -QSet::iterator it = std::find(set.begin(), set.end(), "Jeanette"); +const auto predicate = [](const QString &s) { return s.compare("Jeanette", Qt::CaseInsensitive) == 0; }; +QSet::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 set; ... -QSet::iterator it = std::find(set.begin(), set.end(), "Jeanette"); +const auto predicate = [](const QString &s) { return s.compare("Jeanette", Qt::CaseInsensitive) == 0; }; +QSet::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] -- cgit v1.2.3