Subject: Re: [boost] [gsoc-2013] Boost.Expected
From: Gottlob Frege (gottlobfrege_at_[hidden])
Date: 2013-04-23 12:55:36
On Tue, Apr 23, 2013 at 10:18 AM, Krzysztof Czainski <1czajnik_at_[hidden]>wrote:
> 2013/4/23 Pierre T. <ptalbot_at_[hidden]>
> > Hello,
> > std::expected<int, Exception> exp;
> >> int x = exp.value(); // has no value - does this throw
> >> bad_expected_access,
> >> or does it throw Exception()?
> >> Actually, expected contains an error and we don't know anything about
> > the type of the error so we cannot throw it.
We can throw anything we want. I'm not sure it is a good idea, but you can
throw anything. It doesn't need to derive from std::expection, for
example. You can throw an int. etc.
> It's what I called
> > expected_base<T, Error> in my previous mails, the get() on expected_base
> > doesn't throw and if expected_base doesn't contain a value, then
> > behavior occurs.
> Hmm, couldn't the original error be thrown anyway (if the wrapping type had
> a virtual function that would throw the error)?
I think we'd like to avoid virtual functions. I'm not even sure the base
class is needed. I think we only want one expected<>, not 2 or 3 variants.
(Although maybe I don't understand what all the variants are, I haven't
looked at it thoroughly.)
What we did for optional<> is allow you to access the value in 2 ways:
int x = oi.value(); // throws bad_optional_access
int y = *oi; // undefined behaviour
Similar to vector [n] vs at(n).
I think expected<> should work the same way.
The only question, to me, is what it throws. Either it throws the Error,
or it throws bad_expected_access. Or it throws bad_expected_access<Error>
which derives from bad_expected_access_base, or something like that. (ie a
well defined exception, but I can still get my custom Error value back from
it if I want.)
Boost list run by bdawes at acm.org, gregod at cs.rpi.edu, cpdaniel at pacbell.net, john at johnmaddock.co.uk