Boost logo

Boost :

From: Jan Gaspar (jga_at_[hidden])
Date: 2003-07-29 10:43:27

Hi all!

The updated circular_buffer implementation can be found at the common

Please review it and remind me if I forgot to add some feature or fix

Comments to the update:
- Added exception handling. Please review this carefully, I'm not sure I
have done this properly.
- Changed implementation of the circular_buffer<>::resize() method.
- circular_buffer<>: insert(pos, n, item) works correctly now.
- Updated documentation (but the source code documentation stays
- Many other fixes.

ToDo list:
- Add T* circular_buffer<T>::data(); method.
- Improve source code documentation (add pre/post conditions).
- Maybe later the Mojo technique will be used. Maybe.

Regarding "unused space overhead"

I share the Nigel's opinion. The circular_buffer was designed with fixed
allocated memory. It will just complicate things. For example statements
regarding iterator invalidation won't be true any more. On contrary it
is quite easy to adapt std::list, std::slist or std::deque to achieve
this goal. You can just push_back() elements at the end of e.g.
std:list. In case the size of the container exceeds the desired capacity
you just remove the element from the front.

To Nigel:

Thank you very much for the documentation. I really like it. I changed
the implementation of the resize() method - it will remove elements from
the front if necessary. There was just one small bug in the Simple
int a = pop_back(); // a is 5
int b = pop_front(); // b is 3
should be like this:
int a = back(); // a is 5
int b = front(); // b is 3
And one misunderstanding in the Caveats: begin() == end() only if the
circular_buffer is empty (it cannot be valid for the full buffer except
one special case when the capacity == 0).



Jan Gaspar | jga_at_[hidden]
Whitestein Technologies |
Panenska 28 | SK-81103 Bratislava | Slovak Republic
Tel +421(2)5930-0735 | Fax +421(2)5443-5512

Boost list run by bdawes at, gregod at, cpdaniel at, john at