|
Boost : |
Subject: Re: [boost] [outcome] To variant, or not to variant?
From: Thomas Heller (thom.heller_at_[hidden])
Date: 2017-05-31 14:43:18
Am 31.05.2017 4:26 nachm. schrieb "Peter Dimov via Boost" <
boost_at_[hidden]>:
Gavin Lambert wrote:
> I probably should have thought of asking this earlier, but it occurs to me
> now that my own mental model of how an "outcome"-ish type should act is
> probably not suited to variant storage at all.
>
> So just out of curiosity I thought I'd ask whether people prefer this sort
> of interface:
>
...
Or this sort of interface:
>
...
Neither. I prefer a combination of the two. Like a variant, exactly one of
has_value(), has_error(), has_exception() should report true, depending on
whether you called set_value, set_error, or set_exception. The accessors
however, should work as you previously outlined.
// throws when !has_value()
T value() const;
// error_code() when has_value()
// error when has_error()
// errc::has_exception when has_exception()
error_code error() const noexcept;
// nullptr when has_value()
// either nullptr or make_exception_ptr(system_error()) when has_error()
Why not this:
make_exception_ptr(system_error(error()) when has_error()?
// exception when has_exception()
exception_ptr exception() const noexcept;
Boost list run by bdawes at acm.org, gregod at cs.rpi.edu, cpdaniel at pacbell.net, john at johnmaddock.co.uk