diff options
author | Giuseppe D'Angelo <giuseppe.dangelo@kdab.com> | 2023-10-04 13:24:31 +0200 |
---|---|---|
committer | Giuseppe D'Angelo <giuseppe.dangelo@kdab.com> | 2023-10-05 02:40:02 +0200 |
commit | 7d18ad49a37440835bb38bd77bc4e0991387ada0 (patch) | |
tree | b2ae980850fdc7ffe832f2722ad2235fd395d39e | |
parent | 2c6b7ff501f0f7e13bb0ec6583fc9b9c3865b76e (diff) |
QStringView: simplify the constructor from QString
We have to single QString out because of the isNull/isEmpty distinction.
Still, we can avoid having a constructor template on it constrained on
the argument being precisely QString. This is a historic remnant; in Qt
5 the constructor also worked with QStringRef.
Change-Id: I5457a83d5b77887f57ea9910a826f729ec276d28
Reviewed-by: Thiago Macieira <thiago.macieira@intel.com>
-rw-r--r-- | src/corelib/text/qstring.h | 7 | ||||
-rw-r--r-- | src/corelib/text/qstringview.h | 11 |
2 files changed, 8 insertions, 10 deletions
diff --git a/src/corelib/text/qstring.h b/src/corelib/text/qstring.h index 06c6f668c4..31d19f7fe6 100644 --- a/src/corelib/text/qstring.h +++ b/src/corelib/text/qstring.h @@ -1437,6 +1437,13 @@ 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 05e5ec3fdb..d62dd71bdf 100644 --- a/src/corelib/text/qstringview.h +++ b/src/corelib/text/qstringview.h @@ -97,9 +97,6 @@ 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> @@ -155,13 +152,7 @@ public: : QStringView(str, str ? lengthHelperPointer(str) : 0) {} #endif -#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 + inline QStringView(const QString &str) noexcept; template <typename Container, if_compatible_container<Container> = true> constexpr Q_ALWAYS_INLINE QStringView(const Container &c) noexcept |