Boost logo

Boost :

Subject: Re: [boost] variant2 never empty guarantees
From: Andrzej Krzemienski (akrzemi1_at_[hidden])
Date: 2017-06-06 11:07:52


2017-06-06 12:51 GMT+02:00 Niall Douglas via Boost <boost_at_[hidden]>:

> > You are basically saying: provide the implementation that gives me strong
> > guarantee when I meet condition X. ("X" being up to one type with
> > potentially throwing move constructor).
> >
> > Your expectation is reasonable, but (I think) it is incompatible with
> other
> > peoples' expectation: provide implementation that gives me never-empty
> > guarantee when I meet condition Y. ("Y" in that case means I have a type
> > with nothrow default constructor.)
> >
> > I do not think both expectations can be satisfied in one implementation.
>
> I think it daft that a variant require any default constructors at all.
> My understanding of C++ 17 std::variant<> is that it does not require
> any of its types to have default constructors.
>

It probably doesn't. My "condition Y" does not mean that default
constructor is required. It says, "if you happen to provide a default
constructor, I am offering more in exchange".

>
> I certainly feel no warmth to the idea of a variant which will default
> construct to any of its possible states instead of to explicit
> valueless. If I just lost previous state due to a throw during
> assignment, I **want** that reflected in the variant state.
>

Personally, I also do not see why default constructing to just any state
state upon unsuccessful assignment is better than valueless_by_exception().
It would be helpful if people who consider themselves supporters of
never-empty guarantee could fabricate an example that illustrates when
never-empty is superior to the current valueless_by_exception (note that
you can assign from valueless state).

Regards,
&rzej;


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