Revert "QStringView: simplify the constructor from QString"

This reverts commit 7d18ad49a3.

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>
bb10
Marc Mutz 2024-02-27 12:24:08 +00:00
parent 7f7b5ff3a1
commit ff7e5987ec
2 changed files with 10 additions and 8 deletions

View File

@ -1539,13 +1539,6 @@ inline QString &&asString(QString &&s) { return std::move(s); }
static_cast<const wchar_t*>(static_cast<const void*>(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
//

View File

@ -98,6 +98,9 @@ private:
template <typename Pointer>
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;
@ -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