Subject: Re: [boost] [variant2] Formal review
From: Rainer Deyke (rainerd_at_[hidden])
Date: 2019-04-14 17:18:48
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.
If the alternative types are function pointer types, then never-empty
provides no improvement over valueless-by-exception. On an exception,
the variant will simply contain a typed nullptr instead of being empty.
If the alternative types are non-empty function objects, then
never-empty provides at best a marginal improvement over
valueless-by-exception. On an exception, the variant will contain a
wrong (default-constructed) function object.
If the alternative types are empty function objects, then the benefit of
never-empty is still marginal. The variant will still contain a wrong
function object, albeit one drawn from the pool of correct function
objects. The invariants of the state machine can still be broken.
Also, if the alternative types are empty function objects, then there is
no reason for why their constructors should ever throw, so the
never-empty guarantee should never come into play in the first place.
What am I missing here?
-- Rainer Deyke (rainerd_at_[hidden])
Boost list run by bdawes at acm.org, gregod at cs.rpi.edu, cpdaniel at pacbell.net, john at johnmaddock.co.uk