diff options
author | Marc Mutz <marc.mutz@qt.io> | 2024-01-23 18:28:25 +0100 |
---|---|---|
committer | Marc Mutz <marc.mutz@qt.io> | 2024-01-31 20:18:47 +0000 |
commit | 900d4bd29f30effbb5dbb0efa96886af03839a15 (patch) | |
tree | 3a949279799219eeb8f366b4f3f31cee736dd3f2 | |
parent | 324fe120ba405f0eeca0b1a00cc5aee0ea99f76f (diff) |
Add QtPrivate::ArrowProxy
... use it in QKeyValueIterator.
This is somewhat simpler than the old QKeyValueIterator::pointer.
I don't think the pointer::operator*() could have ever worked, because
it returns value_type&, but is const.
That leaves the defaulted copy and move SMFs as a difference (ArrowProxy
is using aggregate initialization, so doesn't need any), and the fact
that operator->() is const.
Change-Id: I80b9c5f696de6ae30f3939166b205b9213eac57e
Reviewed-by: Thiago Macieira <thiago.macieira@intel.com>
-rw-r--r-- | src/corelib/tools/qcontainertools_impl.h | 7 | ||||
-rw-r--r-- | src/corelib/tools/qiterator.h | 21 |
2 files changed, 10 insertions, 18 deletions
diff --git a/src/corelib/tools/qcontainertools_impl.h b/src/corelib/tools/qcontainertools_impl.h index d66705ef4d..ef73a2a69f 100644 --- a/src/corelib/tools/qcontainertools_impl.h +++ b/src/corelib/tools/qcontainertools_impl.h @@ -254,6 +254,13 @@ void q_relocate_overlap_n(T *first, N n, T *d_first) } } +template <typename T> +struct ArrowProxy +{ + T t; + T *operator->() noexcept { return &t; } +}; + template <typename Iterator> using IfIsInputIterator = typename std::enable_if< std::is_convertible<typename std::iterator_traits<Iterator>::iterator_category, std::input_iterator_tag>::value, diff --git a/src/corelib/tools/qiterator.h b/src/corelib/tools/qiterator.h index ab3d71f760..8a2b493ef4 100644 --- a/src/corelib/tools/qiterator.h +++ b/src/corelib/tools/qiterator.h @@ -5,6 +5,7 @@ #define QITERATOR_H #include <QtCore/qglobal.h> +#include <QtCore/qcontainertools_impl.h> QT_BEGIN_NAMESPACE @@ -253,26 +254,10 @@ public: return std::pair<Key, T>(i.key(), i.value()); } - struct pointer - { - pointer(value_type &&r_) : r(std::move(r_)) { } - - pointer() = default; - pointer(const pointer &other) = default; - pointer(pointer &&other) = default; - pointer &operator=(const pointer &other) = default; - pointer &operator=(pointer &&other) = default; - - value_type &operator*() const { return r; } - - value_type r; - const value_type *operator->() const { - return &r; - } - }; + using pointer = QtPrivate::ArrowProxy<value_type>; pointer operator->() const { - return pointer(std::pair<Key, T>(i.key(), i.value())); + return pointer{std::pair<Key, T>(i.key(), i.value())}; } friend bool operator==(QKeyValueIterator lhs, QKeyValueIterator rhs) noexcept { return lhs.i == rhs.i; } |