pt., 5 kwi 2019 o 19:04 Peter Dimov via Boost
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
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.