diff --git a/src/corelib/text/qbytearrayview.h b/src/corelib/text/qbytearrayview.h index 29624537542..a80ef6797dc 100644 --- a/src/corelib/text/qbytearrayview.h +++ b/src/corelib/text/qbytearrayview.h @@ -4,6 +4,7 @@ #define QBYTEARRAYVIEW_H #include +#include #include #include @@ -315,19 +316,6 @@ public: [[nodiscard]] constexpr char first() const { return front(); } [[nodiscard]] constexpr char last() const { return back(); } - friend inline bool operator==(QByteArrayView lhs, QByteArrayView rhs) noexcept - { return lhs.size() == rhs.size() && (!lhs.size() || memcmp(lhs.data(), rhs.data(), lhs.size()) == 0); } - friend inline bool operator!=(QByteArrayView lhs, QByteArrayView rhs) noexcept - { return !(lhs == rhs); } - friend inline bool operator< (QByteArrayView lhs, QByteArrayView rhs) noexcept - { return QtPrivate::compareMemory(lhs, rhs) < 0; } - friend inline bool operator<=(QByteArrayView lhs, QByteArrayView rhs) noexcept - { return QtPrivate::compareMemory(lhs, rhs) <= 0; } - friend inline bool operator> (QByteArrayView lhs, QByteArrayView rhs) noexcept - { return !(lhs <= rhs); } - friend inline bool operator>=(QByteArrayView lhs, QByteArrayView rhs) noexcept - { return !(lhs < rhs); } - private: Q_ALWAYS_INLINE constexpr void verify([[maybe_unused]] qsizetype pos = 0, [[maybe_unused]] qsizetype n = 1) const @@ -338,6 +326,27 @@ private: Q_ASSERT(n <= size() - pos); } + static inline bool + comparesEqual(const QByteArrayView &lhs, const QByteArrayView &rhs) noexcept + { + return lhs.size() == rhs.size() + && (!lhs.size() || memcmp(lhs.data(), rhs.data(), lhs.size()) == 0); + } + static inline Qt::strong_ordering + compareThreeWay(const QByteArrayView &lhs, const QByteArrayView &rhs) noexcept + { + const int res = QtPrivate::compareMemory(lhs, rhs); + return Qt::compareThreeWay(res, 0); + } + Q_DECLARE_STRONGLY_ORDERED(QByteArrayView) + + static inline bool comparesEqual(const QByteArrayView &lhs, const char *rhs) noexcept + { return comparesEqual(lhs, QByteArrayView(rhs)); } + static inline Qt::strong_ordering + compareThreeWay(const QByteArrayView &lhs, const char *rhs) noexcept + { return compareThreeWay(lhs, QByteArrayView(rhs)); } + Q_DECLARE_STRONGLY_ORDERED(QByteArrayView, const char *) + qsizetype m_size; const storage_type *m_data; }; diff --git a/src/corelib/text/qbytearrayview.qdoc b/src/corelib/text/qbytearrayview.qdoc index 2dc63e469c8..fc8325cc607 100644 --- a/src/corelib/text/qbytearrayview.qdoc +++ b/src/corelib/text/qbytearrayview.qdoc @@ -332,12 +332,12 @@ */ /*! //! friend - \fn int QByteArrayView::operator==(QByteArrayView lhs, QByteArrayView rhs) - \fn int QByteArrayView::operator!=(QByteArrayView lhs, QByteArrayView rhs) - \fn int QByteArrayView::operator< (QByteArrayView lhs, QByteArrayView rhs) - \fn int QByteArrayView::operator<=(QByteArrayView lhs, QByteArrayView rhs) - \fn int QByteArrayView::operator> (QByteArrayView lhs, QByteArrayView rhs) - \fn int QByteArrayView::operator>=(QByteArrayView lhs, QByteArrayView rhs) + \fn int QByteArrayView::operator==(const QByteArrayView &lhs, const QByteArrayView &rhs) + \fn int QByteArrayView::operator!=(const QByteArrayView &lhs, const QByteArrayView &rhs) + \fn int QByteArrayView::operator< (const QByteArrayView &lhs, const QByteArrayView &rhs) + \fn int QByteArrayView::operator<=(const QByteArrayView &lhs, const QByteArrayView &rhs) + \fn int QByteArrayView::operator> (const QByteArrayView &lhs, const QByteArrayView &rhs) + \fn int QByteArrayView::operator>=(const QByteArrayView &lhs, const QByteArrayView &rhs) Comparison operators for QByteArrayView. */ diff --git a/tests/auto/corelib/text/qstringapisymmetry/tst_qstringapisymmetry.cpp b/tests/auto/corelib/text/qstringapisymmetry/tst_qstringapisymmetry.cpp index 635b9cfa52f..e1a2232b7b6 100644 --- a/tests/auto/corelib/text/qstringapisymmetry/tst_qstringapisymmetry.cpp +++ b/tests/auto/corelib/text/qstringapisymmetry/tst_qstringapisymmetry.cpp @@ -320,10 +320,8 @@ private Q_SLOTS: void compare_QByteArrayView_QByteArray() { compare_impl(); } void compare_QByteArrayView_QByteArrayView_data() { compare_data(); } void compare_QByteArrayView_QByteArrayView() { compare_impl(); } -#ifdef AMBIGUOUS_CALL void compare_QByteArrayView_const_char_star_data() { compare_data(); } void compare_QByteArrayView_const_char_star() { compare_impl(); } -#endif void compare_const_char_star_QChar_data() { compare_data(false); } void compare_const_char_star_QChar() { compare_impl(); } @@ -337,10 +335,8 @@ private Q_SLOTS: void compare_const_char_star_QLatin1String() { compare_impl(); } void compare_const_char_star_QByteArray_data() { compare_data(); } void compare_const_char_star_QByteArray() { compare_impl(); } -#ifdef AMBIGUOUS_CALL void compare_const_char_star_QByteArrayView_data() { compare_data(); } void compare_const_char_star_QByteArrayView() { compare_impl(); } -#endif //void compare_const_char_star_const_char_star_data() { compare_data(); } //void compare_const_char_star_const_char_star() { compare_impl(); }