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 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
or
expected
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 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.
Tony