|
Boost : |
From: David Abrahams (dave_at_[hidden])
Date: 2002-08-10 01:11:25
From: "Douglas Gregor" <gregod_at_[hidden]>
> 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.
That's precisely what I meant when I said "broken type". BTW, I don't know
what Fernando's talking about above ;-)
> > 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.
I agree with Fernando that we shouldn't expect variant to do more than
whatever the types themselves do. I also agree with Doug that requiring
exception-free assignment would be bad.
-Dave
-----------------------------------------------------------
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