Yes, that behaviour is expected. When the circular buffer is empty read_pos points to the end. After you put some items into it read_pos will point to the begining.
In your case I would recommend you not to rely on iterators as they may get invalidated. Instead, in you read operation rely on array_one() and after that clear the whole circular buffer.
Jan
----- Original Message ----
From: Daniele Barzotti
Hi Daniele,
The circular_buffer behaves like a sliding window - which is what you don't want apparently. If you want the behaviour you described have a look at array_one() and array_two() methods.
Hi, in my code I have this struct: template<typename T> struct TBuffer { boost::circular_buffer<T> data; iterator write_pos; iterator read_pos; TBuffer(){ write_pos = data.begin(); read_pos = data.begin(); }; }; Then, when I write to it *(when it's still empty!)*: size_type Write(const T* pData, size_type items) { ... buffer_.read_pos = buffer_.data.begin(); if (buffer_.read_pos == buffer_.data.begin()) cout << endl << "THIS IS TRUE.." << endl; std::copy(pData, pData + items, back_inserter(buffer_.data)); // Move the write cursor to the next position buffer_.write_pos = buffer_.data.begin() + items; if (buffer_.read_pos == buffer_.data.begin()) cout << endl << "THIS IS NO MORE TRUE!!!" << endl ... } After inserting the elements, the begin() iterator changes and is no more equal to the buffer_.read_pos iterator! Is it normal?! Regards, Daniele. _______________________________________________ Boost-users mailing list Boost-users@lists.boost.org http://lists.boost.org/mailman/listinfo.cgi/boost-users