From: Dean Michael Berris (mikhailberis_at_[hidden])
Date: 2008-05-15 10:19:25
On Thu, May 15, 2008 at 9:29 PM, Jan Gaspar <jano_gaspar_at_[hidden]> wrote:
> OK, will see what can I do with the 1.35.1. release.
Great, thanks. :)
> Btw on the 4th line I don't see a problem to explicitly set the capacity like this:
> circular_buffer<char> buffer(0); // nothing will be allocated
True, I understand. Actually, the problem is also a little more subtle
than just that. Consider also the case:
map<int, circular_buffer<int> > buffers;
circular_buffer<int> buffer(buffers[rand() % 10]);
In this case doing buffers[rand() % 10] will cause an implicit
creation of a default constructed circular_buffer<int>. There are a
lot of cases (especially in STL containers) that when
circular_buffer<...>'s can be contained, the implicit requirement of
default constructability of items be maintained.
It is a subtle issue, and is really hard to trace (i.e., it took me a
while to figure out why suddenly when I decided to use a
circular_buffer<...>, it kept throwing an std::bad_alloc). I think
instead of (mis)behaving in the case of the default constructed
buffer, there should be some considerably sane default. I personally
chose 0, where adding items to the buffer would most probably fail
afterwards, which can be expected behavior.
It could also be another number, like how the STL vector chooses a
default number of elements and grows accordingly -- but in this case
of the circular buffer, it may be hard to determine that default. We
can make it degenerate to a 1 element circular buffer where there's
really only one value ever in the buffer, but I think that is also
I hope this helps!
-- Dean Michael C. Berris Software Engineer, Friendster, Inc. [http://blog.cplusplus-soup.com] [mikhailberis_at_[hidden]] [+63 928 7291459] [+1 408 4049523]
Boost list run by bdawes at acm.org, gregod at cs.rpi.edu, cpdaniel at pacbell.net, john at johnmaddock.co.uk