Commit 2949ebd8 authored by Rodrigo Hernandez's avatar Rodrigo Hernandez

Updating Iterators to be compatible with C++17

The std::iterator class is being deprecated on MSVC++,
and currently if the compilation flag /std:c++latest
is used a warning is issued in this regard if any
iterators use the class as a base class.

If an external source file being compiled includes
the repeated_field.h header, the iterator clases
RepeatedPtrIterator and RepeatedPtrOverPtrsIterator
trigger the warning.

This change solves the warning and should avoid it in
the future when the default is to remove the class.

Using typedef instead of the modern "using x = y;"
to make it also work on VS2015.
parent 3389bd96
...@@ -2205,23 +2205,14 @@ namespace internal { ...@@ -2205,23 +2205,14 @@ namespace internal {
// This code based on net/proto/proto-array-internal.h by Jeffrey Yasskin // This code based on net/proto/proto-array-internal.h by Jeffrey Yasskin
// (jyasskin@google.com). // (jyasskin@google.com).
template<typename Element> template<typename Element>
class RepeatedPtrIterator class RepeatedPtrIterator {
: public std::iterator<
std::random_access_iterator_tag, Element> {
public: public:
typedef RepeatedPtrIterator<Element> iterator; typedef RepeatedPtrIterator<Element> iterator;
typedef std::iterator< typedef std::random_access_iterator_tag iterator_category;
std::random_access_iterator_tag, Element> superclass; typedef Element value_type;
typedef std::ptrdiff_t difference_type;
// Shadow the value_type in std::iterator<> because const_iterator::value_type typedef Element* pointer;
// needs to be T, not const T. typedef Element& reference;
typedef typename std::remove_const<Element>::type value_type;
// Let the compiler know that these are type names, so we don't have to
// write "typename" in front of them everywhere.
typedef typename superclass::reference reference;
typedef typename superclass::pointer pointer;
typedef typename superclass::difference_type difference_type;
RepeatedPtrIterator() : it_(NULL) {} RepeatedPtrIterator() : it_(NULL) {}
explicit RepeatedPtrIterator(void* const* it) : it_(it) {} explicit RepeatedPtrIterator(void* const* it) : it_(it) {}
...@@ -2301,21 +2292,14 @@ class RepeatedPtrIterator ...@@ -2301,21 +2292,14 @@ class RepeatedPtrIterator
// referenced by the iterator. It should either be "void *" for a mutable // referenced by the iterator. It should either be "void *" for a mutable
// iterator, or "const void* const" for a constant iterator. // iterator, or "const void* const" for a constant iterator.
template <typename Element, typename VoidPtr> template <typename Element, typename VoidPtr>
class RepeatedPtrOverPtrsIterator class RepeatedPtrOverPtrsIterator {
: public std::iterator<std::random_access_iterator_tag, Element> {
public: public:
typedef RepeatedPtrOverPtrsIterator<Element, VoidPtr> iterator; typedef RepeatedPtrOverPtrsIterator<Element, VoidPtr> iterator;
typedef std::iterator<std::random_access_iterator_tag, Element> superclass; typedef std::random_access_iterator_tag iterator_category;
typedef Element value_type;
// Shadow the value_type in std::iterator<> because const_iterator::value_type typedef std::ptrdiff_t difference_type;
// needs to be T, not const T. typedef Element* pointer;
typedef typename std::remove_const<Element>::type value_type; typedef Element& reference;
// Let the compiler know that these are type names, so we don't have to
// write "typename" in front of them everywhere.
typedef typename superclass::reference reference;
typedef typename superclass::pointer pointer;
typedef typename superclass::difference_type difference_type;
RepeatedPtrOverPtrsIterator() : it_(NULL) {} RepeatedPtrOverPtrsIterator() : it_(NULL) {}
explicit RepeatedPtrOverPtrsIterator(VoidPtr* it) : it_(it) {} explicit RepeatedPtrOverPtrsIterator(VoidPtr* it) : it_(it) {}
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment