diff options
Diffstat (limited to 'src/corelib/tools')
-rw-r--r-- | src/corelib/tools/qbitarray.cpp | 11 | ||||
-rw-r--r-- | src/corelib/tools/qcontiguouscache.h | 1 | ||||
-rw-r--r-- | src/corelib/tools/qcryptographichash.cpp | 83 | ||||
-rw-r--r-- | src/corelib/tools/qcryptographichash.h | 14 | ||||
-rw-r--r-- | src/corelib/tools/qhash.h | 1 | ||||
-rw-r--r-- | src/corelib/tools/qlist.h | 1 | ||||
-rw-r--r-- | src/corelib/tools/qmap.h | 1 | ||||
-rw-r--r-- | src/corelib/tools/qmessageauthenticationcode.h | 24 | ||||
-rw-r--r-- | src/corelib/tools/qset.h | 1 | ||||
-rw-r--r-- | src/corelib/tools/qshareddata.cpp | 19 | ||||
-rw-r--r-- | src/corelib/tools/qshareddata.h | 5 | ||||
-rw-r--r-- | src/corelib/tools/qsize.cpp | 33 | ||||
-rw-r--r-- | src/corelib/tools/qsize.h | 23 | ||||
-rw-r--r-- | src/corelib/tools/qspan.h | 23 | ||||
-rw-r--r-- | src/corelib/tools/qspan.qdoc | 36 | ||||
-rw-r--r-- | src/corelib/tools/qvarlengtharray.h | 1 |
16 files changed, 231 insertions, 46 deletions
diff --git a/src/corelib/tools/qbitarray.cpp b/src/corelib/tools/qbitarray.cpp index e4276d383d..d5643df025 100644 --- a/src/corelib/tools/qbitarray.cpp +++ b/src/corelib/tools/qbitarray.cpp @@ -531,12 +531,17 @@ static QBitArray sizedForOverwrite(const QBitArray &a1, const QBitArray &a2) QByteArrayData bytes(n, n); // initialize the count of bits in the last byte (see construction note) - if (n1 > n2) + // and the QByteArray null termination (some of our algorithms read it) + if (n1 > n2) { *bytes.ptr = *d1.ptr; - else if (n2 > n1) + bytes.ptr[n1] = 0; + } else if (n2 > n1) { *bytes.ptr = *d2.ptr; - else if (n1) // n1 == n2 + bytes.ptr[n2] = 0; + } else if (n1) { // n1 == n2 *bytes.ptr = qMin(*d1.ptr, *d2.ptr); + bytes.ptr[n1] = 0; + } result.data_ptr() = std::move(bytes); return result; diff --git a/src/corelib/tools/qcontiguouscache.h b/src/corelib/tools/qcontiguouscache.h index c01dbb9390..e3f98c30de 100644 --- a/src/corelib/tools/qcontiguouscache.h +++ b/src/corelib/tools/qcontiguouscache.h @@ -8,6 +8,7 @@ #include <QtCore/qassert.h> #include <QtCore/qtclasshelpermacros.h> #include <QtCore/qtcoreexports.h> +#include <QtCore/qttypetraits.h> #include <QtCore/qtypeinfo.h> #include <climits> diff --git a/src/corelib/tools/qcryptographichash.cpp b/src/corelib/tools/qcryptographichash.cpp index 2e82a394ee..d0ed17eba2 100644 --- a/src/corelib/tools/qcryptographichash.cpp +++ b/src/corelib/tools/qcryptographichash.cpp @@ -1153,13 +1153,49 @@ void QCryptographicHashPrivate::State::finalizeUnchecked(QCryptographicHash::Alg \note In Qt versions prior to 6.3, this function took QByteArray, not QByteArrayView. + + \sa hashInto() */ QByteArray QCryptographicHash::hash(QByteArrayView data, Algorithm method) { + QByteArray ba(hashLengthInternal(method), Qt::Uninitialized); + [[maybe_unused]] const auto r = hashInto(ba, data, method); + Q_ASSERT(r.size() == ba.size()); + return ba; +} + +/*! + \since 6.8 + \fn QCryptographicHash::hashInto(QSpan<char> buffer, QSpan<const QByteArrayView> data, Algorithm method); + \fn QCryptographicHash::hashInto(QSpan<uchar> buffer, QSpan<const QByteArrayView> data, Algorithm method); + \fn QCryptographicHash::hashInto(QSpan<std::byte> buffer, QSpan<const QByteArrayView> data, Algorithm method); + \fn QCryptographicHash::hashInto(QSpan<char> buffer, QByteArrayView data, Algorithm method); + \fn QCryptographicHash::hashInto(QSpan<uchar> buffer, QByteArrayView data, Algorithm method); + \fn QCryptographicHash::hashInto(QSpan<std::byte> buffer, QByteArrayView data, Algorithm method); + + Returns the hash of \a data using \a method, using \a buffer to store the result. + + If \a data is a span, adds all the byte array views to the hash, in the order given. + + The return value will be a sub-span of \a buffer, unless \a buffer is of + insufficient size, in which case a null QByteArrayView is returned. + + \sa hash() +*/ +QByteArrayView QCryptographicHash::hashInto(QSpan<std::byte> buffer, + QSpan<const QByteArrayView> data, + Algorithm method) noexcept +{ QCryptographicHashPrivate hash(method); - hash.addData(data); + for (QByteArrayView part : data) + hash.addData(part); hash.finalizeUnchecked(); // no mutex needed: no-one but us has access to 'hash' - return hash.resultView().toByteArray(); + auto result = hash.resultView(); + if (buffer.size() < result.size()) + return {}; // buffer too small + // ### optimize: have the method directly write into `buffer` + memcpy(buffer.data(), result.data(), result.size()); + return buffer.first(result.size()); } /*! @@ -1338,7 +1374,7 @@ static HashBlock xored(const HashBlock &block, quint8 val) noexcept class QMessageAuthenticationCodePrivate { public: - QMessageAuthenticationCodePrivate(QCryptographicHash::Algorithm m) + explicit QMessageAuthenticationCodePrivate(QCryptographicHash::Algorithm m) noexcept : messageHash(m) { } @@ -1635,15 +1671,52 @@ void QMessageAuthenticationCodePrivate::finalizeUnchecked() noexcept the key \a key and the method \a method. \include qcryptographichash.cpp {qba-to-qbav-6.6} + + \sa hashInto() */ QByteArray QMessageAuthenticationCode::hash(QByteArrayView message, QByteArrayView key, QCryptographicHash::Algorithm method) { + QByteArray ba(hashLengthInternal(method), Qt::Uninitialized); + [[maybe_unused]] const auto r = hashInto(ba, message, key, method); + Q_ASSERT(r.size() == ba.size()); + return ba; +} + +/*! + \since 6.8 + \fn QMessageAuthenticationCode::hashInto(QSpan<char> buffer, QSpan<const QByteArrayView> messageParts, QByteArrayView key, QCryptographicHash::Algorithm method); + \fn QMessageAuthenticationCode::hashInto(QSpan<uchar> buffer, QSpan<const QByteArrayView> messageParts, QByteArrayView key, QCryptographicHash::Algorithm method); + \fn QMessageAuthenticationCode::hashInto(QSpan<std::byte> buffer, QSpan<const QByteArrayView> messageParts, QByteArrayView key, QCryptographicHash::Algorithm method); + \fn QMessageAuthenticationCode::hashInto(QSpan<char> buffer, QByteArrayView message, QByteArrayView key, QCryptographicHash::Algorithm method); + \fn QMessageAuthenticationCode::hashInto(QSpan<uchar> buffer, QByteArrayView message, QByteArrayView key, QCryptographicHash::Algorithm method); + \fn QMessageAuthenticationCode::hashInto(QSpan<std::byte> buffer, QByteArrayView message, QByteArrayView key, QCryptographicHash::Algorithm method); + + Returns the authentication code for the message (\a message or, for the + QSpan overloads, the concatenation of \a messageParts) using the key \a key + and the method \a method. + + The return value will be a sub-span of \a buffer, unless \a buffer is of + insufficient size, in which case a null QByteArrayView is returned. + + \sa hash() +*/ +QByteArrayView QMessageAuthenticationCode::hashInto(QSpan<std::byte> buffer, + QSpan<const QByteArrayView> messageParts, + QByteArrayView key, + QCryptographicHash::Algorithm method) noexcept +{ QMessageAuthenticationCodePrivate mac(method); mac.setKey(key); - mac.messageHash.addData(message); + for (QByteArrayView part : messageParts) + mac.messageHash.addData(part); mac.finalizeUnchecked(); - return mac.messageHash.resultView().toByteArray(); + auto result = mac.messageHash.resultView(); + if (buffer.size() < result.size()) + return {}; // buffer too small + // ### optimize: have the method directly write into `buffer` + memcpy(buffer.data(), result.data(), result.size()); + return buffer.first(result.size()); } QT_END_NAMESPACE diff --git a/src/corelib/tools/qcryptographichash.h b/src/corelib/tools/qcryptographichash.h index 294453adce..8c4f70457f 100644 --- a/src/corelib/tools/qcryptographichash.h +++ b/src/corelib/tools/qcryptographichash.h @@ -8,6 +8,7 @@ #include <QtCore/qbytearray.h> #include <QtCore/qobjectdefs.h> +#include <QtCore/qspan.h> QT_BEGIN_NAMESPACE @@ -91,6 +92,19 @@ public: static QByteArray hash(const QByteArray &data, Algorithm method); #endif static QByteArray hash(QByteArrayView data, Algorithm method); + + static QByteArrayView hashInto(QSpan<char> buffer, QByteArrayView data, Algorithm method) noexcept + { return hashInto(as_writable_bytes(buffer), {&data, 1}, method); } + static QByteArrayView hashInto(QSpan<uchar> buffer, QByteArrayView data, Algorithm method) noexcept + { return hashInto(as_writable_bytes(buffer), {&data, 1}, method); } + static QByteArrayView hashInto(QSpan<std::byte> buffer, QByteArrayView data, Algorithm method) noexcept + { return hashInto(buffer, {&data, 1}, method); } + static QByteArrayView hashInto(QSpan<char> buffer, QSpan<const QByteArrayView> data, Algorithm method) noexcept + { return hashInto(as_writable_bytes(buffer), data, method); } + static QByteArrayView hashInto(QSpan<uchar> buffer, QSpan<const QByteArrayView> data, Algorithm method) noexcept + { return hashInto(as_writable_bytes(buffer), data, method); } + static QByteArrayView hashInto(QSpan<std::byte> buffer, QSpan<const QByteArrayView> data, Algorithm method) noexcept; + static int hashLength(Algorithm method); static bool supportsAlgorithm(Algorithm method); private: diff --git a/src/corelib/tools/qhash.h b/src/corelib/tools/qhash.h index e7cd4123fb..9cc6fbf30b 100644 --- a/src/corelib/tools/qhash.h +++ b/src/corelib/tools/qhash.h @@ -11,6 +11,7 @@ #include <QtCore/qiterator.h> #include <QtCore/qlist.h> #include <QtCore/qrefcount.h> +#include <QtCore/qttypetraits.h> #include <initializer_list> #include <functional> // for std::hash diff --git a/src/corelib/tools/qlist.h b/src/corelib/tools/qlist.h index 89e0e3f380..1cced5acc2 100644 --- a/src/corelib/tools/qlist.h +++ b/src/corelib/tools/qlist.h @@ -11,6 +11,7 @@ #include <QtCore/qiterator.h> #include <QtCore/qcontainertools_impl.h> #include <QtCore/qnamespace.h> +#include <QtCore/qttypetraits.h> #include <functional> #include <limits> diff --git a/src/corelib/tools/qmap.h b/src/corelib/tools/qmap.h index 7ee0be1e51..326ae7d8a5 100644 --- a/src/corelib/tools/qmap.h +++ b/src/corelib/tools/qmap.h @@ -12,6 +12,7 @@ #include <QtCore/qpair.h> #include <QtCore/qshareddata.h> #include <QtCore/qshareddata_impl.h> +#include <QtCore/qttypetraits.h> #include <functional> #include <initializer_list> diff --git a/src/corelib/tools/qmessageauthenticationcode.h b/src/corelib/tools/qmessageauthenticationcode.h index 4e88138763..7c5edfa7bf 100644 --- a/src/corelib/tools/qmessageauthenticationcode.h +++ b/src/corelib/tools/qmessageauthenticationcode.h @@ -55,6 +55,30 @@ public: static QByteArray hash(QByteArrayView message, QByteArrayView key, QCryptographicHash::Algorithm method); + static QByteArrayView + hashInto(QSpan<char> buffer, QByteArrayView message, QByteArrayView key, + QCryptographicHash::Algorithm method) noexcept + { return hashInto(as_writable_bytes(buffer), {&message, 1}, key, method); } + static QByteArrayView + hashInto(QSpan<uchar> buffer, QByteArrayView message, QByteArrayView key, + QCryptographicHash::Algorithm method) noexcept + { return hashInto(as_writable_bytes(buffer), {&message, 1}, key, method); } + static QByteArrayView + hashInto(QSpan<std::byte> buffer, QByteArrayView message, + QByteArrayView key, QCryptographicHash::Algorithm method) noexcept + { return hashInto(buffer, {&message, 1}, key, method); } + static QByteArrayView + hashInto(QSpan<char> buffer, QSpan<const QByteArrayView> messageParts, + QByteArrayView key, QCryptographicHash::Algorithm method) noexcept + { return hashInto(as_writable_bytes(buffer), messageParts, key, method); } + static QByteArrayView + hashInto(QSpan<uchar> buffer, QSpan<const QByteArrayView> messageParts, + QByteArrayView key, QCryptographicHash::Algorithm method) noexcept + { return hashInto(as_writable_bytes(buffer), messageParts, key, method); } + static QByteArrayView + hashInto(QSpan<std::byte> buffer, QSpan<const QByteArrayView> message, + QByteArrayView key, QCryptographicHash::Algorithm method) noexcept; + private: Q_DISABLE_COPY(QMessageAuthenticationCode) QMessageAuthenticationCodePrivate *d; diff --git a/src/corelib/tools/qset.h b/src/corelib/tools/qset.h index 7330b5e91c..6eaeb8fc41 100644 --- a/src/corelib/tools/qset.h +++ b/src/corelib/tools/qset.h @@ -6,6 +6,7 @@ #include <QtCore/qhash.h> #include <QtCore/qcontainertools_impl.h> +#include <QtCore/qttypetraits.h> #include <initializer_list> #include <iterator> diff --git a/src/corelib/tools/qshareddata.cpp b/src/corelib/tools/qshareddata.cpp index 8ef174ebfc..345d7396b2 100644 --- a/src/corelib/tools/qshareddata.cpp +++ b/src/corelib/tools/qshareddata.cpp @@ -570,25 +570,6 @@ QT_BEGIN_NAMESPACE implicitly converted to the type \c{T *}; the result of this conversion is set as the \e{d pointer} of \e{this}, and the reference count of the shared data object is incremented. - - However, if the macro - \c{QT_ENABLE_QEXPLICITLYSHAREDDATAPOINTER_STATICCAST} is defined - before including the \c{QExplicitlySharedDataPointer} header, then - the \e{d pointer} of \a o undergoes a \c{static_cast} to the - type \c{T *}. The result of the cast is then set as the - \e{d pointer} of \e{this}, and the reference count of the shared data - object is incremented. - - \warning relying on such \c{static_cast} is potentially dangerous, - because it allows code like this to compile: - - \snippet code/src_corelib_tools_qshareddata.cpp 2 - - Starting from Qt 5.4 the cast is disabled by default. It is - possible to enable it back by defining the - \c{QT_ENABLE_QEXPLICITLYSHAREDDATAPOINTER_STATICCAST} macro, and - therefore to allow old code (that relied on this feature) to - compile without modifications. */ /*! \fn template <class T> QExplicitlySharedDataPointer<T>& QExplicitlySharedDataPointer<T>::operator=(const QExplicitlySharedDataPointer<T>& o) diff --git a/src/corelib/tools/qshareddata.h b/src/corelib/tools/qshareddata.h index 4c4153a506..8e96db93b5 100644 --- a/src/corelib/tools/qshareddata.h +++ b/src/corelib/tools/qshareddata.h @@ -162,10 +162,9 @@ public: Q_NODISCARD_CTOR QExplicitlySharedDataPointer(const QExplicitlySharedDataPointer<X> &o) noexcept #ifdef QT_ENABLE_QEXPLICITLYSHAREDDATAPOINTER_STATICCAST - : d(static_cast<T *>(o.data())) -#else - : d(o.data()) +#error This macro has been removed in Qt 6.9. #endif + : d(o.data()) { if (d) d->ref.ref(); } void reset(T *ptr = nullptr) noexcept diff --git a/src/corelib/tools/qsize.cpp b/src/corelib/tools/qsize.cpp index d5e8e4c71b..27ff1d164d 100644 --- a/src/corelib/tools/qsize.cpp +++ b/src/corelib/tools/qsize.cpp @@ -266,15 +266,15 @@ QSize QSize::scaled(const QSize &s, Qt::AspectRatioMode mode) const noexcept */ /*! - \fn bool QSize::operator==(const QSize &s1, const QSize &s2) + \fn bool QSize::operator==(const QSize &lhs, const QSize &rhs) - Returns \c true if \a s1 and \a s2 are equal; otherwise returns \c false. + Returns \c true if \a lhs and \a rhs are equal; otherwise returns \c false. */ /*! - \fn bool QSize::operator!=(const QSize &s1, const QSize &s2) + \fn bool QSize::operator!=(const QSize &lhs, const QSize &rhs) - Returns \c true if \a s1 and \a s2 are different; otherwise returns \c false. + Returns \c true if \a lhs and \a rhs are different; otherwise returns \c false. */ /*! @@ -714,9 +714,9 @@ QSizeF QSizeF::scaled(const QSizeF &s, Qt::AspectRatioMode mode) const noexcept */ /*! - \fn bool QSizeF::operator==(const QSizeF &s1, const QSizeF &s2) + \fn bool QSizeF::operator==(const QSizeF &lhs, const QSizeF &rhs) - Returns \c true if \a s1 and \a s2 are approximately equal; otherwise + Returns \c true if \a lhs and \a rhs are approximately equal; otherwise returns false. \warning This function does not check for strict equality; instead, @@ -726,9 +726,9 @@ QSizeF QSizeF::scaled(const QSizeF &s, Qt::AspectRatioMode mode) const noexcept */ /*! - \fn bool QSizeF::operator!=(const QSizeF &s1, const QSizeF &s2) + \fn bool QSizeF::operator!=(const QSizeF &lhs, const QSizeF &rhs) - Returns \c true if \a s1 and \a s2 are sufficiently different; otherwise + Returns \c true if \a lhs and \a rhs are sufficiently different; otherwise returns \c false. \warning This function does not check for strict inequality; instead, @@ -808,7 +808,24 @@ QSizeF QSizeF::scaled(const QSizeF &s, Qt::AspectRatioMode mode) const noexcept \sa expandedTo(), scale() */ +/*! + \fn bool QSizeF::qFuzzyCompare(const QSizeF &lhs, const QSizeF &rhs) + \since 6.8 + + Returns \c true if the size \a lhs is approximately equal to the + size \a rhs; otherwise returns \c false. + + The sizes are considered approximately equal if their width and + height are approximately equal. +*/ +/*! + \fn bool QSizeF::qFuzzyIsNull(const QSizeF &size) + \since 6.8 + + Returns \c true if both width and height of the size \a size + are approximately equal to zero. +*/ /***************************************************************************** QSizeF stream functions diff --git a/src/corelib/tools/qsize.h b/src/corelib/tools/qsize.h index a5eaf34afe..67f7146201 100644 --- a/src/corelib/tools/qsize.h +++ b/src/corelib/tools/qsize.h @@ -59,10 +59,10 @@ public: constexpr inline QSize &operator*=(qreal c) noexcept; inline QSize &operator/=(qreal c); - friend inline constexpr bool operator==(const QSize &s1, const QSize &s2) noexcept +private: + friend constexpr bool comparesEqual(const QSize &s1, const QSize &s2) noexcept { return s1.wd == s2.wd && s1.ht == s2.ht; } - friend inline constexpr bool operator!=(const QSize &s1, const QSize &s2) noexcept - { return s1.wd != s2.wd || s1.ht != s2.ht; } + Q_DECLARE_EQUALITY_COMPARABLE_LITERAL_TYPE(QSize) friend inline constexpr QSize operator+(const QSize &s1, const QSize &s2) noexcept { return QSize(s1.wd + s2.wd, s1.ht + s2.ht); } friend inline constexpr QSize operator-(const QSize &s1, const QSize &s2) noexcept @@ -75,6 +75,7 @@ public: { Q_ASSERT(!qFuzzyIsNull(c)); return QSize(qRound(s.wd / c), qRound(s.ht / c)); } friend inline constexpr size_t qHash(const QSize &, size_t) noexcept; +public: #if defined(Q_OS_DARWIN) || defined(Q_QDOC) [[nodiscard]] CGSize toCGSize() const noexcept; #endif @@ -242,16 +243,25 @@ public: constexpr inline QSizeF &operator*=(qreal c) noexcept; inline QSizeF &operator/=(qreal c); +private: QT_WARNING_PUSH QT_WARNING_DISABLE_FLOAT_COMPARE - friend constexpr inline bool operator==(const QSizeF &s1, const QSizeF &s2) + friend constexpr bool qFuzzyCompare(const QSizeF &s1, const QSizeF &s2) noexcept { + // Cannot use qFuzzyCompare(), because it will give incorrect results + // if one of the arguments is 0.0. return ((!s1.wd || !s2.wd) ? qFuzzyIsNull(s1.wd - s2.wd) : qFuzzyCompare(s1.wd, s2.wd)) && ((!s1.ht || !s2.ht) ? qFuzzyIsNull(s1.ht - s2.ht) : qFuzzyCompare(s1.ht, s2.ht)); } QT_WARNING_POP - friend constexpr inline bool operator!=(const QSizeF &s1, const QSizeF &s2) - { return !(s1 == s2); } + friend constexpr bool qFuzzyIsNull(const QSizeF &size) noexcept + { return qFuzzyIsNull(size.wd) && qFuzzyIsNull(size.ht); } + friend constexpr bool comparesEqual(const QSizeF &lhs, const QSizeF &rhs) noexcept + { return qFuzzyCompare(lhs, rhs); } + Q_DECLARE_EQUALITY_COMPARABLE_LITERAL_TYPE(QSizeF) + friend constexpr bool comparesEqual(const QSizeF &lhs, const QSize &rhs) noexcept + { return comparesEqual(lhs, rhs.toSizeF()); } + Q_DECLARE_EQUALITY_COMPARABLE_LITERAL_TYPE(QSizeF, QSize) friend constexpr inline QSizeF operator+(const QSizeF &s1, const QSizeF &s2) noexcept { return QSizeF(s1.wd + s2.wd, s1.ht + s2.ht); } friend constexpr inline QSizeF operator-(const QSizeF &s1, const QSizeF &s2) noexcept @@ -263,6 +273,7 @@ public: friend inline QSizeF operator/(const QSizeF &s, qreal c) { Q_ASSERT(!qFuzzyIsNull(c)); return QSizeF(s.wd / c, s.ht / c); } +public: constexpr inline QSize toSize() const noexcept; #if defined(Q_OS_DARWIN) || defined(Q_QDOC) diff --git a/src/corelib/tools/qspan.h b/src/corelib/tools/qspan.h index d6ae2570ae..2671ba374f 100644 --- a/src/corelib/tools/qspan.h +++ b/src/corelib/tools/qspan.h @@ -433,6 +433,29 @@ public: [[nodiscard]] constexpr QSpan<T> sliced(size_type pos) const { return subspan(pos); } [[nodiscard]] constexpr QSpan<T> sliced(size_type pos, size_type n) const { return subspan(pos, n); } +private: + // [span.objectrep] + [[nodiscard]] friend + QSpan<const std::byte, E == q20::dynamic_extent ? q20::dynamic_extent : E * sizeof(T)> + as_bytes(QSpan s) noexcept + { + using R = QSpan<const std::byte, E == q20::dynamic_extent ? q20::dynamic_extent : E * sizeof(T)>; + return R{reinterpret_cast<const std::byte *>(s.data()), s.size_bytes()}; + } + + template <typename U> + using if_mutable = std::enable_if_t<!std::is_const_v<U>, bool>; + +#ifndef Q_QDOC + template <typename T2 = T, if_mutable<T2> = true> +#endif + [[nodiscard]] friend + QSpan<std::byte, E == q20::dynamic_extent ? q20::dynamic_extent : E * sizeof(T)> + as_writable_bytes(QSpan s) noexcept + { + using R = QSpan<std::byte, E == q20::dynamic_extent ? q20::dynamic_extent : E * sizeof(T)>; + return R{reinterpret_cast<std::byte *>(s.data()), s.size_bytes()}; + } }; // class QSpan // [span.deduct] diff --git a/src/corelib/tools/qspan.qdoc b/src/corelib/tools/qspan.qdoc index 472f122877..9b55b09bf7 100644 --- a/src/corelib/tools/qspan.qdoc +++ b/src/corelib/tools/qspan.qdoc @@ -556,7 +556,6 @@ \sa subspan(QSpan<T,E>::size_type), subspan(), first(), last() */ -#if 0 // needs fix for QTBUG-118080 integrated into qt5.git /*! \fn template <typename T, size_t E> template <std::size_t Offset, std::size_t Count> auto QSpan<T, E>::subspan() const \keyword subspan-t2 @@ -573,7 +572,6 @@ \sa subspan(QSpan<T,E>::size_type, QSpan<T,E>::size_type), subspan(), first(), last() */ -#endif // // runtime subspans: @@ -649,3 +647,37 @@ \sa subspan(), first(QSpan<T,E>::size_type), last(QSpan<T,E>::size_type) */ +/*! + \fn template <typename T, size_t E> auto QSpan<T, E>::as_bytes(QSpan s) + \since 6.8 + + Returns \a s as a \c{QSpan<const std::byte, E'>} whose size() is equal to + \c{s.size_bytes()}. + + If \c{E} is \c{std::dynamic_extent} then so is \c{E'}. + Otherwise, \c{E' = E * sizeof(T)}. + + \note \c{q20::dynamic_extent} is a C++17 backport of C++20's + \l{https://en.cppreference.com/w/cpp/container/span/dynamic_extent}{\c{std::dynamic_extent}}. + + \sa as_writable_bytes(), size_bytes() +*/ + +/*! + \fn template <typename T, size_t E> auto QSpan<T, E>::as_writable_bytes(QSpan s) + \since 6.8 + + Returns \a s as a \c{QSpan<std::byte, E'>} whose size() is equal to + \c{s.size_bytes()}. + + If \c{E} is \c{std::dynamic_extent} then so is \c{E'}. + Otherwise, \c{E' = E * sizeof(T)}. + + \note This function participates in overload resolution only if + \c{!std::is_const_v<T>}. + + \note \c{q20::dynamic_extent} is a C++17 backport of C++20's + \l{https://en.cppreference.com/w/cpp/container/span/dynamic_extent}{\c{std::dynamic_extent}}. + + \sa as_bytes(), size_bytes() +*/ diff --git a/src/corelib/tools/qvarlengtharray.h b/src/corelib/tools/qvarlengtharray.h index 0a579bf487..78d5a27627 100644 --- a/src/corelib/tools/qvarlengtharray.h +++ b/src/corelib/tools/qvarlengtharray.h @@ -14,6 +14,7 @@ #include <QtCore/qalgorithms.h> #include <QtCore/qcontainertools_impl.h> #include <QtCore/qhashfunctions.h> +#include <QtCore/qttypetraits.h> #include <algorithm> #include <initializer_list> |