diff options
author | Giuseppe D'Angelo <giuseppe.dangelo@kdab.com> | 2020-10-16 16:15:02 +0200 |
---|---|---|
committer | Giuseppe D'Angelo <giuseppe.dangelo@kdab.com> | 2020-10-23 16:37:14 +0200 |
commit | 45cf0cf5135e653baaf689f51b3c6338d848c16e (patch) | |
tree | aae1539a0bed2e00667f19fb1d3b7ff1a53329ed /src/corelib/tools/qlist.qdoc | |
parent | d53bbecf4c2565f2e5fd834b20ff90b073a25189 (diff) |
QList: make (last)IndexOf and contains function templates
There's no reason why they shouldn't be; one might want to do a
lookup passing an object which is comparable with the list's value
type (e.g. search with a QByteArrayView needle into a QByteArrayList
haystack). Insofar we've had to add overloads to QListSpecialMethods
for all these cases, which clearly doesn't scale and creates
top-tier and low-tier lists.
There is one downside, namely, calling QList<A>::indexOf(B) for a B
for which there isn't an operator==(A, B) but only a conversion
towards A. Before, B was converted only once (at call site), now
it's converted at every call of operator==.
In general: such types are broken and should be fixed on their own.
However let's avoid a possible regression in client code, so I've
left the QString overloads in QStringList in.
To get there: centralize the implementation of those methods in a
empty base class, which gets then inherited by QListSpecialMethods,
which is inherited by QList. This is there are still special methods
that may want to overload contains, e.g. QStringList which also
passes a case sensitivity).
The only breakages comes from code that was already broken, for
instance mixing signed and unsigned types, and the beauty of this is
that now we *detect* that instead of silently ignoring.
QVLA and other QList methods will be tackled in future commits.
[ChangeLog][QtCore][QList] The indexOf, lastIndexOf and contains
methods now take an object of any datatype -- and not just the
list's own value type. This allows for heterogenous lookup in
QLists.
Change-Id: Ib34812217eb2b0f926fad1fc195b33758196941c
Reviewed-by: Lars Knoll <lars.knoll@qt.io>
Diffstat (limited to 'src/corelib/tools/qlist.qdoc')
-rw-r--r-- | src/corelib/tools/qlist.qdoc | 6 |
1 files changed, 3 insertions, 3 deletions
diff --git a/src/corelib/tools/qlist.qdoc b/src/corelib/tools/qlist.qdoc index 52ac5360c8..84296e8e47 100644 --- a/src/corelib/tools/qlist.qdoc +++ b/src/corelib/tools/qlist.qdoc @@ -952,7 +952,7 @@ \sa resize() */ -/*! \fn template <typename T> qsizetype QList<T>::indexOf(const T &value, qsizetype from = 0) const +/*! \fn template <typename T> template <typename AT> qsizetype QList<T>::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 <typename T> qsizetype QList<T>::lastIndexOf(const T &value, qsizetype from = -1) const +/*! \fn template <typename T> template <typename AT> qsizetype QList<T>::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 <typename T> bool QList<T>::contains(const T &value) const +/*! \fn template <typename T> template <typename AT> bool QList<T>::contains(const AT &value) const Returns \c true if the list contains an occurrence of \a value; otherwise returns \c false. |