Skip to content

Commit

Permalink
Stop using std::iterator (deprecated in C++17).
Browse files Browse the repository at this point in the history
  • Loading branch information
Quuxplusone committed Jun 17, 2021
1 parent 5ab8239 commit 63003a5
Show file tree
Hide file tree
Showing 2 changed files with 35 additions and 10 deletions.
9 changes: 7 additions & 2 deletions src/google/protobuf/reflection.h
Original file line number Diff line number Diff line change
Expand Up @@ -392,13 +392,18 @@ class PROTOBUF_EXPORT RepeatedFieldAccessor {

// Implement (Mutable)RepeatedFieldRef::iterator
template <typename T>
class RepeatedFieldRefIterator
: public std::iterator<std::forward_iterator_tag, T> {
class RepeatedFieldRefIterator {
typedef typename RefTypeTraits<T>::AccessorValueType AccessorValueType;
typedef typename RefTypeTraits<T>::IteratorValueType IteratorValueType;
typedef typename RefTypeTraits<T>::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)
Expand Down
36 changes: 28 additions & 8 deletions src/google/protobuf/repeated_field.h
Original file line number Diff line number Diff line change
Expand Up @@ -2740,9 +2740,14 @@ RepeatedPtrField<Element>::pointer_end() const {
namespace internal {
// A back inserter for RepeatedField objects.
template <typename T>
class RepeatedFieldBackInsertIterator
: public std::iterator<std::output_iterator_tag, T> {
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<T>* const mutable_field)
: field_(mutable_field) {}
Expand All @@ -2762,9 +2767,14 @@ class RepeatedFieldBackInsertIterator

// A back inserter for RepeatedPtrField objects.
template <typename T>
class RepeatedPtrFieldBackInsertIterator
: public std::iterator<std::output_iterator_tag, T> {
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<T>* const mutable_field)
: field_(mutable_field) {}
RepeatedPtrFieldBackInsertIterator<T>& operator=(const T& value) {
Expand Down Expand Up @@ -2793,9 +2803,14 @@ class RepeatedPtrFieldBackInsertIterator
// A back inserter for RepeatedPtrFields that inserts by transferring ownership
// of a pointer.
template <typename T>
class AllocatedRepeatedPtrFieldBackInsertIterator
: public std::iterator<std::output_iterator_tag, T> {
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<T>* const mutable_field)
: field_(mutable_field) {}
Expand All @@ -2817,9 +2832,14 @@ class AllocatedRepeatedPtrFieldBackInsertIterator
// Almost identical to AllocatedRepeatedPtrFieldBackInsertIterator. This one
// uses the UnsafeArenaAddAllocated instead.
template <typename T>
class UnsafeArenaAllocatedRepeatedPtrFieldBackInsertIterator
: public std::iterator<std::output_iterator_tag, T> {
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<T>* const mutable_field)
: field_(mutable_field) {}
Expand Down

0 comments on commit 63003a5

Please sign in to comment.