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>
bb10
Marc Mutz 2024-01-23 18:28:25 +01:00
parent 324fe120ba
commit 900d4bd29f
2 changed files with 10 additions and 18 deletions

View File

@ -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,

View File

@ -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; }