diff options
author | Marc Mutz <marc.mutz@qt.io> | 2024-02-27 12:24:08 +0000 |
---|---|---|
committer | Marc Mutz <marc.mutz@qt.io> | 2024-03-06 11:09:16 +0100 |
commit | ff7e5987ecdd09f87cfcdb4c42039214627dcdb6 (patch) | |
tree | b681f7013a06f42c8c83ecebd093676ea273c772 | |
parent | 7f7b5ff3a1b617a3a1add1b1b6ad0718f0dcf143 (diff) |
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.
Pick-to: 6.7
Change-Id: Icd506e7221bb50c99f276f6a43c15403ec0be7a9
Reviewed-by: Ivan Solovev <ivan.solovev@qt.io>
Reviewed-by: Thiago Macieira <thiago.macieira@intel.com>
Reviewed-by: Qt CI Bot <qt_ci_bot@qt-project.org>
-rw-r--r-- | src/corelib/text/qstring.h | 7 | ||||
-rw-r--r-- | 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 a76909c081..198b63c995 100644 --- a/src/corelib/text/qstring.h +++ b/src/corelib/text/qstring.h @@ -1540,13 +1540,6 @@ inline QString &&asString(QString &&s) { return std::move(s); } #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 742ecadcf5..ab97d834d3 100644 --- a/src/corelib/text/qstringview.h +++ b/src/corelib/text/qstringview.h @@ -99,6 +99,9 @@ private: using if_compatible_pointer = typename std::enable_if<QtPrivate::IsCompatiblePointer<Pointer>::value, bool>::type; template <typename T> + using if_compatible_qstring_like = typename std::enable_if<std::is_same<T, QString>::value, bool>::type; + + template <typename T> using if_compatible_container = typename std::enable_if<QtPrivate::IsContainerCompatibleWithQStringView<T>::value, bool>::type; template <typename Char> @@ -152,7 +155,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 <typename String, if_compatible_qstring_like<String> = true> + QStringView(const String &str) noexcept + : QStringView(str.isNull() ? nullptr : str.data(), qsizetype(str.size())) {} +#endif template <typename Container, if_compatible_container<Container> = true> constexpr Q_ALWAYS_INLINE QStringView(const Container &c) noexcept |