diff options
author | Giuseppe D'Angelo <giuseppe.dangelo@kdab.com> | 2024-02-19 13:05:54 +0100 |
---|---|---|
committer | Giuseppe D'Angelo <giuseppe.dangelo@kdab.com> | 2024-02-27 16:58:27 +0100 |
commit | 7ce6920aacfcba485cd8017e01c6aeb324292e75 (patch) | |
tree | d01cafcfb81457bc60ad270b72088c5cfc75dba2 /src/corelib/text/qstring.h | |
parent | 476d2a7392ee26294d1230f0c5031fe6bb4a0f26 (diff) |
Containers: add max_size()
One more method for STL compatibility.
This one is particularly subtle as it's required by the
`reservable-container` concept:
https://eel.is/c++draft/ranges#range.utility.conv.general-3
Without this concept, ranges::to won't reserve() before copying the
elements (out of a sized range which isn't a common_range).
Implementation notes: there were already a couple of constants denoting
the maximum QByteArray and QString size. Centralize that implementation
in QTypedArrayData, so that QList can use it too.
The maximum allocation size (private constant) needs a even more central
place so that even QVLA can use it. Lacking anything better, I've put it
in qcontainerfwd.h.
Since our containers aren't allocator-aware, I can make max_size() a
static member, and replace the existing constants throughout the rest of
qtbase. (I can't kill them yet as they're used by other submodules.)
[ChangeLog][QtCore][QList] Added max_size().
[ChangeLog][QtCore][QString] Added max_size().
[ChangeLog][QtCore][QByteArray] Added max_size().
[ChangeLog][QtCore][QVarLengthArray] Added max_size().
Change-Id: I176142e31b998f4f787c96333894b8f6653eb70d
Reviewed-by: Qt CI Bot <qt_ci_bot@qt-project.org>
Reviewed-by: Thiago Macieira <thiago.macieira@intel.com>
Diffstat (limited to 'src/corelib/text/qstring.h')
-rw-r--r-- | src/corelib/text/qstring.h | 5 |
1 files changed, 5 insertions, 0 deletions
diff --git a/src/corelib/text/qstring.h b/src/corelib/text/qstring.h index 780b3090c1..5936f76ed4 100644 --- a/src/corelib/text/qstring.h +++ b/src/corelib/text/qstring.h @@ -941,6 +941,11 @@ public: void shrink_to_fit() { squeeze(); } iterator erase(const_iterator first, const_iterator last); inline iterator erase(const_iterator it) { return erase(it, it + 1); } + static constexpr qsizetype max_size() noexcept + { + // -1 to deal with the NUL terminator + return Data::max_size() - 1; + } static inline QString fromStdString(const std::string &s); inline std::string toStdString() const; |