Boost logo

Boost :

From: Eric Friedman (ebf_at_[hidden])
Date: 2003-10-07 03:34:58


E. Gladyshev wrote:
> --- Eric Friedman <ebf_at_[hidden]> wrote:
> [...]
>>To check each type Ti in variant<T1,...,TN> would add O(n) compile-time
>>complexity. To check only the first type T1 adds only O(1) complexity.
>>
>>In short, then, there's no theoretical reason to treat T1 specially, but
>>it seemed to me a good compromise.
>
> I don't think that it is a good compromise.
> It enables an unpredictable behaviour that is changing
> based on the first type in the variant.
> If the user doesn't enforce the predictability
> by using boost::empty, then all of her variant types
> will behave differently based on what the first type is.
> It is a very artificial and dangerous solution.

I disagree. The *only* relevant guarantee made by a variant<T1,...,TN>
is that at all times it contains exactly one value of one type Ti. Thus,
in the event of assignment failure, there is no guarantee that the
contained type Tk after failure is the same type Tj as before.

There is nothing "unpredictable" about going into assignment with some
type U and coming out after failure with boost::empty (or some other
nothrow default-constructible type).

Eric


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