summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorGiuseppe D'Angelo <giuseppe.dangelo@kdab.com>2021-10-13 01:50:45 +0200
committerGiuseppe D'Angelo <giuseppe.dangelo@kdab.com>2021-10-15 10:19:17 +0200
commitad972af8fb771129b6db69dbb13855021d14e2fe (patch)
tree67f6df15eeaf053a7cbc061e6a28f1a29667ba91
parentbe3df082bc965bf1206c6694c6bc0e2245fbce91 (diff)
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 <thiago.macieira@intel.com>
-rw-r--r--src/corelib/tools/qlist.h17
1 files changed, 15 insertions, 2 deletions
diff --git a/src/corelib/tools/qlist.h b/src/corelib/tools/qlist.h
index 6f0e0931d4..0d3b0a8da6 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<T>;
+ 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<T>;
+ 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; }