|
Boost : |
From: Nigel Stewart (nigels_at_[hidden])
Date: 2003-06-06 20:43:51
Hi Jan,
>>1. How about push_front()? (in std::list style)
>> And pop_front()?
>
> Imagine you have a cyclic buffer which is full. When you add (push_back or
> insert) a new item into this buffer the first (oldest) item will be removed.
Ahh, I see that your conceptualisation is based on
age, or order of insertion. Mine was more circular-
list oriented: Adding to the front would overwite the
backmost item if the buffer is already full. Being a
circle, the buffer slides either left or right, as
needed.
In the case that the buffer is full and items are
alternatively added to the front and back, nothing
much happens. Admittedly, a special case.
Perhaps our concepts are incompatible. Looking at
Knuth's coverage of Circular Lists, insertion
is allowed at both ends. Knuth also mentions
FIFO (first-in first-out) lists as being
sometimes called "circular stores". There
seems to be no particular implication of circular
meaning one way or the other, based on Knuth.
So the issue here seems to be whether a cyclic_buffer
should be circular-list-like or FIFO-like. Given
that there is already a queue container adapter,
perhaps it's worth listing some applications
of cyclic_buffer that depend on either
circular-list-like or FIFO-like semantics.
Could a queue adaptor using a cyclic_buffer instead
of a deque provide the explicitly FIFO-like mode of
operation? (While leaving cyclic_buffer to be
circular-list-like?)
>> Semantics of resize should probably follow vector:
>> 1. The capacity is implicitly adjusted to fit the
>> requested size.
http://www.sgi.com/tech/stl/Vector.html
vector::resize
Inserts or erases elements at the end such that
the size becomes n.
(I think a developer may find it surprising for a
cyclic_buffer::resize to be clamped to the capacity.)
>> 2. Items are lost from the end if the container is
>> to be shrunk.
>
> Are you sure you want to lost the items at the end ? Not at the beginning (the
In the FIFO-view, the leftmost/oldest should be removed, agreed.
In the circular-list view, it is not so obvious - so follow
vector and erase the rightmost... :-)
Have a nice weekend, I'm off to the country side...
Nigel
Boost list run by bdawes at acm.org, gregod at cs.rpi.edu, cpdaniel at pacbell.net, john at johnmaddock.co.uk