From 63003a5cc7d81c437ffcd2063fd9e00636702e6b Mon Sep 17 00:00:00 2001 From: Arthur O'Dwyer Date: Thu, 17 Jun 2021 11:02:09 -0400 Subject: [PATCH] Stop using std::iterator (deprecated in C++17). --- src/google/protobuf/reflection.h | 9 +++++-- src/google/protobuf/repeated_field.h | 36 +++++++++++++++++++++------- 2 files changed, 35 insertions(+), 10 deletions(-) diff --git a/src/google/protobuf/reflection.h b/src/google/protobuf/reflection.h index af8eb00ef84ca..bb41fbaeb52ed 100644 --- a/src/google/protobuf/reflection.h +++ b/src/google/protobuf/reflection.h @@ -392,13 +392,18 @@ class PROTOBUF_EXPORT RepeatedFieldAccessor { // Implement (Mutable)RepeatedFieldRef::iterator template -class RepeatedFieldRefIterator - : public std::iterator { +class RepeatedFieldRefIterator { typedef typename RefTypeTraits::AccessorValueType AccessorValueType; typedef typename RefTypeTraits::IteratorValueType IteratorValueType; typedef typename RefTypeTraits::IteratorPointerType IteratorPointerType; public: + using iterator_category = std::forward_iterator_tag; + using value_type = T; + using pointer = T*; + using reference = T&; + using difference_type = std::ptrdiff_t; + // Constructor for non-message fields. RepeatedFieldRefIterator(const void* data, const RepeatedFieldAccessor* accessor, bool begin) diff --git a/src/google/protobuf/repeated_field.h b/src/google/protobuf/repeated_field.h index 3e3f601d7eb59..c8fe9333dee4d 100644 --- a/src/google/protobuf/repeated_field.h +++ b/src/google/protobuf/repeated_field.h @@ -2740,9 +2740,14 @@ RepeatedPtrField::pointer_end() const { namespace internal { // A back inserter for RepeatedField objects. template -class RepeatedFieldBackInsertIterator - : public std::iterator { +class RepeatedFieldBackInsertIterator { public: + using iterator_category = std::output_iterator_tag; + using value_type = T; + using pointer = void; + using reference = void; + using difference_type = std::ptrdiff_t; + explicit RepeatedFieldBackInsertIterator( RepeatedField* const mutable_field) : field_(mutable_field) {} @@ -2762,9 +2767,14 @@ class RepeatedFieldBackInsertIterator // A back inserter for RepeatedPtrField objects. template -class RepeatedPtrFieldBackInsertIterator - : public std::iterator { +class RepeatedPtrFieldBackInsertIterator { public: + using iterator_category = std::output_iterator_tag; + using value_type = T; + using pointer = void; + using reference = void; + using difference_type = std::ptrdiff_t; + RepeatedPtrFieldBackInsertIterator(RepeatedPtrField* const mutable_field) : field_(mutable_field) {} RepeatedPtrFieldBackInsertIterator& operator=(const T& value) { @@ -2793,9 +2803,14 @@ class RepeatedPtrFieldBackInsertIterator // A back inserter for RepeatedPtrFields that inserts by transferring ownership // of a pointer. template -class AllocatedRepeatedPtrFieldBackInsertIterator - : public std::iterator { +class AllocatedRepeatedPtrFieldBackInsertIterator { public: + using iterator_category = std::output_iterator_tag; + using value_type = T; + using pointer = void; + using reference = void; + using difference_type = std::ptrdiff_t; + explicit AllocatedRepeatedPtrFieldBackInsertIterator( RepeatedPtrField* const mutable_field) : field_(mutable_field) {} @@ -2817,9 +2832,14 @@ class AllocatedRepeatedPtrFieldBackInsertIterator // Almost identical to AllocatedRepeatedPtrFieldBackInsertIterator. This one // uses the UnsafeArenaAddAllocated instead. template -class UnsafeArenaAllocatedRepeatedPtrFieldBackInsertIterator - : public std::iterator { +class UnsafeArenaAllocatedRepeatedPtrFieldBackInsertIterator { public: + using iterator_category = std::output_iterator_tag; + using value_type = T; + using pointer = void; + using reference = void; + using difference_type = std::ptrdiff_t; + explicit UnsafeArenaAllocatedRepeatedPtrFieldBackInsertIterator( RepeatedPtrField* const mutable_field) : field_(mutable_field) {}