|
Boost : |
From: Anthony Williams (anthwil_at_[hidden])
Date: 2002-08-09 02:50:33
From: Eric Friedman [mailto:ebf_at_[hidden]]
Sent: 08 August 2002 11:00
> >From David Abrahams:
>
> > From "Eric Friedman" <ebf_at_[hidden]>
> [snip]
> > > * Is it a major obstacle that Boost.Variant will not offer
> > > exception-safe assign
> > > or swap unless externally wrapped with the pimpl idiom? Should
> > > boost::fast_variant
> > > and boost::safe_variant be introduced to encapsulate yet allow
> > > choice in this issue?
> >
> > Wait!
> >
> > ***** There's nothing unsafe about the basic guarantee. *****
> >
> > The strong guarantee is not the holy grail of exception-safety, as
> many
> > people seem to think. It's just a useful behavior to distinguish.
> > There's no reason to resort to heroics just to achieve it.
>
> Well, having the strong guarantee does make variant's use much, much
> nicer.
>
> Now, in the process of removing the undefined behavior from swap and
> assign, I've had to reintroduce the notion of an empty
> variant (namely,
> an empty variant is one that has only "partly" made it
> through an assign
> or a swap).
I've just had a thought about how to implement the strong guarantee for
variant, at the expense of larger space requirements --- have *two* copies
of the internals, with a flag to indicate which is valid. Then, when
swapping or assigning, copy construct the value from the other variant into
the unused space, and destruct the original and switch the flag when
everything is done.
What do people think?
Anthony
Boost list run by bdawes at acm.org, gregod at cs.rpi.edu, cpdaniel at pacbell.net, john at johnmaddock.co.uk