Skip to content

Commit b551b45

Browse files
committed
chore: fix two usages of std::iterator (deprecated)
This trait has been deprecated in C++17, with users instructed to migrate to defining each associated type when implementing an iterator. This quiets the _GLIBCXX17_DEPRECATED warnings when compiling the project on a sufficiently new gcc. This follows on from previous efforts in 8b8a96d (ceph#45198). References: ceph#45198 References: https://www.fluentcpp.com/2018/05/08/std-iterator-deprecated/ Signed-off-by: Paul Stemmet <[email protected]>
1 parent 20b1021 commit b551b45

File tree

2 files changed

+18
-9
lines changed

2 files changed

+18
-9
lines changed

src/include/rangeset.h

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -55,9 +55,14 @@ struct _rangeset_base {
5555

5656

5757
template <class T>
58-
class rangeset_iterator :
59-
public std::iterator<std::input_iterator_tag, T>
58+
class rangeset_iterator
6059
{
60+
using iterator_category = std::input_iterator_tag;
61+
using value_type = T;
62+
using difference_type = std::ptrdiff_t;
63+
using pointer = T*;
64+
using reference = T&;
65+
6166
//typedef typename map<T,T>::iterator mapit;
6267

6368
map<T,T> ranges;

src/msg/async/dpdk/circular_buffer.h

Lines changed: 11 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -89,8 +89,12 @@ class circular_buffer {
8989
size_t mask(size_t idx) const;
9090

9191
template<typename CB, typename ValueType>
92-
struct cbiterator : std::iterator<std::random_access_iterator_tag, ValueType> {
93-
typedef std::iterator<std::random_access_iterator_tag, ValueType> super_t;
92+
struct cbiterator {
93+
using iterator_category = std::random_access_iterator_tag;
94+
using value_type = ValueType;
95+
using difference_type = std::ptrdiff_t;
96+
using pointer = ValueType*;
97+
using reference = ValueType&;
9498

9599
ValueType& operator*() const { return cb->_impl.storage[cb->mask(idx)]; }
96100
ValueType* operator->() const { return &cb->_impl.storage[cb->mask(idx)]; }
@@ -116,17 +120,17 @@ class circular_buffer {
116120
idx--;
117121
return v;
118122
}
119-
cbiterator<CB, ValueType> operator+(typename super_t::difference_type n) const {
123+
cbiterator<CB, ValueType> operator+(difference_type n) const {
120124
return cbiterator<CB, ValueType>(cb, idx + n);
121125
}
122-
cbiterator<CB, ValueType> operator-(typename super_t::difference_type n) const {
126+
cbiterator<CB, ValueType> operator-(difference_type n) const {
123127
return cbiterator<CB, ValueType>(cb, idx - n);
124128
}
125-
cbiterator<CB, ValueType>& operator+=(typename super_t::difference_type n) {
129+
cbiterator<CB, ValueType>& operator+=(difference_type n) {
126130
idx += n;
127131
return *this;
128132
}
129-
cbiterator<CB, ValueType>& operator-=(typename super_t::difference_type n) {
133+
cbiterator<CB, ValueType>& operator-=(difference_type n) {
130134
idx -= n;
131135
return *this;
132136
}
@@ -148,7 +152,7 @@ class circular_buffer {
148152
bool operator<=(const cbiterator<CB, ValueType>& rhs) const {
149153
return idx <= rhs.idx;
150154
}
151-
typename super_t::difference_type operator-(const cbiterator<CB, ValueType>& rhs) const {
155+
difference_type operator-(const cbiterator<CB, ValueType>& rhs) const {
152156
return idx - rhs.idx;
153157
}
154158
private:

0 commit comments

Comments
 (0)