Boost logo

Boost :

Subject: Re: [boost] [variant2] Review of Variant2 started today : April 1 - April 10
From: Peter Dimov (pdimov_at_[hidden])
Date: 2019-04-05 17:03:47


Andrzej Krzemienski wrote:
> > A possibly-empty variant can be well approximated by adding `monostate`
> > as one of the alternatives. This is recognized by `variant` as the empty
> > state, and is preferentially used as a fallback on exception. If
> > monostate is the first alternative, as is the common case, variant will
> > default-construct to it.
>
> Does this happen *only* when `monostate` is at index 0, or when
> `monostate` is at any index? I thought from the sources that `monostate`
> on any index gives the guarantee.

Like std::variant, variant2 always default-constructs to the first
alternative. That is, the default constructor of variant<T1, T2, ..., Tn>
initializes a contained value of type T1.


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