Boost logo

Boost :

From: Douglas Gregor (gregod_at_[hidden])
Date: 2003-10-10 22:17:40

On Friday 10 October 2003 09:01 pm, Eric Friedman wrote:
> The question that needs to be answered is the following:
> "Is a singular variant worse than one with unspecified content?"

Absolutely. The basic guarantee is used in many places, and I can deal with it
when I'm truly paranoid about exceptions. But this singular value breaks one
of the key variant invariants: static completeness-of-decoding safety. I
haven't had the fortune to use variant<> much, but I use my own little hack
to assure completeness of decoding in my own variant-like area, and I can't
even count the number of times it's saved me: added another potential option
to the variant? BOOM! All the code that doesn't take that option into account
fails to compile. But this singular state... that doesn't affect compilation,
so now we fall into the land of undefined behavior any time an exception is
thrown in operator=, and we can't detect this statically?

I'm in the same camp as Dave here: I'm solidly against having a singular state
in variant unless the user asks for it with boost::empty, but I'm not going
to argue the issue further. You know variant best, and I'm sure you'll make
the right decision.


Boost list run by bdawes at, gregod at, cpdaniel at, john at