From 9ea3087d365fa9184d06d4f164ad73f905bab7bd Mon Sep 17 00:00:00 2001 From: Marc Mutz Date: Tue, 27 Feb 2024 12:24:08 +0000 Subject: [PATCH] Revert "QStringView: simplify the constructor from QString" This reverts commit 7d18ad49a37440835bb38bd77bc4e0991387ada0. Reason for revert: This changes the constructor from being a template to being a normal function, so changes overload resolution. The commit message gave no indication on why this is safe. Since it's just a nice to have, revert instead of running the risk of breaking code. Change-Id: Icd506e7221bb50c99f276f6a43c15403ec0be7a9 Reviewed-by: Ivan Solovev Reviewed-by: Thiago Macieira Reviewed-by: Qt CI Bot (cherry picked from commit ff7e5987ecdd09f87cfcdb4c42039214627dcdb6) Reviewed-by: Qt Cherry-pick Bot --- src/corelib/text/qstring.h | 7 ------- src/corelib/text/qstringview.h | 11 ++++++++++- 2 files changed, 10 insertions(+), 8 deletions(-) diff --git a/src/corelib/text/qstring.h b/src/corelib/text/qstring.h index 3e28d7727c2..c2628c6f7d3 100644 --- a/src/corelib/text/qstring.h +++ b/src/corelib/text/qstring.h @@ -1486,13 +1486,6 @@ inline QString &&asString(QString &&s) { return std::move(s); } static_cast(static_cast(QtPrivate::asString(string).utf16())) #endif -// -// QStringView::QStringView(const QString &) implementation -// - -inline QStringView::QStringView(const QString &str) noexcept - : QStringView(str.isNull() ? nullptr : str.data(), qsizetype(str.size())) {} - // // QStringView::arg() implementation // diff --git a/src/corelib/text/qstringview.h b/src/corelib/text/qstringview.h index e91bb6978c6..d9a4d4ba652 100644 --- a/src/corelib/text/qstringview.h +++ b/src/corelib/text/qstringview.h @@ -97,6 +97,9 @@ private: template using if_compatible_pointer = typename std::enable_if::value, bool>::type; + template + using if_compatible_qstring_like = typename std::enable_if::value, bool>::type; + template using if_compatible_container = typename std::enable_if::value, bool>::type; @@ -151,7 +154,13 @@ public: : QStringView(str, str ? lengthHelperPointer(str) : 0) {} #endif - inline QStringView(const QString &str) noexcept; +#ifdef Q_QDOC + QStringView(const QString &str) noexcept; +#else + template = true> + QStringView(const String &str) noexcept + : QStringView(str.isNull() ? nullptr : str.data(), qsizetype(str.size())) {} +#endif template = true> constexpr Q_ALWAYS_INLINE QStringView(const Container &c) noexcept