summaryrefslogtreecommitdiffstats
path: root/src/corelib/tools
diff options
context:
space:
mode:
Diffstat (limited to 'src/corelib/tools')
-rw-r--r--src/corelib/tools/qlist.cpp24
-rw-r--r--src/corelib/tools/qlist.h2
2 files changed, 24 insertions, 2 deletions
diff --git a/src/corelib/tools/qlist.cpp b/src/corelib/tools/qlist.cpp
index f4901d336e..d774548d3a 100644
--- a/src/corelib/tools/qlist.cpp
+++ b/src/corelib/tools/qlist.cpp
@@ -1227,7 +1227,7 @@ void **QListData::erase(void **xi)
not be empty. If the list can be empty, call isEmpty() before
calling this function.
- \sa last(), isEmpty()
+ \sa constFirst(), last(), isEmpty()
*/
/*! \fn const T& QList::first() const
@@ -1235,13 +1235,23 @@ void **QListData::erase(void **xi)
\overload
*/
+/*! \fn const T& QList::constFirst() const
+ \since 5.6
+
+ Returns a const reference to the first item in the list. The list must
+ not be empty. If the list can be empty, call isEmpty() before
+ calling this function.
+
+ \sa constLast(), isEmpty(), first()
+*/
+
/*! \fn T& QList::last()
Returns a reference to the last item in the list. The list must
not be empty. If the list can be empty, call isEmpty() before
calling this function.
- \sa first(), isEmpty()
+ \sa constLast(), first(), isEmpty()
*/
/*! \fn const T& QList::last() const
@@ -1249,6 +1259,16 @@ void **QListData::erase(void **xi)
\overload
*/
+/*! \fn const T& QList::constLast() const
+ \since 5.6
+
+ Returns a reference to the last item in the list. The list must
+ not be empty. If the list can be empty, call isEmpty() before
+ calling this function.
+
+ \sa constFirst(), isEmpty(), last()
+*/
+
/*! \fn void QList::removeFirst()
Removes the first item in the list. Calling this function is
diff --git a/src/corelib/tools/qlist.h b/src/corelib/tools/qlist.h
index e446a6625b..ac46dc3244 100644
--- a/src/corelib/tools/qlist.h
+++ b/src/corelib/tools/qlist.h
@@ -331,9 +331,11 @@ public:
inline int count() const { return p.size(); }
inline int length() const { return p.size(); } // Same as count()
inline T& first() { Q_ASSERT(!isEmpty()); return *begin(); }
+ inline const T& constFirst() const { return first(); }
inline const T& first() const { Q_ASSERT(!isEmpty()); return at(0); }
T& last() { Q_ASSERT(!isEmpty()); return *(--end()); }
const T& last() const { Q_ASSERT(!isEmpty()); return at(count() - 1); }
+ inline const T& constLast() const { return last(); }
inline void removeFirst() { Q_ASSERT(!isEmpty()); erase(begin()); }
inline void removeLast() { Q_ASSERT(!isEmpty()); erase(--end()); }
inline bool startsWith(const T &t) const { return !isEmpty() && first() == t; }