Subject: Re: [boost] variant2 never empty guarantees (was: Re: Outcome/expected/etc/etc/etc)
From: Andrzej Krzemienski (akrzemi1_at_[hidden])
Date: 2017-06-16 09:22:02
2017-06-14 19:10 GMT+02:00 Peter Dimov via Boost <boost_at_[hidden]>:
> Andrzej Krzemienski wrote:
> Now I realize this all means the types inside variant need to be movable.
>> This will not be a problem in most of the cases, but does it mean I cannot
>> use variant2 with non-movable types?
> You can, it will double-buffer to keep emplace strong. Or you can use
> All types nothrow move constructible -> single buffer;
> Otherwise, first alternative is valueless -> single buffer;
> Otherwise -> double buffer.
So, If I got all this right:
* All types nothrow move constructible -> single buffer, requires
* Otherwise, first alternative is valueless -> single buffer (no
* Otherwise -> double buffer (no MoveConstructible).
Is that correct?
Some other thoughts:
When valueless is required as the first type, it also implies that the
default constructor of variant puts it into valueless state, which some
might find useful, but others inferior to std::variant. Would it be
possible to also assign a special meaning to putting `valueless` at the
end, which would assign semantics of std::variant?
Maybe the choice how you want to implement the assignment should be
explicitly controlled by the users (in form of a policy)? You could still
provide the defaults based on properties of the types, but it looks to me
sometimes people might want to override the defaults. For instance, we have
seen examples where I want strong guarantee on assignment even when T does
not offer one. Or to put it differently, it may be that this double
buffering may be useful on its own, even outside the variant.
Boost list run by bdawes at acm.org, gregod at cs.rpi.edu, cpdaniel at pacbell.net, john at johnmaddock.co.uk