Boost logo

Boost :

From: Fernando Cacciola (fcacciola_at_[hidden])
Date: 2002-08-07 16:02:53


----- Original Message -----
From: "Eric Friedman" <ebf_at_[hidden]>
To: "'David Abrahams'" <dave_at_[hidden]>; <boost_at_[hidden]>
Sent: Wednesday, August 07, 2002 5:15 PM
Subject: RE: [boost] Re: Mini-review request: aligned_storage.hpp

> [snipped]
> Three questions come to my mind:
>
> * Are there any implementations that do not behave as desired under
> this undefined
> behavior? (Or more fundamentally, what is the reason for the
> standard's behavior
> on this issue?)
>
Unless utterly neccesary, we must not make any assumptions about
implementations behaviour.

> * 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?
>
Personally, I would be more than happy with a variant which is not any more
exception-safe than the objects it wraps.

> * Any ideas out there as to how to make variant::operator= and
> variant::swap "as safe
> as possible," yet still efficient, even if we can't guarantee strong
> exception-safety?
>
My personal preference in this area is to do nothing...

Consider:

T a(val0) ;
T b(val1) ;

b = a ;
// if assignment above throws, how much inconsistent is 'b' left is totally
undefined.

Therefore, with:

variant<int,T> va (a);
variant<int,T> vb(b);
va = vb ;

Struggling to make the above assignment exception safe is too dificult -if
at all possible-,
while doing nothing at all won't ever be worse than the case of using T
directly.

In any event, if I need to put such touchy objects in a variant, I can
always wrap the object, with a exception-safe but specific assignment
mechanism, and put the proxy in the variant instead.

Fernando Cacciola
Sierra s.r.l.
fcacciola_at_[hidden]
www.gosierra.com


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