Boost logo

Boost :

From: Fernando Cacciola (fernando_cacciola_at_[hidden])
Date: 2002-09-27 09:14:49


"Anthony Williams" <anthwil_at_[hidden]> wrote in message
news:15764.24164.632000.110962_at_gargle.gargle.HOWL...
> Fernando Cacciola (hotmail) writes:
> > void push_back ( Polygon* poly, PolygonInterface* intf )
> > {
> > // Exceptions can be thrown below...
> > mpoly_.reserve( mpoly_.size() + 1);
> > interfaces_.reserve(interfaces_.size()+1);
> >
> > // But no exceptions can be thrown after this point.
> > mpoly_ .push_back(poly);
> > interfaces_.push_back(intf);
> > }
> >
> > w.r.t to the containers (assuming that the transfers are "basically
> > exception safe"),
> > does the technique of reserving storage always provide the basic
guarantee?
> > Is the problem generic enough?
> > Is the solution good enough?
>
> container.push_back can always throw an exception, if the copy constructor
of
> the element to push_back throws an exception.
>
> reserving first ensures that it won't throw due to running out of memory
in
> the container, but if the copy constructor can throw you will have to
pop_back
> the first container if the insert into the second throws an exception, so
> reserving first doesn't gain you much.
>
You're right.
I was not clear to state that the situation assumes that copy don't throw.
In my case, this is nearly always. See my response to David.

--
Fernando Cacciola

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