diff options
Diffstat (limited to 'src/corelib')
-rw-r--r-- | src/corelib/tools/qvector.cpp | 26 | ||||
-rw-r--r-- | src/corelib/tools/qvector.h | 2 |
2 files changed, 26 insertions, 2 deletions
diff --git a/src/corelib/tools/qvector.cpp b/src/corelib/tools/qvector.cpp index 5ece011f0b..e72c1964a2 100644 --- a/src/corelib/tools/qvector.cpp +++ b/src/corelib/tools/qvector.cpp @@ -551,7 +551,7 @@ the vector can be empty, call isEmpty() before calling this function. - \sa remove(), isEmpty() + \sa remove(), takeFirst(), isEmpty() */ /*! \fn void QVector::removeLast() @@ -561,9 +561,31 @@ empty. If the vector can be empty, call isEmpty() before calling this function. - \sa remove(), removeFirst(), isEmpty() + \sa remove(), takeLast(), removeFirst(), isEmpty() */ +/*! \fn T QVector::takeFirst() + + Removes the first item in the vector and returns it. This function + assumes the vector is not empty. To avoid failure, call isEmpty() + before calling this function. + + \sa takeLast(), removeFirst() +*/ + +/*! \fn T QVector::takeLast() + + Removes the last item in the list and returns it. This function + assumes the vector is not empty. To avoid failure, call isEmpty() + before calling this function. + + If you don't use the return value, removeLast() is more + efficient. + + \sa takeFirst(), removeLast() +*/ + + /*! \fn QVector &QVector::fill(const T &value, int size = -1) Assigns \a value to all items in the vector. If \a size is diff --git a/src/corelib/tools/qvector.h b/src/corelib/tools/qvector.h index f6fe316a15..e2c28e4060 100644 --- a/src/corelib/tools/qvector.h +++ b/src/corelib/tools/qvector.h @@ -140,6 +140,8 @@ public: 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); } + inline T takeFirst() { Q_ASSERT(!isEmpty()); T r = first(); removeFirst(); return r; } + inline T takeLast() { Q_ASSERT(!isEmpty()); T r = last(); removeLast(); return r; } QVector<T> &fill(const T &t, int size = -1); |