Boost logo

Boost :

Subject: Re: [boost] [outcome] Possible extensions/changes to std::experimental::expected
From: Niall Douglas (s_sourceforge_at_[hidden])
Date: 2017-05-25 22:38:14


> Ok. Now I am thinking, another thing you can do, is to internally store
> something like varient<T, Y, Empty> but do not expose this Empty in the
> interface. Instead, rewrite observer functions like this:
>
> ```
> bool has_value() const
> {
> if (BOOST_UNLIKELY(_is_in_empty_state()))
> __builtin_unreachable();
>
> return _is_in_valued_state;
> }
> ```

Good god no. .has_value() is always legal to call irrespective of the
current state.

I don't mind the above for say .value(), so if trying to retrieve a
value and the current state is not a value, that should be unreachable
i.e. static analysis triggers if you're doing an obvious stupidity.

Niall

-- 
ned Productions Limited Consulting
http://www.nedproductions.biz/ http://ie.linkedin.com/in/nialldouglas/

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