66#include < memory>
77#include < iterator>
88#include < type_traits>
9+ #include < algorithm>
910
1011template <typename T>
1112class CircularBuffer {
@@ -28,6 +29,20 @@ class CircularBuffer {
2829 explicit CircularBuffer (size_t size)
2930 :_buff{std::unique_ptr<T[]>(new T[size])}, _max_size{size}{}
3031
32+ CircularBuffer (const CircularBuffer& other)
33+ :_buff{std::unique_ptr<T[]>(new T[other.capacity ()])},
34+ _max_size{other.capacity ()}{
35+
36+ std::copy (other.data (), other.data () + _max_size, _buff.get ());
37+ }
38+
39+ CircularBuffer& operator =(const CircularBuffer& other){
40+ _buff = std::unique_ptr<T[]>(new T[other.capacity ()]);
41+ _max_size = other.capacity ();
42+ std::copy (other.data (), other.data () + _max_size, _buff.get ());
43+ return *this ;
44+ }
45+
3146 void push_back (const value_type& data);
3247 void pop_front ();
3348 reference front ();
@@ -40,6 +55,7 @@ class CircularBuffer {
4055 size_type capacity () const ;
4156 size_type size () const ;
4257 size_type buffer_size () const {return sizeof (T)*_max_size;};
58+ const_pointer data () const { return _buff.get (); }
4359
4460 const_reference operator [](size_type index) const ;
4561 reference operator [](size_type index);
@@ -56,6 +72,7 @@ class CircularBuffer {
5672 void _decrement_bufferstate ();
5773 mutable std::mutex _mtx;
5874 std::unique_ptr<T[]> _buff;
75+
5976 size_type _head = 0 ;
6077 size_type _tail = 0 ;
6178 size_type _size = 0 ;
0 commit comments