Boost logo

Boost :

Subject: Re: [boost] [variant2] Review of Variant2 started today : April 1 - April 10
From: Andrzej Krzemienski (akrzemi1_at_[hidden])
Date: 2019-04-05 21:02:57


pt., 5 kwi 2019 o 19:04 Peter Dimov via Boost <boost_at_[hidden]>
napisał(a):

> 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.
>

Ah ok; default-constructs to `monostate` when at index 0, and falls back
(after exception) to `monostate` if at any index.


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