Boost logo

Boost :

From: David Abrahams (dave_at_[hidden])
Date: 2002-09-27 09:30:14


----- Original Message -----
From: "Fernando Cacciola" <fernando_cacciola_at_[hidden]>

> Right.
> I forgot to mention that the sort of sequences that I was considering are
of
> objects which themselves provide exception-safe copy construction.

Don't say "exception-safe". It's an imprecise term. Any type which
documents the exception behavior of its copy constructor and fulfills it is
"exception-safe".

Every type which provides the basic guarantee for its copy constructor also
provides the strong guarantee (unless it somehow mutates its argument or
touches global state), so your statement above has little meaning.

Maybe you just meant "objects which don't throw from their copy
constructors". Pretty limiting.

> In
> practice, this means that the sequence is of managed pointers (i.e.
> shared_ptr<>) which don't throw during copy construction.

> > > w.r.t to the containers (assuming that the transfers are "basically
> > > exception safe"),
> >
> > ??? What does this mean?
> >
> I meant: assume that the element's copy-ctor don't throw. I'm so used to
> work with such guarantees that I forgot to be explicit about it.
> (I said 'transfer' instead of 'copy' because I have move-semantics in my
> head :-)

I understand. However, this sort of assumption is a poor one for generic
components.

> > > does the technique of reserving storage always provide the basic
> > guarantee?
> >
> > Clearly not.
> >
> How about in the case where copy-ctor/move don't throw.

Depending on how much of the internal state is visible from the outside, it
might even give the strong guarantee.

> In some applications, like mine, this is almost always the case.
> If an object can throw when copied, I use handle/body and 'clone()' so
that
> copy/assignment (of the handle) never throws, and if I need a 'real' copy
I
> always write:
> handle new_object = old_object->clone(); // can throw.
>
> So I'm usually left with only contaier-reallocations to worry about.

That's generally expensive, but whatever floats your boat...

-----------------------------------------------------------
           David Abrahams * Boost Consulting
dave_at_[hidden] * http://www.boost-consulting.com


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