From d88c8d5d4b7c458b3c0f894ad46700aa4fca7b39 Mon Sep 17 00:00:00 2001 From: Kent Ross Date: Thu, 4 Nov 2021 07:16:02 -0700 Subject: [PATCH] Implement unambiguous comparisons for RepeatedPtrIterator in C++20 (#9139) --- src/google/protobuf/repeated_ptr_field.h | 20 ++++++++++++++------ 1 file changed, 14 insertions(+), 6 deletions(-) diff --git a/src/google/protobuf/repeated_ptr_field.h b/src/google/protobuf/repeated_ptr_field.h index 7d635e3bb5..3c813a9f0a 100644 --- a/src/google/protobuf/repeated_ptr_field.h +++ b/src/google/protobuf/repeated_ptr_field.h @@ -1617,6 +1617,8 @@ class RepeatedPtrIterator { using iterator = RepeatedPtrIterator; using iterator_category = std::random_access_iterator_tag; using value_type = typename std::remove_const::type; + using const_iterator = RepeatedPtrIterator; + using nonconst_iterator = RepeatedPtrIterator; using difference_type = std::ptrdiff_t; using pointer = Element*; using reference = Element&; @@ -1652,14 +1654,20 @@ class RepeatedPtrIterator { iterator operator--(int) { return iterator(it_--); } // equality_comparable - bool operator==(const iterator& x) const { return it_ == x.it_; } - bool operator!=(const iterator& x) const { return it_ != x.it_; } + bool operator==(const nonconst_iterator& x) const { return it_ == x.it_; } + bool operator==(const const_iterator& x) const { return it_ == x.it_; } + bool operator!=(const nonconst_iterator& x) const { return it_ != x.it_; } + bool operator!=(const const_iterator& x) const { return it_ != x.it_; } // less_than_comparable - bool operator<(const iterator& x) const { return it_ < x.it_; } - bool operator<=(const iterator& x) const { return it_ <= x.it_; } - bool operator>(const iterator& x) const { return it_ > x.it_; } - bool operator>=(const iterator& x) const { return it_ >= x.it_; } + bool operator<(const nonconst_iterator& x) const { return it_ < x.it_; } + bool operator<(const const_iterator& x) const { return it_ < x.it_; } + bool operator<=(const nonconst_iterator& x) const { return it_ <= x.it_; } + bool operator<=(const const_iterator& x) const { return it_ <= x.it_; } + bool operator>(const nonconst_iterator& x) const { return it_ > x.it_; } + bool operator>(const const_iterator& x) const { return it_ > x.it_; } + bool operator>=(const nonconst_iterator& x) const { return it_ >= x.it_; } + bool operator>=(const const_iterator& x) const { return it_ >= x.it_; } // addable, subtractable iterator& operator+=(difference_type d) {