diff --git a/src/corelib/text/qbytearray.cpp b/src/corelib/text/qbytearray.cpp index af22ff81bc..b61686ddde 100644 --- a/src/corelib/text/qbytearray.cpp +++ b/src/corelib/text/qbytearray.cpp @@ -1421,10 +1421,9 @@ QByteArray &QByteArray::operator=(const char *str) */ /*! \fn qsizetype QByteArray::max_size() + \fn qsizetype QByteArray::maxSize() \since 6.8 - This function is provided for STL compatibility. - It returns the maximum number of elements that the byte array can theoretically hold. In practice, the number can be much smaller, limited by the amount of memory available to the system. diff --git a/src/corelib/text/qbytearray.h b/src/corelib/text/qbytearray.h index 6bc9bd1ce3..b090770255 100644 --- a/src/corelib/text/qbytearray.h +++ b/src/corelib/text/qbytearray.h @@ -68,7 +68,6 @@ private: template using if_input_iterator = QtPrivate::IfIsInputIterator; public: - enum Base64Option { Base64Encoding = 0, Base64UrlEncoding = 1, @@ -483,15 +482,20 @@ 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; + return maxSize(); } static QByteArray fromStdString(const std::string &s); std::string toStdString() const; + static constexpr qsizetype maxSize() noexcept + { + // -1 to deal with the NUL terminator + return Data::maxSize() - 1; + } inline qsizetype size() const noexcept { return d.size; } #if QT_DEPRECATED_SINCE(6, 4) QT_DEPRECATED_VERSION_X_6_4("Use size() or length() instead.") diff --git a/src/corelib/text/qstring.cpp b/src/corelib/text/qstring.cpp index 9eecacbf28..23d9291c0d 100644 --- a/src/corelib/text/qstring.cpp +++ b/src/corelib/text/qstring.cpp @@ -6415,10 +6415,9 @@ QString& QString::fill(QChar ch, qsizetype size) /*! \fn qsizetype QString::max_size() + \fn qsizetype QString::maxSize() \since 6.8 - This function is provided for STL compatibility. - It returns the maximum number of elements that the string can theoretically hold. In practice, the number can be much smaller, limited by the amount of memory available to the system. diff --git a/src/corelib/text/qstring.h b/src/corelib/text/qstring.h index 0e0aef8267..c2b62a7069 100644 --- a/src/corelib/text/qstring.h +++ b/src/corelib/text/qstring.h @@ -183,6 +183,12 @@ public: = default; QT_MOVE_ASSIGNMENT_OPERATOR_IMPL_VIA_PURE_SWAP(QString) void swap(QString &other) noexcept { d.swap(other.d); } + + static constexpr qsizetype maxSize() noexcept + { + // -1 to deal with the NUL terminator + return Data::maxSize() - 1; + } inline qsizetype size() const noexcept { return d.size; } #if QT_DEPRECATED_SINCE(6, 4) QT_DEPRECATED_VERSION_X_6_4("Use size() or length() instead.") @@ -965,8 +971,7 @@ public: 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; + return maxSize(); } static inline QString fromStdString(const std::string &s); diff --git a/src/corelib/tools/qarraydata.h b/src/corelib/tools/qarraydata.h index da83fc1a21..38d1091ac1 100644 --- a/src/corelib/tools/qarraydata.h +++ b/src/corelib/tools/qarraydata.h @@ -171,11 +171,15 @@ struct QTypedArrayData return static_cast(start); } - constexpr static qsizetype max_size() noexcept + constexpr static qsizetype maxSize() noexcept { // -1 to deal with the pointer one-past-the-end return (QtPrivate::MaxAllocSize - sizeof(QtPrivate::AlignedQArrayData) - 1) / sizeof(T); } + constexpr static qsizetype max_size() noexcept + { + return maxSize(); + } }; namespace QtPrivate { diff --git a/src/corelib/tools/qlist.h b/src/corelib/tools/qlist.h index 3bac861109..62779cba06 100644 --- a/src/corelib/tools/qlist.h +++ b/src/corelib/tools/qlist.h @@ -395,6 +395,7 @@ public: bool operator>=(const QList &other) const; #endif // Q_QDOC + static constexpr qsizetype maxSize() { return Data::maxSize(); } qsizetype size() const noexcept { return d->size; } qsizetype count() const noexcept { return size(); } qsizetype length() const noexcept { return size(); } @@ -692,7 +693,7 @@ public: void shrink_to_fit() { squeeze(); } static constexpr qsizetype max_size() noexcept { - return Data::max_size(); + return maxSize(); } // comfort diff --git a/src/corelib/tools/qlist.qdoc b/src/corelib/tools/qlist.qdoc index 6ea38f3c83..74da71896b 100644 --- a/src/corelib/tools/qlist.qdoc +++ b/src/corelib/tools/qlist.qdoc @@ -1333,10 +1333,9 @@ */ /*! \fn template qsizetype QList::max_size() + \fn template qsizetype QList::maxSize() \since 6.8 - This function is provided for STL compatibility. - It returns the maximum number of elements that the list can theoretically hold. In practice, the number can be much smaller, limited by the amount of memory available to the system. diff --git a/src/corelib/tools/qvarlengtharray.h b/src/corelib/tools/qvarlengtharray.h index 78d5a27627..577a5b193e 100644 --- a/src/corelib/tools/qvarlengtharray.h +++ b/src/corelib/tools/qvarlengtharray.h @@ -184,11 +184,15 @@ public: iterator erase(const_iterator begin, const_iterator end); iterator erase(const_iterator pos) { return erase(pos, pos + 1); } - static constexpr qsizetype max_size() noexcept + static constexpr qsizetype maxSize() noexcept { // -1 to deal with the pointer one-past-the-end return (QtPrivate::MaxAllocSize / sizeof(T)) - 1; } + static constexpr qsizetype max_size() noexcept + { + return maxSize(); + } size_t hash(size_t seed) const noexcept(QtPrivate::QNothrowHashable_v) { @@ -404,6 +408,7 @@ public: } #ifdef Q_QDOC inline qsizetype size() const { return this->s; } + static constexpr qsizetype maxSize() noexcept { return QVLABase::maxSize(); } static constexpr qsizetype max_size() noexcept { return QVLABase::max_size(); } #endif using Base::size; diff --git a/src/corelib/tools/qvarlengtharray.qdoc b/src/corelib/tools/qvarlengtharray.qdoc index d010ba4d4c..8305f49536 100644 --- a/src/corelib/tools/qvarlengtharray.qdoc +++ b/src/corelib/tools/qvarlengtharray.qdoc @@ -141,10 +141,9 @@ */ /*! \fn template qsizetype QVarLengthArray::max_size() + \fn template qsizetype QVarLengthArray::maxSize() \since 6.8 - This function is provided for STL compatibility. - It returns the maximum number of elements that the array can theoretically hold. In practice, the number can be much smaller, limited by the amount of memory available to the system.