diff --git a/src/corelib/text/qbytearraylist.h b/src/corelib/text/qbytearraylist.h index 25f4395a5d6..e00586291f6 100644 --- a/src/corelib/text/qbytearraylist.h +++ b/src/corelib/text/qbytearraylist.h @@ -63,7 +63,7 @@ namespace QtPrivate { #ifdef Q_CLANG_QDOC class QByteArrayList : public QList #else -template <> struct QListSpecialMethods +template <> struct QListSpecialMethods : QListSpecialMethodsBase #endif { #ifndef Q_CLANG_QDOC @@ -71,12 +71,9 @@ protected: ~QListSpecialMethods() = default; #endif public: - qsizetype indexOf(const QByteArray &ba, qsizetype from = 0) const noexcept - { return QtPrivate::indexOf(*self(), ba, from); } - qsizetype lastIndexOf(const QByteArray &ba, qsizetype from = -1) const noexcept - { return QtPrivate::lastIndexOf(*self(), ba, from); } - bool contains(const QByteArray &ba) const noexcept - { return indexOf(ba) != -1; } + using QListSpecialMethodsBase::indexOf; + using QListSpecialMethodsBase::lastIndexOf; + using QListSpecialMethodsBase::contains; inline QByteArray join() const { return QtPrivate::QByteArrayList_join(self(), nullptr, 0); } @@ -84,11 +81,6 @@ public: { return QtPrivate::QByteArrayList_join(self(), sep.constData(), sep.size()); } inline QByteArray join(char sep) const { return QtPrivate::QByteArrayList_join(self(), &sep, 1); } - -private: - typedef QList Self; - Self *self() { return static_cast(this); } - const Self *self() const { return static_cast(this); } }; QT_END_NAMESPACE diff --git a/src/corelib/text/qstringlist.cpp b/src/corelib/text/qstringlist.cpp index 233f7653558..c3957503763 100644 --- a/src/corelib/text/qstringlist.cpp +++ b/src/corelib/text/qstringlist.cpp @@ -369,55 +369,6 @@ bool QtPrivate::QStringList_contains(const QStringList *that, QLatin1String str, return stringList_contains(*that, str, cs); } -/*! - \fn bool QStringList::indexOf(QStringView str, qsizetype from) const - \overload - \since 5.13 - - Returns the index position of the first occurrence of \a str in - the list, searching forward from index position \a from. Returns - -1 if no item matched. - - \sa lastIndexOf(), contains() - */ - -/*! - \fn bool QStringList::indexOf(QLatin1String str, qsizetype from) const - \overload - \since 5.13 - - Returns the index position of the first occurrence of \a str in - the list, searching forward from index position \a from. Returns - -1 if no item matched. - - \sa lastIndexOf(), contains() - */ - -/*! - \fn bool QStringList::lastIndexOf(QStringView str, qsizetype from) const - \overload - \since 5.13 - - Returns the index position of the last occurrence of \a str in - the list, searching backward from index position \a from. If \a - from is -1 (the default), the search starts at the last item. - Returns -1 if no item matched. - - \sa indexOf(), contains() - */ - -/*! - \fn bool QStringList::lastIndexOf(QLatin1String str, qsizetype from) const - \overload - \since 5.13 - - Returns the index position of the last occurrence of \a str in - the list, searching backward from index position \a from. If \a - from is -1 (the default), the search starts at the last item. - Returns -1 if no item matched. - - \sa indexOf(), contains() - */ #if QT_CONFIG(regularexpression) /*! diff --git a/src/corelib/text/qstringlist.h b/src/corelib/text/qstringlist.h index 2894fa78cf0..5ec95036be6 100644 --- a/src/corelib/text/qstringlist.h +++ b/src/corelib/text/qstringlist.h @@ -82,7 +82,7 @@ namespace QtPrivate { #ifdef Q_QDOC class QStringList : public QList #else -template <> struct QListSpecialMethods +template <> struct QListSpecialMethods : QListSpecialMethodsBase #endif { #ifdef Q_QDOC @@ -100,10 +100,6 @@ public: QStringList &operator<<(const QList &other); private: #endif - inline QStringList *self() - { return static_cast(this); } - inline const QStringList *self() const - { return static_cast(this); } public: inline void sort(Qt::CaseSensitivity cs = Qt::CaseSensitive) @@ -147,22 +143,15 @@ public: return *self(); } #endif + using QListSpecialMethodsBase::contains; + using QListSpecialMethodsBase::indexOf; + using QListSpecialMethodsBase::lastIndexOf; inline bool contains(QLatin1String str, Qt::CaseSensitivity cs = Qt::CaseSensitive) const noexcept { return QtPrivate::QStringList_contains(self(), str, cs); } inline bool contains(QStringView str, Qt::CaseSensitivity cs = Qt::CaseSensitive) const noexcept { return QtPrivate::QStringList_contains(self(), str, cs); } - inline qsizetype indexOf(QStringView str, qsizetype from = 0) const noexcept - { return QtPrivate::indexOf(*self(), str, from); } - inline qsizetype indexOf(QLatin1String str, qsizetype from = 0) const noexcept - { return QtPrivate::indexOf(*self(), str, from); } - - inline qsizetype lastIndexOf(QStringView str, qsizetype from = -1) const noexcept - { return QtPrivate::lastIndexOf(*self(), str, from); } - inline qsizetype lastIndexOf(QLatin1String str, qsizetype from = -1) const noexcept - { return QtPrivate::lastIndexOf(*self(), str, from); } - #if QT_STRINGVIEW_LEVEL < 2 inline bool contains(const QString &str, Qt::CaseSensitivity cs = Qt::CaseSensitive) const noexcept { return QtPrivate::QStringList_contains(self(), str, cs); } diff --git a/src/corelib/tools/qlist.h b/src/corelib/tools/qlist.h index 6931bd6cbcc..38cc0ed348e 100644 --- a/src/corelib/tools/qlist.h +++ b/src/corelib/tools/qlist.h @@ -58,18 +58,35 @@ namespace QtPrivate { template qsizetype lastIndexOf(const QList &list, const U &u, qsizetype from) noexcept; } -template struct QListSpecialMethods +template struct QListSpecialMethodsBase +{ +protected: + ~QListSpecialMethodsBase() = default; + + using Self = QList; + Self *self() { return static_cast(this); } + const Self *self() const { return static_cast(this); } + +public: + template + qsizetype indexOf(const AT &t, qsizetype from = 0) const noexcept; + template + qsizetype lastIndexOf(const AT &t, qsizetype from = -1) const noexcept; + + template + bool contains(const AT &t) const noexcept + { + return self()->indexOf(t) != -1; + } +}; +template struct QListSpecialMethods : QListSpecialMethodsBase { protected: ~QListSpecialMethods() = default; public: - qsizetype indexOf(const T &t, qsizetype from = 0) const noexcept; - qsizetype lastIndexOf(const T &t, qsizetype from = -1) const noexcept; - - bool contains(const T &t) const noexcept - { - return indexOf(t) != -1; - } + using QListSpecialMethodsBase::indexOf; + using QListSpecialMethodsBase::lastIndexOf; + using QListSpecialMethodsBase::contains; }; template <> struct QListSpecialMethods; template <> struct QListSpecialMethods; @@ -327,12 +344,16 @@ public: using QListSpecialMethods::indexOf; using QListSpecialMethods::lastIndexOf; #else - qsizetype indexOf(const T &t, qsizetype from = 0) const noexcept; - qsizetype lastIndexOf(const T &t, qsizetype from = -1) const noexcept; - bool contains(const T &t) const noexcept; + template + qsizetype indexOf(const AT &t, qsizetype from = 0) const noexcept; + template + qsizetype lastIndexOf(const AT &t, qsizetype from = -1) const noexcept; + template + bool contains(const AT &t) const noexcept; #endif - qsizetype count(parameter_type t) const noexcept + template + qsizetype count(const AT &t) const noexcept { return qsizetype(std::count(&*cbegin(), &*cend(), t)); } @@ -790,15 +811,17 @@ qsizetype lastIndexOf(const QList &vector, const U &u, qsizetype from) noexce } template -qsizetype QListSpecialMethods::indexOf(const T &t, qsizetype from) const noexcept +template +qsizetype QListSpecialMethodsBase::indexOf(const AT &t, qsizetype from) const noexcept { - return QtPrivate::indexOf(*static_cast *>(this), t, from); + return QtPrivate::indexOf(*self(), t, from); } template -qsizetype QListSpecialMethods::lastIndexOf(const T &t, qsizetype from) const noexcept +template +qsizetype QListSpecialMethodsBase::lastIndexOf(const AT &t, qsizetype from) const noexcept { - return QtPrivate::lastIndexOf(*static_cast *>(this), t, from); + return QtPrivate::lastIndexOf(*self(), t, from); } template diff --git a/src/corelib/tools/qlist.qdoc b/src/corelib/tools/qlist.qdoc index 52ac5360c87..84296e8e47e 100644 --- a/src/corelib/tools/qlist.qdoc +++ b/src/corelib/tools/qlist.qdoc @@ -952,7 +952,7 @@ \sa resize() */ -/*! \fn template qsizetype QList::indexOf(const T &value, qsizetype from = 0) const +/*! \fn template template qsizetype QList::indexOf(const AT &value, qsizetype from = 0) const Returns the index position of the first occurrence of \a value in the list, searching forward from index position \a from. @@ -967,7 +967,7 @@ \sa lastIndexOf(), contains() */ -/*! \fn template qsizetype QList::lastIndexOf(const T &value, qsizetype from = -1) const +/*! \fn template template qsizetype QList::lastIndexOf(const AT &value, qsizetype from = -1) const Returns the index position of the last occurrence of the value \a value in the list, searching backward from index position \a @@ -983,7 +983,7 @@ \sa indexOf() */ -/*! \fn template bool QList::contains(const T &value) const +/*! \fn template template bool QList::contains(const AT &value) const Returns \c true if the list contains an occurrence of \a value; otherwise returns \c false.