diff options
author | Thorbjørn Martsum <tmartsum@gmail.com> | 2013-02-13 17:48:49 +0100 |
---|---|---|
committer | The Qt Project <gerrit-noreply@qt-project.org> | 2013-03-07 06:12:59 +0100 |
commit | 510660080de6fab87e117de2663c33eff5ae451b (patch) | |
tree | 20edeb768f3dbfb2b4e85c86d4d3ede6a04e41b0 /src | |
parent | d1308232d31cb0b414e844fb18c8a02b7cba62c1 (diff) |
QVector - add remove functions
This patch adds the functions removeFirst() and removeLast().
Functions that QList has.
Beside making these functions, pop_back and pop_front are
redirected to these rather than calling erase.
Change-Id: Ifc5f8a78e33f436f06f21095a920ec5d4311fd6f
Reviewed-by: Thiago Macieira <thiago.macieira@intel.com>
Diffstat (limited to 'src')
-rw-r--r-- | src/corelib/tools/qvector.cpp | 24 | ||||
-rw-r--r-- | src/corelib/tools/qvector.h | 6 |
2 files changed, 26 insertions, 4 deletions
diff --git a/src/corelib/tools/qvector.cpp b/src/corelib/tools/qvector.cpp index efc4b6a446..5ece011f0b 100644 --- a/src/corelib/tools/qvector.cpp +++ b/src/corelib/tools/qvector.cpp @@ -544,6 +544,26 @@ \sa insert(), replace(), fill() */ +/*! \fn void QVector::removeFirst() + \since 5.1 + Removes the first item in the vector. Calling this function is + equivalent to calling remove(0). The vector must not be empty. If + the vector can be empty, call isEmpty() before calling this + function. + + \sa remove(), isEmpty() +*/ + +/*! \fn void QVector::removeLast() + \since 5.1 + Removes the last item in the vector. Calling this function is + equivalent to calling remove(size() - 1). The vector must not be + empty. If the vector can be empty, call isEmpty() before calling + this function. + + \sa remove(), removeFirst(), isEmpty() +*/ + /*! \fn QVector &QVector::fill(const T &value, int size = -1) Assigns \a value to all items in the vector. If \a size is @@ -773,13 +793,13 @@ /*! \fn void QVector::pop_front() This function is provided for STL compatibility. It is equivalent - to erase(begin()). + to removeFirst(). */ /*! \fn void QVector::pop_back() This function is provided for STL compatibility. It is equivalent - to erase(end() - 1). + to removeLast(). */ /*! \fn T& QVector::front() diff --git a/src/corelib/tools/qvector.h b/src/corelib/tools/qvector.h index 7d5cf91324..f6fe316a15 100644 --- a/src/corelib/tools/qvector.h +++ b/src/corelib/tools/qvector.h @@ -138,6 +138,8 @@ public: void replace(int i, const T &t); void remove(int i); void remove(int i, int n); + inline void removeFirst() { Q_ASSERT(!isEmpty()); erase(d->begin()); } + inline void removeLast() { Q_ASSERT(!isEmpty()); erase(d->end() - 1); } QVector<T> &fill(const T &t, int size = -1); @@ -198,8 +200,8 @@ public: typedef int size_type; inline void push_back(const T &t) { append(t); } inline void push_front(const T &t) { prepend(t); } - void pop_back() { Q_ASSERT(!isEmpty()); erase(d->end() - 1); } - void pop_front() { Q_ASSERT(!isEmpty()); erase(d->begin()); } + void pop_back() { removeLast(); } + void pop_front() { removeFirst(); } inline bool empty() const { return d->size == 0; } inline T& front() { return first(); } |