summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorMarc Mutz <marc.mutz@qt.io>2024-02-27 12:24:08 +0000
committerQt Cherry-pick Bot <cherrypick_bot@qt-project.org>2024-03-06 10:28:03 +0000
commit9ea3087d365fa9184d06d4f164ad73f905bab7bd (patch)
treeeb76bc9c73cf5002fe4b5d1678efc134dcf67098
parent244618c19af8c5bc5b39c1dc6c0c387e7040b50b (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. 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> (cherry picked from commit ff7e5987ecdd09f87cfcdb4c42039214627dcdb6) Reviewed-by: Qt Cherry-pick Bot <cherrypick_bot@qt-project.org>
-rw-r--r--src/corelib/text/qstring.h7
-rw-r--r--src/corelib/text/qstringview.h11
2 files changed, 10 insertions, 8 deletions
diff --git a/src/corelib/text/qstring.h b/src/corelib/text/qstring.h
index 3e28d7727c..c2628c6f7d 100644
--- a/src/corelib/text/qstring.h
+++ b/src/corelib/text/qstring.h
@@ -1487,13 +1487,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 e91bb6978c..d9a4d4ba65 100644
--- a/src/corelib/text/qstringview.h
+++ b/src/corelib/text/qstringview.h
@@ -98,6 +98,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>
@@ -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 <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