Boost logo

Boost :

Subject: Re: [boost] [variant2] Formal review
From: Emil Dotchevski (emildotchevski_at_[hidden])
Date: 2019-04-14 18:16:08


On Sun, Apr 14, 2019 at 10:19 AM Rainer Deyke via Boost <
boost_at_[hidden]> wrote:
>
> On 13.04.19 19:26, Bjorn Reese via Boost wrote:
> > * std::variant which enters an invalid (valuless_by_exception) state.
> > While that may be appropriate for some use cases, there are others
> > where it is not. For instance, the variant may be used for a state
> > machine where the alternative types are function object types to be
> > invoked when events arrive. Having a valueless state is the wrong
> > choice for this use case.
>
> Wait. I don't understand how never-empty is an advantage in this example.
>
> The invariants of the state machine can still be broken.

It is not the job of variant to maintain the invariants of the state
machine, that is the job of the state machine.

If you have:

struct foo { bar x; .... };

Even though bar provides the basic guarantee, if a bar operation fails, it
is still possible for x to change to a valid (for bar) state that makes the
foo object invalid. This doesn't mean that there's something wrong with the
design of bar, it just means that the basic guarantee does not propagate
automagically.


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