Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Support changing the error type via .or_else #102

Open
Quuxplusone opened this issue Jan 2, 2022 · 1 comment
Open

Support changing the error type via .or_else #102

Quuxplusone opened this issue Jan 2, 2022 · 1 comment

Comments

@Quuxplusone
Copy link

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.

@azais-corentin
Copy link

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);

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants