Boost logo

Boost :

From: David Tapia (dat15_at_[hidden])
Date: 2008-04-25 10:34:51


I've started using the circular_buffer container and I am a little
confused by
its behavior with regard to start and stop positions for iterators.

As
implemented, the
iterator::begin() call always returns the fixed position at element 0 and the
iterator::end() call always returns the fixed position past the last element of
the circular_buffer. A more intuitive approach might appear to be that
the iterator::begin() should return the oldest element in the buffer and
iterator::end should return the newest (most recently pushed) element.
Thus, in the case where the circular_buffer were NOT full, begin() would return
the
position at element 0. After the circular buffer became full, begin()
should return the position of the
next insertion point, again the oldest element in the buffer.

When I think of the context of a circular buffer,
it seems that absolute positions (element 1, 2, 3, and so on) have little
meaning.

Under this behavior, existing iterators would then be
invalidated
whenever a new element is pushed into the buffer, as is the case for other STL
containers. No confusing hard/soft invalidation of iterators that exists
now.

David


Boost list run by bdawes at acm.org, gregod at cs.rpi.edu, cpdaniel at pacbell.net, john at johnmaddock.co.uk