Boost logo

Boost :

From: Jan Gaspar (jga_at_[hidden])
Date: 2003-07-22 13:34:37


Hi Nigel,

It cannot be done as you propose. Please check the archive.
It can be done like this:
cb.rinsert(cb.begin(), 2); // rinsert
        cb.push_front(2); // this is equivalent

It will be documented and I think not everything can be driven by "the principle
of least surprise".

Jan

Nigel Stewart wrote:

> Jan,
>
> I have closely proof-read the HTML document
> and intend to respond with a new draft shortly.
>
> There is one point I would like to raise for
> discussion:
>
> > Inserting at the beginning or "close to the beginning"
> > of the circular_buffer is another trap.
> >
> > boost::circular_buffer<int> cb(5, 1);
> > cb.insert(cb.begin(), 2); // nothing will be inserted
>
> By way of "the principle of least surprise" I think that
> insert should _always_ succeed. Inserting to the front
> should always overwrite the back, and vice versa. The
> concept of "old" and "new" serves only to confuse the
> issue IMHO - there is a front and back, (or left and right)
> but the circular buffer should not assume that the
> front-most are the oldest or newest. (The circular buffer
> can be _used_ as a FIFO, but does not _enforce_ FIFO,
> since it allows both push and pop from each end)
>
> The following should be exactly equivalent:
> cb.insert(cb.begin(), 2);
> cb.push_front(2);
>
> We may have discussed this already, I havn't checked the
> archives, but it appears to me as hazardous.
>
> As a proposed semantic:
>
> Insertion to the front or back will always be
> equivalent to a corresponding sequence of
> push_front or push_back.
>
> What are the semantics of inserting a huge sequence to
> the middle of a circular buffer? What exactly gets kept?
>
> Nigel
>
> _______________________________________________
> Unsubscribe & other changes: http://lists.boost.org/mailman/listinfo.cgi/boost

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

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