From fb7404e569b5c69dd9e1c6eab3157826442872e8 Mon Sep 17 00:00:00 2001 From: Robin Burchell Date: Wed, 14 Dec 2011 17:49:35 +0100 Subject: Implement (and unit test) simple QVarLengthArray::first()/last(). MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Pure syntactical sugar, to match up with what the other container classes offer. Change-Id: I0f97de011923d9d204cca0fa906b059dc5054a89 Reviewed-by: João Abecasis Reviewed-by: Bradley T. Hughes --- src/corelib/tools/qvarlengtharray.h | 4 ++++ src/corelib/tools/qvarlengtharray.qdoc | 30 ++++++++++++++++++++++++++++++ 2 files changed, 34 insertions(+) (limited to 'src/corelib') diff --git a/src/corelib/tools/qvarlengtharray.h b/src/corelib/tools/qvarlengtharray.h index fd8c26c128..48b14e6816 100644 --- a/src/corelib/tools/qvarlengtharray.h +++ b/src/corelib/tools/qvarlengtharray.h @@ -96,6 +96,10 @@ public: inline int size() const { return s; } inline int count() const { return s; } inline int length() const { return s; } + inline T& first() { Q_ASSERT(!isEmpty()); return *begin(); } + inline const T& first() const { Q_ASSERT(!isEmpty()); return *begin(); } + T& last() { Q_ASSERT(!isEmpty()); return *(end() - 1); } + const T& last() const { Q_ASSERT(!isEmpty()); return *(end() - 1); } inline bool isEmpty() const { return (s == 0); } inline void resize(int size); inline void clear() { resize(0); } diff --git a/src/corelib/tools/qvarlengtharray.qdoc b/src/corelib/tools/qvarlengtharray.qdoc index a932e9fbcb..032521d1c2 100644 --- a/src/corelib/tools/qvarlengtharray.qdoc +++ b/src/corelib/tools/qvarlengtharray.qdoc @@ -125,6 +125,36 @@ \sa isEmpty(), resize() */ +/*! \fn T& QVarLengthArray::first() + + Returns a reference to the first item in the array. The array must + not be empty. If the array can be empty, check isEmpty() before + calling this function. + + \sa last(), isEmpty() +*/ + +/*! \fn const T& QVarLengthArray::first() const + + \overload +*/ + +/*! \fn T& QVarLengthArray::last() + + Returns a reference to the last item in the array. The array must + not be empty. If the array can be empty, check isEmpty() before + calling this function. + + \sa first(), isEmpty() +*/ + +/*! \fn const T& QVarLengthArray::last() const + + \overload +*/ + + + /*! \fn bool QVarLengthArray::isEmpty() const Returns true if the array has size 0; otherwise returns false. -- cgit v1.2.3