|
Boost : |
From: Douglas Gregor (gregod_at_[hidden])
Date: 2002-08-09 17:28:51
On Friday 09 August 2002 04:26 pm, Fernando Cacciola wrote:
> If the user-defined copy-ctor throws, AND variant does NOTHING, not even
> resetting 'v' to empty before the assignment, the variant lvalue will be
> left undefined. Not empty, just plain inconsistent.
> This sounds terrifying, but it isn't, because a user defined type whose
> copy-constructor throws will most likely define an assignment operator
> which also throws, so the situation won't be any worse than working with
> this broken-type (as David called it) directly.
I wouldn't call that a broken type. Most classes allocate memory in their
constructor. I think I broken type is one that, for instance, doesn't meet
even the basic guarantee for an assignment operator.
> IMO, since variant<> is essentially a compound type, exception-free
> assignment should be guaranteed by the types it contains, not by itself. We
> shouldn't except it to do more than whatever the types themselves do.
>
> Besides, it will always be possible for a user to wrap offending types.
I don't agree with the need for exception-free assignment. Then we can't even
have an std::string in a variant without wrapping it.
Doug
Boost list run by bdawes at acm.org, gregod at cs.rpi.edu, cpdaniel at pacbell.net, john at johnmaddock.co.uk