|
Boost Users : |
Subject: [Boost-users] circular_buffer iterators
From: Bosko Markovic (boskoma_at_[hidden])
Date: 2010-09-20 18:17:55
I have a simple use case for circular_buffer but I need a few advices.
There is one producer and one consumer which only inspects elements
and circular buffer will only be keeping history of last CB_SIZE
elements.
As far as I have understood there are two ways to access buffer
elements, using indexes and operator[] or using iterators.
I have chosen iterators.
Since adding elements to buffer can invalidate iterators what is the
proper way to check if they are still valid?
Is it comparing it to .end() and .begin()?
typedef boost::circular_buffer<data_type> CircularBuffer;
CircularBuffer cb(CB_SIZE);
CircularBuffer::iterator it = cb.begin();
...
if( it >= cb.begin() && it < cb.end() ){
cout << *it;
}
Regards,
BoskoM.
Boost-users list run by williamkempf at hotmail.com, kalb at libertysoft.com, bjorn.karlsson at readsoft.com, gregod at cs.rpi.edu, wekempf at cox.net