QList/QVLA: default the parameter for indexOf/contains/remove/etc.

This allows to use list-initialization when calling these functions,
for instance list.removeAll({}).

Change-Id: I2828d900a44bd0bc5aea5fba4777304b09190bc9
Reviewed-by: Thiago Macieira <thiago.macieira@intel.com>
This commit is contained in:
Giuseppe D'Angelo 2020-10-20 18:23:46 +02:00
parent 45cf0cf513
commit 155ee2bbd7
2 changed files with 8 additions and 8 deletions

View File

@ -68,12 +68,12 @@ protected:
const Self *self() const { return static_cast<const Self *>(this); } const Self *self() const { return static_cast<const Self *>(this); }
public: public:
template <typename AT> template <typename AT = T>
qsizetype indexOf(const AT &t, qsizetype from = 0) const noexcept; qsizetype indexOf(const AT &t, qsizetype from = 0) const noexcept;
template <typename AT> template <typename AT = T>
qsizetype lastIndexOf(const AT &t, qsizetype from = -1) const noexcept; qsizetype lastIndexOf(const AT &t, qsizetype from = -1) const noexcept;
template <typename AT> template <typename AT = T>
bool contains(const AT &t) const noexcept bool contains(const AT &t) const noexcept
{ {
return self()->indexOf(t) != -1; return self()->indexOf(t) != -1;
@ -360,7 +360,7 @@ public:
// QList compatibility // QList compatibility
void removeAt(qsizetype i) { remove(i); } void removeAt(qsizetype i) { remove(i); }
template <typename AT> template <typename AT = T>
qsizetype removeAll(const AT &t) qsizetype removeAll(const AT &t)
{ {
const const_iterator ce = this->cend(), cit = std::find(this->cbegin(), ce, t); const const_iterator ce = this->cend(), cit = std::find(this->cbegin(), ce, t);
@ -381,7 +381,7 @@ public:
erase(it, e); erase(it, e);
return result; return result;
} }
template <typename AT> template <typename AT = T>
bool removeOne(const AT &t) bool removeOne(const AT &t)
{ {
const qsizetype i = indexOf(t); const qsizetype i = indexOf(t);

View File

@ -190,11 +190,11 @@ public:
inline qsizetype capacity() const { return a; } inline qsizetype capacity() const { return a; }
inline void reserve(qsizetype size); inline void reserve(qsizetype size);
template <typename AT> template <typename AT = T>
inline qsizetype indexOf(const AT &t, qsizetype from = 0) const; inline qsizetype indexOf(const AT &t, qsizetype from = 0) const;
template <typename AT> template <typename AT = T>
inline qsizetype lastIndexOf(const AT &t, qsizetype from = -1) const; inline qsizetype lastIndexOf(const AT &t, qsizetype from = -1) const;
template <typename AT> template <typename AT = T>
inline bool contains(const AT &t) const; inline bool contains(const AT &t) const;
inline T &operator[](qsizetype idx) inline T &operator[](qsizetype idx)