Brush up the container documentation

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

Change-Id: Ic8baaa56805392855736164efa03d065330309fa
Reviewed-by: Mårten Nordheim <marten.nordheim@qt.io>
(cherry picked from commit f6b137bdc43d4021cbbe602759dbcced2e04d638)
Reviewed-by: Qt Cherry-pick Bot <cherrypick_bot@qt-project.org>
This commit is contained in:
Friedemann Kleint 2022-12-01 09:25:50 +01:00 committed by Qt Cherry-pick Bot
parent d2f3e3949f
commit c1bbd4e442
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 onlyLetters(const QString &in)
{ {
QString out; QString out;
for (int j = 0; j < in.size(); ++j) { for (qsizetype j = 0; j < in.size(); ++j) {
if (in[j].isLetter()) if (in.at(j).isLetter())
out += in[j]; out += in.at(j);
} }
return out; return out;
} }
@ -286,15 +286,15 @@ int j = *i; // Undefined behavior!
//! [24] //! [24]
//! [25] //! [25]
QList<int> list { 1, 2, 3, 4, 4, 5 }; QList<int> list = {1, 2, 3, 4, 4, 5};
QSet<int> set(list.begin(), list.end()); QSet<int> set(list.cbegin(), list.cend());
/* /*
Will generate a QSet containing 1, 2, 3, 4, 5. Will generate a QSet containing 1, 2, 3, 4, 5.
*/ */
//! [25] //! [25]
//! [26] //! [26]
QList<int> list { 2, 3, 1 }; QList<int> list = {2, 3, 1};
std::sort(list.begin(), list.end()); 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 \note Since Qt 5.14, range constructors are available for most of the
container classes. QMultiMap is a notable exception. Their use is 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 \snippet code/doc_src_containers.cpp 25
@ -285,12 +286,10 @@
In the code snippets so far, we used the unary \c * operator to In the code snippets so far, we used the unary \c * operator to
retrieve the item (of type QString) stored at a certain iterator retrieve the item (of type QString) stored at a certain iterator
position, and we then called QString::toLower() on it. Most C++ position, and we then called QString::toLower() on it.
compilers also allow us to write \c{i->toLower()}, but some
don't.
For read-only access, you can use const_iterator, \l{QList::constBegin}{constBegin()}, For read-only access, you can use const_iterator, \l{QList::cbegin}{cbegin()},
and \l{QList::constEnd()}{constEnd()}. For example: and \l{QList::cend()}{cend()}. For example:
\snippet code/doc_src_containers.cpp 12 \snippet code/doc_src_containers.cpp 12
@ -384,7 +383,7 @@
\li Similar to std::queue<T>, inherits from \l{QList}. \li Similar to std::queue<T>, inherits from \l{QList}.
\row \li \l{QSet}<T> \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}. \l{QHash}.
\row \li \l{QMap}<Key, T> \row \li \l{QMap}<Key, T>
@ -394,10 +393,10 @@
\li Similar to std::multimap<T>. \li Similar to std::multimap<T>.
\row \li \l{QHash}<Key, 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> \row \li \l{QMultiHash}<Key, T>
\li Most similar to std::multimap<T>. \li Most similar to std::unordered_multimap<T>.
\endtable \endtable