summaryrefslogtreecommitdiffstats
path: root/src/corelib/doc/snippets
diff options
context:
space:
mode:
Diffstat (limited to 'src/corelib/doc/snippets')
-rw-r--r--src/corelib/doc/snippets/code/src_corelib_tools_qhash.cpp20
1 files changed, 18 insertions, 2 deletions
diff --git a/src/corelib/doc/snippets/code/src_corelib_tools_qhash.cpp b/src/corelib/doc/snippets/code/src_corelib_tools_qhash.cpp
index ec9e704fb17..eea61b1b410 100644
--- a/src/corelib/doc/snippets/code/src_corelib_tools_qhash.cpp
+++ b/src/corelib/doc/snippets/code/src_corelib_tools_qhash.cpp
@@ -6,6 +6,8 @@
#include <iostream>
#include <QDate>
+#include <utility>
+
using namespace std;
void examples()
@@ -61,12 +63,26 @@ void examples()
{
//! [8]
- for (auto i = hash.cbegin(), end = hash.cend(); i != end; ++i)
- cout << qPrintable(i.key()) << ": " << i.value() << endl;
+ for (const auto &[key, value] : std::as_const(hash).asKeyValueRange())
+ cout << qPrintable(key) << ": " << value << endl;
//! [8]
}
{
+ //! [qhash-iterator-stl-style]
+ for (auto it = hash.cbegin(); it != hash.cend(); ++it)
+ cout << qPrintable(it.key()) << ": " << it.value() << endl;
+ //! [qhash-iterator-stl-style]
+ }
+
+ {
+ //! [qhash-iterator-modify-values]
+ for (auto it = hash.begin(); it != hash.end(); ++it)
+ it.value() += 1;
+ //! [qhash-iterator-modify-values]
+ }
+
+ {
//! [9]
hash.insert("plenty", 100);
hash.insert("plenty", 2000);