diff options
author | Marc Mutz <marc.mutz@kdab.com> | 2013-10-05 03:48:45 +0200 |
---|---|---|
committer | The Qt Project <gerrit-noreply@qt-project.org> | 2013-10-11 18:47:27 +0200 |
commit | 059857d4d5dc5862d0135c839e7dabaa7331e4b5 (patch) | |
tree | f7452bccc8493d88927ed5cc56d49ce7138436b7 /src/corelib/tools/qvector.h | |
parent | 0e96e47debd1d8c48d1d23fd51c9ee05f61c80e0 (diff) |
QVector: add some functions missing for QList compat
Eases migration from QList to QVector.
Had to rename the 'length' parameter to mid() to suppress
-Wshadow warnings.
Task-number: QTBUG-3781
Change-Id: I755c6caefe4de81ea42a81b1c76aab728e639613
Reviewed-by: Lars Knoll <lars.knoll@digia.com>
Diffstat (limited to 'src/corelib/tools/qvector.h')
-rw-r--r-- | src/corelib/tools/qvector.h | 23 |
1 files changed, 14 insertions, 9 deletions
diff --git a/src/corelib/tools/qvector.h b/src/corelib/tools/qvector.h index 3d86440fcd..f56511edbf 100644 --- a/src/corelib/tools/qvector.h +++ b/src/corelib/tools/qvector.h @@ -152,6 +152,11 @@ public: bool contains(const T &t) const; int count(const T &t) const; + // QList compatibility + void removeAt(int i) { remove(i); } + int length() const { return size(); } + T takeAt(int i) { T t = at(i); remove(i); return t; } + // STL-style typedef typename Data::iterator iterator; typedef typename Data::const_iterator const_iterator; @@ -187,7 +192,7 @@ public: inline const T &last() const { Q_ASSERT(!isEmpty()); return *(end()-1); } inline bool startsWith(const T &t) const { return !isEmpty() && first() == t; } inline bool endsWith(const T &t) const { return !isEmpty() && last() == t; } - QVector<T> mid(int pos, int length = -1) const; + QVector<T> mid(int pos, int len = -1) const; T value(int i) const; T value(int i, const T &defaultValue) const; @@ -772,17 +777,17 @@ int QVector<T>::count(const T &t) const } template <typename T> -Q_OUTOFLINE_TEMPLATE QVector<T> QVector<T>::mid(int pos, int length) const +Q_OUTOFLINE_TEMPLATE QVector<T> QVector<T>::mid(int pos, int len) const { - if (length < 0) - length = size() - pos; - if (pos == 0 && length == size()) + if (len < 0) + len = size() - pos; + if (pos == 0 && len == size()) return *this; - if (pos + length > size()) - length = size() - pos; + if (pos + len > size()) + len = size() - pos; QVector<T> copy; - copy.reserve(length); - for (int i = pos; i < pos + length; ++i) + copy.reserve(len); + for (int i = pos; i < pos + len; ++i) copy += at(i); return copy; } |