Subject: Re: [boost] [outcome] Possible extensions/changes to std::experimental::expected
From: Andrzej Krzemienski (akrzemi1_at_[hidden])
Date: 2017-05-25 21:47:13
2017-05-25 23:34 GMT+02:00 Peter Dimov via Boost <boost_at_[hidden]>:
> Andrzej Krzemienski wrote:
>> Instead, rewrite observer functions like this:
>> bool has_value() const
>> if (BOOST_UNLIKELY(_is_in_empty_state()))
> Please no. This is horrible. Actually it's doubly horrible; merely
> horrible would be putting the above in value(). In an observer function...
> it's just evil.
Can you explain?
My reasoning is that the above is superior to just leaving members with
uninitialized vaues. This is a proposed implementation for the design
where decision has been made to only allow to assign to and destroy the
empty value. UB sanitizers can detect reachin __builtin_unreachable() and
report an error.
And what is the alternative? That if I forget to check for the empty state
I get some unintended behavior?