summaryrefslogtreecommitdiffstats
path: root/src/corelib/tools/qvector.h
diff options
context:
space:
mode:
authorMarc Mutz <marc.mutz@kdab.com>2013-10-08 13:17:52 +0200
committerThe Qt Project <gerrit-noreply@qt-project.org>2014-03-26 00:21:22 +0100
commit84c10500b1730e8d947732728d190fde612fc840 (patch)
tree6378b7246b6c25ca93e1e64c05650a3e6c81db16 /src/corelib/tools/qvector.h
parent9157a1f97a47fd63d1e58c560d30c25f97674ae8 (diff)
QVector: add removeOne(), removeAll() for QList compatibility
Eases migration from QList to QVector. [ChangeLog][QtCore][QVector] Added removeOne(), removeAll() for QList compatibility. Change-Id: I4211afb2e077c187d0a39f0ac4528f0c66721fb3 Reviewed-by: Olivier Goffart <ogoffart@woboq.com>
Diffstat (limited to 'src/corelib/tools/qvector.h')
-rw-r--r--src/corelib/tools/qvector.h19
1 files changed, 19 insertions, 0 deletions
diff --git a/src/corelib/tools/qvector.h b/src/corelib/tools/qvector.h
index 075e8e83e8..d1420088a4 100644
--- a/src/corelib/tools/qvector.h
+++ b/src/corelib/tools/qvector.h
@@ -154,6 +154,24 @@ public:
// QList compatibility
void removeAt(int i) { remove(i); }
+ int removeAll(const T &t)
+ {
+ const const_iterator ce = this->cend(), cit = std::find(this->cbegin(), ce, t);
+ if (cit == ce)
+ return 0;
+ const iterator e = end(), it = std::remove(c2m(cit), e, t);
+ const int result = std::distance(it, e);
+ erase(it, e);
+ return result;
+ }
+ bool removeOne(const T &t)
+ {
+ const int i = indexOf(t);
+ if (i < 0)
+ return false;
+ remove(i);
+ return true;
+ }
int length() const { return size(); }
T takeAt(int i) { T t = at(i); remove(i); return t; }
@@ -250,6 +268,7 @@ private:
{
return (i <= d->end()) && (d->begin() <= i);
}
+ iterator c2m(const_iterator it) { return begin() + (it - cbegin()); }
class AlignmentDummy { Data header; T array[1]; };
};