5
5
#include < mutex>
6
6
#include < memory>
7
7
#include < iterator>
8
- #include < type_traits>
9
8
#include < algorithm>
10
9
#include < utility>
11
10
@@ -20,7 +19,7 @@ class CircularBuffer {
20
19
typedef const T& const_reference;
21
20
typedef size_t size_type;
22
21
typedef ptrdiff_t difference_type;
23
- template <bool isConst> struct BufferIterator ;
22
+ template <bool isConst> struct BufferIterator ;
24
23
25
24
26
25
public:
@@ -80,7 +79,7 @@ class CircularBuffer {
80
79
}
81
80
return *this ;
82
81
}
83
-
82
+
84
83
void push_back (const value_type& data);
85
84
void push_back (value_type&& data) noexcept ;
86
85
void pop_front ();
@@ -116,31 +115,33 @@ class CircularBuffer {
116
115
void _decrement_bufferstate ();
117
116
mutable std::mutex _mtx;
118
117
std::unique_ptr<value_type[]> _buff;
119
-
120
118
size_type _head = 0 ;
121
119
size_type _tail = 0 ;
122
120
size_type _size = 0 ;
123
121
size_type _max_size = 0 ;
124
-
122
+
125
123
template <bool isConst = false >
126
124
struct BufferIterator {
127
125
public:
128
-
129
- typedef std::random_access_iterator_tag iterator_type;
126
+ friend class CircularBuffer <T>;
127
+ typedef std::forward_iterator_tag iterator_category;
128
+ typedef ptrdiff_t difference_type;
129
+ typedef T value_type;
130
130
typedef typename std::conditional<isConst, const value_type&, value_type&>::type reference;
131
131
typedef typename std::conditional<isConst, const value_type*, value_type*>::type pointer;
132
132
typedef typename std::conditional<isConst, const CircularBuffer<value_type>*,
133
133
CircularBuffer<value_type>*>::type cbuf_pointer;
134
-
134
+ private:
135
135
cbuf_pointer _ptrToBuffer;
136
136
size_type _offset;
137
137
size_type _index;
138
138
bool _reverse;
139
-
139
+
140
140
bool _comparable (const BufferIterator<isConst>& other) const {
141
141
return (_ptrToBuffer == other._ptrToBuffer )&&(_reverse == other._reverse );
142
142
}
143
143
144
+ public:
144
145
BufferIterator ()
145
146
:_ptrToBuffer{nullptr }, _offset{0 }, _index{0 }, _reverse{false }{}
146
147
@@ -246,7 +247,6 @@ class CircularBuffer {
246
247
return false ;
247
248
return ((_index + _offset)>=(other._index +other._offset ));
248
249
}
249
-
250
250
};
251
251
};
252
252
0 commit comments