Brush up the container documentation

Make the code snippets consistent, update the comparison table
and fix some sentences.

Pick-to: 6.4 6.2
Change-Id: Ic8baaa56805392855736164efa03d065330309fa
Reviewed-by: Mårten Nordheim <marten.nordheim@qt.io>
This commit is contained in:
Friedemann Kleint 2022-12-01 09:25:50 +01:00
parent 93f54f0aa4
commit f6b137bdc4
2 changed files with 14 additions and 15 deletions

View File

@ -247,9 +247,9 @@ target_compile_definitions(my_app PRIVATE QT_NO_KEYWORDS)
QString onlyLetters(const QString &in)
{
QString out;
for (int j = 0; j < in.size(); ++j) {
if (in[j].isLetter())
out += in[j];
for (qsizetype j = 0; j < in.size(); ++j) {
if (in.at(j).isLetter())
out += in.at(j);
}
return out;
}
@ -286,15 +286,15 @@ int j = *i; // Undefined behavior!
//! [24]
//! [25]
QList<int> list { 1, 2, 3, 4, 4, 5 };
QSet<int> set(list.begin(), list.end());
QList<int> list = {1, 2, 3, 4, 4, 5};
QSet<int> set(list.cbegin(), list.cend());
/*
Will generate a QSet containing 1, 2, 3, 4, 5.
*/
//! [25]
//! [26]
QList<int> list { 2, 3, 1 };
QList<int> list = {2, 3, 1};
std::sort(list.begin(), list.end());
/*

View File

@ -39,7 +39,8 @@
\note Since Qt 5.14, range constructors are available for most of the
container classes. QMultiMap is a notable exception. Their use is
encouraged in place of the various from/to methods. For example:
encouraged to replace of the various deprecated from/to methods of Qt 5.
For example:
\snippet code/doc_src_containers.cpp 25
@ -285,12 +286,10 @@
In the code snippets so far, we used the unary \c * operator to
retrieve the item (of type QString) stored at a certain iterator
position, and we then called QString::toLower() on it. Most C++
compilers also allow us to write \c{i->toLower()}, but some
don't.
position, and we then called QString::toLower() on it.
For read-only access, you can use const_iterator, \l{QList::constBegin}{constBegin()},
and \l{QList::constEnd()}{constEnd()}. For example:
For read-only access, you can use const_iterator, \l{QList::cbegin}{cbegin()},
and \l{QList::cend()}{cend()}. For example:
\snippet code/doc_src_containers.cpp 12
@ -384,7 +383,7 @@
\li Similar to std::queue<T>, inherits from \l{QList}.
\row \li \l{QSet}<T>
\li Similar to std::set<T>. Internally, \l{QSet} is implemented with a
\li Similar to std::unordered_set<T>. Internally, \l{QSet} is implemented with a
\l{QHash}.
\row \li \l{QMap}<Key, T>
@ -394,10 +393,10 @@
\li Similar to std::multimap<T>.
\row \li \l{QHash}<Key, T>
\li Most similar to std::map<T>.
\li Most similar to std::unordered_map<T>.
\row \li \l{QMultiHash}<Key, T>
\li Most similar to std::multimap<T>.
\li Most similar to std::unordered_multimap<T>.
\endtable