@@ -108,6 +108,8 @@ class CircularBuffer {
108108 const_iterator begin () const ;
109109 iterator end ();
110110 const_iterator end () const ;
111+ const_iterator cbegin () const noexcept ;
112+ const_iterator cend () const noexcept ;
111113
112114private:
113115 void _increment_bufferstate ();
@@ -127,14 +129,15 @@ class CircularBuffer {
127129 typedef std::random_access_iterator_tag iterator_type;
128130 typedef typename std::conditional<isConst, const value_type&, value_type&>::type reference;
129131 typedef typename std::conditional<isConst, const value_type*, value_type*>::type pointer;
130- typedef CircularBuffer* cbuf_pointer;
132+ typedef typename std::conditional<isConst, const CircularBuffer<value_type>*,
133+ CircularBuffer<value_type>*>::type cbuf_pointer;
131134
132135 cbuf_pointer _ptrToBuffer;
133136 size_type _offset;
134137 size_type _index;
135138 bool _reverse;
136139
137- bool _comparable (const BufferIterator& other){
140+ bool _comparable (const BufferIterator<isConst> & other) const {
138141 return (_ptrToBuffer == other._ptrToBuffer )&&(_reverse == other._reverse );
139142 }
140143
@@ -208,37 +211,37 @@ class CircularBuffer {
208211 return *this ;
209212 }
210213
211- bool operator ==(const BufferIterator& other){
214+ bool operator ==(const BufferIterator& other) const {
212215 if (!_comparable (other))
213216 return false ;
214217 return ((_index == other._index )&&(_offset == other._offset ));
215218 }
216219
217- bool operator !=(const BufferIterator& other){
220+ bool operator !=(const BufferIterator& other) const {
218221 if (!_comparable (other))
219222 return true ;
220223 return ((_index != other._index )||(_offset != other._offset ));
221224 }
222225
223- bool operator <(const BufferIterator& other){
226+ bool operator <(const BufferIterator& other) const {
224227 if (!_comparable (other))
225228 return false ;
226229 return ((_index + _offset)<(other._index +other._offset ));
227230 }
228231
229- bool operator >(const BufferIterator& other){
232+ bool operator >(const BufferIterator& other) const {
230233 if (!_comparable (other))
231234 return false ;
232235 return ((_index + _offset)>(other._index +other._offset ));
233236 }
234237
235- bool operator <=(const BufferIterator& other){
238+ bool operator <=(const BufferIterator& other) const {
236239 if (!_comparable (other))
237240 return false ;
238241 return ((_index + _offset)<=(other._index +other._offset ));
239242 }
240243
241- bool operator >=(const BufferIterator& other){
244+ bool operator >=(const BufferIterator& other) const {
242245 if (!_comparable (other))
243246 return false ;
244247 return ((_index + _offset)>=(other._index +other._offset ));
@@ -452,4 +455,27 @@ typename CircularBuffer<T>::const_iterator CircularBuffer<T>::end() const{
452455 return iter;
453456}
454457
458+ template <typename T>
459+ inline
460+ typename CircularBuffer<T>::const_iterator CircularBuffer<T>::cbegin() const noexcept {
461+ std::lock_guard<std::mutex> _lck (_mtx);
462+ const_iterator iter;
463+ iter._ptrToBuffer = this ;
464+ iter._offset = _tail;
465+ iter._index = 0 ;
466+ iter._reverse = false ;
467+ return iter;
468+ }
469+
470+ template <typename T>
471+ inline
472+ typename CircularBuffer<T>::const_iterator CircularBuffer<T>::cend() const noexcept {
473+ std::lock_guard<std::mutex> _lck (_mtx);
474+ const_iterator iter;
475+ iter._ptrToBuffer = this ;
476+ iter._offset = _tail;
477+ iter._index = _size;
478+ iter._reverse = false ;
479+ return iter;
480+ }
455481#endif /* CIRCULAR_BUFFER_H */
0 commit comments