Algorithm: Do not derive from std::iterator

MSVC throws warnings that this is deprecated.

Change-Id: I010c54a923f395a04a4c84cfcd01848a42752e2e
Reviewed-by: hjk <hjk@qt.io>
This commit is contained in:
Eike Ziller
2020-07-13 13:50:56 +02:00
parent a066bfd170
commit 6ac8bf2f0a

View File

@@ -566,52 +566,56 @@ namespace {
// SetInsertIterator, straight from the standard for insert_iterator // SetInsertIterator, straight from the standard for insert_iterator
// just without the additional parameter to insert // just without the additional parameter to insert
template <class Container> template<class Container>
class SetInsertIterator : class SetInsertIterator
public std::iterator<std::output_iterator_tag,void,void,void,void>
{ {
protected: protected:
Container *container; Container *container;
public: public:
using container_type = Container; using iterator_category = std::output_iterator_tag;
explicit SetInsertIterator (Container &x) using container_type = Container;
: container(&x) {} explicit SetInsertIterator(Container &x)
SetInsertIterator<Container> &operator=(const typename Container::value_type &value) : container(&x)
{ container->insert(value); return *this; } {}
SetInsertIterator<Container> &operator= (typename Container::value_type &&value) SetInsertIterator<Container> &operator=(const typename Container::value_type &value)
{ container->insert(std::move(value)); return *this; } {
SetInsertIterator<Container >&operator*() container->insert(value);
{ return *this; } return *this;
SetInsertIterator<Container> &operator++() }
{ return *this; } SetInsertIterator<Container> &operator=(typename Container::value_type &&value)
SetInsertIterator<Container> operator++(int) {
{ return *this; } container->insert(std::move(value));
return *this;
}
SetInsertIterator<Container> &operator*() { return *this; }
SetInsertIterator<Container> &operator++() { return *this; }
SetInsertIterator<Container> operator++(int) { return *this; }
}; };
// for QMap / QHash, inserting a std::pair / QPair // for QMap / QHash, inserting a std::pair / QPair
template <class Container> template<class Container>
class MapInsertIterator : class MapInsertIterator
public std::iterator<std::output_iterator_tag,void,void,void,void> {
{ protected:
protected:
Container *container; Container *container;
public: public:
using iterator_category = std::output_iterator_tag;
using container_type = Container; using container_type = Container;
explicit MapInsertIterator (Container &x) explicit MapInsertIterator(Container &x)
: container(&x) {} : container(&x)
MapInsertIterator<Container> &operator=(const std::pair<const typename Container::key_type, typename Container::mapped_type> &value) {}
{ container->insert(value.first, value.second); return *this; } MapInsertIterator<Container> &operator=(
MapInsertIterator<Container> &operator=(const QPair<typename Container::key_type, typename Container::mapped_type> &value) const std::pair<const typename Container::key_type, typename Container::mapped_type> &value)
{ container->insert(value.first, value.second); return *this; } { container->insert(value.first, value.second); return *this; }
MapInsertIterator<Container >&operator*() MapInsertIterator<Container> &operator=(
{ return *this; } const QPair<typename Container::key_type, typename Container::mapped_type> &value)
MapInsertIterator<Container> &operator++() { container->insert(value.first, value.second); return *this; }
{ return *this; } MapInsertIterator<Container> &operator*() { return *this; }
MapInsertIterator<Container> operator++(int) MapInsertIterator<Container> &operator++() { return *this; }
{ return *this; } MapInsertIterator<Container> operator++(int) { return *this; }
}; };
// inserter helper function, returns a std::back_inserter for most containers // inserter helper function, returns a std::back_inserter for most containers
// and is overloaded for QSet<> and other containers without push_back, returning custom inserters // and is overloaded for QSet<> and other containers without push_back, returning custom inserters