I like Boost Templated Circular Buffer Container, but how to get when it was filled 100%?
#include <boost/circular_buffer.hpp>
int main() {
// Create a circular buffer with a capacity for 3 integers.
boost::circular_buffer<int> cb(3);
// Insert some elements into the buffer.
cb.push_back(1);
cb.push_back(2);
cb.push_back(3);
// Here I want some function to be called (for example one that would cout all buffer contents)
int a = cb[0]; // a == 1
int b = cb[1]; // b == 2
int c = cb[2]; // c == 3
return 0;
}
So how to listen for such event in boost::circular_buffer and for example cout all buffer contents?
You can wrap the
circular_bufferinstance into its own class and implement event handling on top of it.If code outside of
MyCircularBufferneeds to be notified of the event, you can implement some variant of the Observer pattern, use Boost.Function or use some other callback mechanism.