Support changing the error type via `.or_else`
Quuxplusone opened this issue · comments
Today I commented on P2505R0 that it should be designed to permit this code:
std::expected<Connection, PortableError> convertError(SSLError e) {
return std::unexpected(PortableError(e));
}
std::expected<Connection, SSLError> e1 = ~~~;
std::expected<Connection, PortableError> e2 = e1.or_else(convertError);
This doesn't work with tl::expected
today. I plan to submit a PR for this feature, but will wait for some of my preliminary PRs to get merged first.
As a workaround, this is exactly what .map_error
does.
Example:
tl::expected<Connection, PortableError> translateError(SSLError e) {
return tl::make_unexpected(PortableError(e));
}
tl::expected<Connection, PortableError> s = e1.map_error(translateError);