From d1de6c521ea2114b3bb6dbe4a0bb302f0a3db434 Mon Sep 17 00:00:00 2001 From: Giuseppe D'Angelo Date: Sat, 16 May 2015 12:52:30 +0200 Subject: 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) --- src/corelib/tools/qvector.h | 2 ++ 1 file changed, 2 insertions(+) (limited to 'src/corelib/tools/qvector.h') 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 mid(int pos, int len = -1) const; -- cgit v1.2.3