summaryrefslogtreecommitdiffstats
path: root/src/corelib/tools/qlist.h
diff options
context:
space:
mode:
authorGiuseppe D'Angelo <giuseppe.dangelo@kdab.com>2021-10-11 12:02:27 +0200
committerGiuseppe D'Angelo <giuseppe.dangelo@kdab.com>2021-10-16 13:48:27 +0200
commit896f71d500ecd6e2ea3a32e80bbb4faa70fd2684 (patch)
tree7fed9a8b4133ea62f93dc0105dfe48e7cfc3ff57 /src/corelib/tools/qlist.h
parentb6cbd9c43afc7e005c1f78e1d0f700524930ed71 (diff)
QList: deprecate iterator<->pointer implicit conversions (3/3)
Follow-up of the previous commit: in case the implicit conversions between iterator and pointers are disabled, then reintroduce the non-template arithmetic operators for the iterator classes. Change-Id: I8cee60fe77ee3a47e189b4b53a08e39408f9db18 Reviewed-by: Qt CI Bot <qt_ci_bot@qt-project.org> Reviewed-by: Thiago Macieira <thiago.macieira@intel.com>
Diffstat (limited to 'src/corelib/tools/qlist.h')
-rw-r--r--src/corelib/tools/qlist.h16
1 files changed, 14 insertions, 2 deletions
diff --git a/src/corelib/tools/qlist.h b/src/corelib/tools/qlist.h
index fe8d36a9c7..0b33fc1d7b 100644
--- a/src/corelib/tools/qlist.h
+++ b/src/corelib/tools/qlist.h
@@ -187,7 +187,6 @@ public:
"the implicit conversion between a QList/QVector::iterator "
"and a raw pointer")
inline operator T*() const { return i; }
-#endif
template <typename Int> std::enable_if_t<std::is_integral_v<Int>, iterator>
&operator+=(Int j) { i+=j; return *this; }
@@ -199,6 +198,13 @@ public:
operator-(Int j) const { return iterator(i-j); }
template <typename Int> friend std::enable_if_t<std::is_integral_v<Int>, iterator>
operator+(Int j, iterator k) { return k + j; }
+#else
+ inline iterator &operator+=(qsizetype j) { i += j; return *this; }
+ inline iterator &operator-=(qsizetype j) { i -= j; return *this; }
+ inline iterator operator+(qsizetype j) const { return iterator(i + j); }
+ inline iterator operator-(qsizetype j) const { return iterator(i - j); }
+ friend inline iterator operator+(qsizetype j, iterator k) { return k + j; }
+#endif
};
class const_iterator {
@@ -254,7 +260,6 @@ public:
"the implicit conversion between a QList/QVector::const_iterator "
"and a raw pointer")
inline operator const T*() const { return i; }
-#endif
template <typename Int> std::enable_if_t<std::is_integral_v<Int>, const_iterator>
&operator+=(Int j) { i+=j; return *this; }
@@ -266,6 +271,13 @@ public:
operator-(Int j) const { return const_iterator(i-j); }
template <typename Int> friend std::enable_if_t<std::is_integral_v<Int>, const_iterator>
operator+(Int j, const_iterator k) { return k + j; }
+#else
+ inline const_iterator &operator+=(qsizetype j) { i += j; return *this; }
+ inline const_iterator &operator-=(qsizetype j) { i -= j; return *this; }
+ inline const_iterator operator+(qsizetype j) const { return const_iterator(i + j); }
+ inline const_iterator operator-(qsizetype j) const { return const_iterator(i - j); }
+ friend inline const_iterator operator+(qsizetype j, const_iterator k) { return k + j; }
+#endif
};
using Iterator = iterator;
using ConstIterator = const_iterator;