Boost logo

Boost :

From: David Abrahams (dave_at_[hidden])
Date: 2003-10-10 21:39:47


"E. Gladyshev" <egladysh_at_[hidden]> writes:

> --- Eric Friedman <ebf_at_[hidden]> wrote:
> [...]
>> Since the value of v is in general wholly unspecified, it seems to me
>> that the only way to ensure meaningful content for v is another
>> assignment. This suggests to me that a singular variant is no worse than
>> one with unspecified content.
>
> I think that debugging programs with singular variants
> is much simpler than with variants with unspecified content.
> If you allow unspecified content, in practice you would
> have to catch unspecified data for all types in your variants
> instead of just one case of a singular variant.
> If you don't catch well formed but unspecified content,
> the program might appear running just fine for years.
> Programmer's worst nightmare. :)

Oh, two more things I should point out:

1. The unspecified content that can arise with variant is never any
   worse than the unspecified content of one of its contained types.
   In other words, you can only get unspecified content when assigning
   a new T value into a variant already containing an object of type
   T, and only if T's assignment operator does not give at least the
   strong guarantee.

2. If you change variant so that it "goes singular" the moment an
   assignment fails, you actually *weaken* the guarantees you get for
   a variant where every possible contained type's assignment operator
   gives at least the strong guarantee. Basically, the value is still
   perfectly good, but just because there was an exception, variant
   decides it must be erased. I think that's nasty.

-- 
Dave Abrahams
Boost Consulting
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