diff options
author | Giuseppe D'Angelo <giuseppe.dangelo@kdab.com> | 2015-05-16 12:52:30 +0200 |
---|---|---|
committer | Giuseppe D'Angelo <giuseppe.dangelo@kdab.com> | 2015-05-26 15:21:21 +0000 |
commit | d1de6c521ea2114b3bb6dbe4a0bb302f0a3db434 (patch) | |
tree | cd2212a888b1da8b9f895ca03c439a69ae004234 /src/corelib/tools/qvector.h | |
parent | ee336c2096618782d5f30245a055bdeae56ecd2f (diff) |
QVector: add const first/last getters
Convenience to avoid annoying detaching (instead of using at()),
especially on temporary vectors (returned by functions or so).
[ChangeLog][QtCore][QVector] Added the convenience constFirst
and constLast functions.
Change-Id: If61b1f0096f6a7a1c9074340e237cc2376ce3d18
Task-number: QTBUG-46026
Reviewed-by: Olivier Goffart (Woboq GmbH) <ogoffart@woboq.com>
Diffstat (limited to 'src/corelib/tools/qvector.h')
-rw-r--r-- | src/corelib/tools/qvector.h | 2 |
1 files changed, 2 insertions, 0 deletions
diff --git a/src/corelib/tools/qvector.h b/src/corelib/tools/qvector.h index 2eb2dc4550..2adf2d4522 100644 --- a/src/corelib/tools/qvector.h +++ b/src/corelib/tools/qvector.h @@ -212,8 +212,10 @@ public: inline int count() const { return d->size; } inline T& first() { Q_ASSERT(!isEmpty()); return *begin(); } inline const T &first() const { Q_ASSERT(!isEmpty()); return *begin(); } + inline const T &constFirst() const { Q_ASSERT(!isEmpty()); return *begin(); } inline T& last() { Q_ASSERT(!isEmpty()); return *(end()-1); } inline const T &last() const { Q_ASSERT(!isEmpty()); return *(end()-1); } + inline const T &constLast() 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 len = -1) const; |