diff options
Diffstat (limited to 'src/corelib/tools/qlist.h')
-rw-r--r-- | src/corelib/tools/qlist.h | 56 |
1 files changed, 56 insertions, 0 deletions
diff --git a/src/corelib/tools/qlist.h b/src/corelib/tools/qlist.h index f5ff952f97..ac46dc3244 100644 --- a/src/corelib/tools/qlist.h +++ b/src/corelib/tools/qlist.h @@ -38,6 +38,7 @@ #include <QtCore/qiterator.h> #include <QtCore/qrefcount.h> #include <QtCore/qarraydata.h> +#include <QtCore/qhashfunctions.h> #include <iterator> #include <list> @@ -220,7 +221,11 @@ public: inline iterator() : i(0) {} inline iterator(Node *n) : i(n) {} +#if QT_VERSION < QT_VERSION_CHECK(6,0,0) + // can't remove it in Qt 5, since doing so would make the type trivial, + // which changes the way it's passed to functions by value. inline iterator(const iterator &o): i(o.i){} +#endif inline T &operator*() const { return i->t(); } inline T *operator->() const { return &i->t(); } inline T &operator[](difference_type j) const { return i[j].t(); } @@ -268,7 +273,11 @@ public: inline const_iterator() : i(0) {} inline const_iterator(Node *n) : i(n) {} +#if QT_VERSION < QT_VERSION_CHECK(6,0,0) + // can't remove it in Qt 5, since doing so would make the type trivial, + // which changes the way it's passed to functions by value. inline const_iterator(const const_iterator &o): i(o.i) {} +#endif #ifdef QT_STRICT_ITERATORS inline explicit const_iterator(const iterator &o): i(o.i) {} #else @@ -296,6 +305,8 @@ public: friend class const_iterator; // stl style + typedef std::reverse_iterator<iterator> reverse_iterator; + typedef std::reverse_iterator<const_iterator> const_reverse_iterator; inline iterator begin() { detach(); return reinterpret_cast<Node *>(p.begin()); } inline const_iterator begin() const { return reinterpret_cast<Node *>(p.begin()); } inline const_iterator cbegin() const { return reinterpret_cast<Node *>(p.begin()); } @@ -304,6 +315,12 @@ public: inline const_iterator end() const { return reinterpret_cast<Node *>(p.end()); } inline const_iterator cend() const { return reinterpret_cast<Node *>(p.end()); } inline const_iterator constEnd() const { return reinterpret_cast<Node *>(p.end()); } + reverse_iterator rbegin() { return reverse_iterator(end()); } + reverse_iterator rend() { return reverse_iterator(begin()); } + const_reverse_iterator rbegin() const { return const_reverse_iterator(end()); } + const_reverse_iterator rend() const { return const_reverse_iterator(begin()); } + const_reverse_iterator crbegin() const { return const_reverse_iterator(end()); } + const_reverse_iterator crend() const { return const_reverse_iterator(begin()); } iterator insert(iterator before, const T &t); iterator erase(iterator pos); iterator erase(iterator first, iterator last); @@ -314,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; } @@ -1020,6 +1039,43 @@ inline int QList<T>::count_impl(const T &t, QListData::ArrayCompatibleLayout) co Q_DECLARE_SEQUENTIAL_ITERATOR(List) Q_DECLARE_MUTABLE_SEQUENTIAL_ITERATOR(List) +template <typename T> +uint qHash(const QList<T> &key, uint seed = 0) + Q_DECL_NOEXCEPT_EXPR(noexcept(qHashRange(key.cbegin(), key.cend(), seed))) +{ + return qHashRange(key.cbegin(), key.cend(), seed); +} + +template <typename T> +bool operator<(const QList<T> &lhs, const QList<T> &rhs) + Q_DECL_NOEXCEPT_EXPR(noexcept(std::lexicographical_compare(lhs.begin(), lhs.end(), + rhs.begin(), rhs.end()))) +{ + return std::lexicographical_compare(lhs.begin(), lhs.end(), + rhs.begin(), rhs.end()); +} + +template <typename T> +inline bool operator>(const QList<T> &lhs, const QList<T> &rhs) + Q_DECL_NOEXCEPT_EXPR(noexcept(lhs < rhs)) +{ + return rhs < lhs; +} + +template <typename T> +inline bool operator<=(const QList<T> &lhs, const QList<T> &rhs) + Q_DECL_NOEXCEPT_EXPR(noexcept(lhs < rhs)) +{ + return !(lhs > rhs); +} + +template <typename T> +inline bool operator>=(const QList<T> &lhs, const QList<T> &rhs) + Q_DECL_NOEXCEPT_EXPR(noexcept(lhs < rhs)) +{ + return !(lhs < rhs); +} + QT_END_NAMESPACE #include <QtCore/qbytearraylist.h> |