From ad972af8fb771129b6db69dbb13855021d14e2fe Mon Sep 17 00:00:00 2001 From: Giuseppe D'Angelo Date: Wed, 13 Oct 2021 01:50:45 +0200 Subject: [PATCH] QList: add mixed comparison operators between (const_)iterators It is currently possible to compare a QList iterator with a const_iterator and viceversa, even though these operations aren't defined, because they are actually routed through the relational operators between iterators and raw pointers after a conversion (!). With the deprecation of iterator->pointer implicit conversions, this is going to break, so add the missig mixed comparison operators. Change-Id: Ic645ab0246f79f64b04334ecd02e9fe8fa46f0fa Reviewed-by: Thiago Macieira --- src/corelib/tools/qlist.h | 17 +++++++++++++++-- 1 file changed, 15 insertions(+), 2 deletions(-) diff --git a/src/corelib/tools/qlist.h b/src/corelib/tools/qlist.h index 6f0e0931d41..0d3b0a8da64 100644 --- a/src/corelib/tools/qlist.h +++ b/src/corelib/tools/qlist.h @@ -129,8 +129,10 @@ public: using rvalue_ref = T &&; #endif + class const_iterator; class iterator { friend class QList; + friend class const_iterator; T *i = nullptr; public: using difference_type = qsizetype; @@ -157,6 +159,12 @@ public: inline constexpr bool operator<=(iterator other) const { return i <= other.i; } inline constexpr bool operator>(iterator other) const { return i > other.i; } inline constexpr bool operator>=(iterator other) const { return i >= other.i; } + inline constexpr bool operator==(const_iterator o) const { return i == o.i; } + inline constexpr bool operator!=(const_iterator o) const { return i != o.i; } + inline constexpr bool operator<(const_iterator other) const { return i < other.i; } + inline constexpr bool operator<=(const_iterator other) const { return i <= other.i; } + inline constexpr bool operator>(const_iterator other) const { return i > other.i; } + inline constexpr bool operator>=(const_iterator other) const { return i >= other.i; } inline constexpr bool operator==(pointer p) const { return i == p; } inline constexpr bool operator!=(pointer p) const { return i != p; } inline iterator &operator++() { ++i; return *this; } @@ -180,6 +188,7 @@ public: class const_iterator { friend class QList; + friend class iterator; const T *i = nullptr; public: using difference_type = qsizetype; @@ -206,8 +215,12 @@ public: inline constexpr bool operator<=(const_iterator other) const { return i <= other.i; } inline constexpr bool operator>(const_iterator other) const { return i > other.i; } inline constexpr bool operator>=(const_iterator other) const { return i >= other.i; } - inline constexpr bool operator==(iterator o) const { return i == const_iterator(o).i; } - inline constexpr bool operator!=(iterator o) const { return i != const_iterator(o).i; } + inline constexpr bool operator==(iterator o) const { return i == o.i; } + inline constexpr bool operator!=(iterator o) const { return i != o.i; } + inline constexpr bool operator<(iterator other) const { return i < other.i; } + inline constexpr bool operator<=(iterator other) const { return i <= other.i; } + inline constexpr bool operator>(iterator other) const { return i > other.i; } + inline constexpr bool operator>=(iterator other) const { return i >= other.i; } inline constexpr bool operator==(pointer p) const { return i == p; } inline constexpr bool operator!=(pointer p) const { return i != p; } inline const_iterator &operator++() { ++i; return *this; }