Boost logo

Boost :

Subject: Re: [boost] [gsoc-2013] Boost.Expected
From: Gottlob Frege (gottlobfrege_at_[hidden])
Date: 2013-04-22 12:45:20

A few thoughts about expected<> :

I think comparison with optional<> is worthwhile. In fact, I think we
should consider small changes to optional, if necessary, if it helps them
align. Specifically I'm thinking of the cast to bool. Does the below
conversions to bool bother anyone?

std::expected<int, Err> exp = ...;
std::optional<int> opt = ...;

if (opt) {

if (exp) {

And if that doesn't bother you, change the 'int' to 'bool' above.

I don't care which way it goes (the alternative being a explicit function
call, like exp.valid() or is_valid() or...), but I think it makes sense for
expected and optional to work the same way, and currently, optional<> is
set to work in the above. So if you really dislike if (exp), then you have
an uphill battle to change optional, which was just accepted.

As for comparing "exceptions", I'm not sure the exception part of expected
should be always considered an exception. Maybe it is just the "false
case" type. ie

expected<true_case, false_case>
expected<expect_type, else_type>

or however you want to think of it.

I would only call it an *exception* type if it gets thrown when trying to
access the value of a false expected:

std::expected<int, Exception> exp;

int x = exp.value(); // has no value - does this throw bad_expected_access,
or does it throw Exception()?

I think answering these questions might help answering the comparison
questions. ie first know what expected<> really is.


Boost list run by bdawes at, gregod at, cpdaniel at, john at