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

Add support for std::optional<T> coroutine that allows unwrapping optional values using co_await #43

Open
lewissbaker opened this issue Aug 31, 2017 · 2 comments

Comments

@lewissbaker
Copy link
Owner

lewissbaker commented Aug 31, 2017

See https://github.com/toby-allsopp/coroutine_monad for inspiration.

std::optional<int> parse_int(const std::string_view& s);

std::optional<std::tuple<int, int>> parse_int_pair(const std::string_view& a, const std::string_view& b)
{
  co_return std::make_tuple(co_await parse_int(a), co_await parse_int(b));
}
@lewissbaker
Copy link
Owner Author

Note that MSVC as of 2017 Update 3 would not currently be able to use such an abstraction as it currently converts from get_return_object() return-value into coroutine return-type immediately rather than waiting until after the coroutine is suspended. I am told this will be addressed in a future release.

Clang does not have this problem.

@no-more-secrets
Copy link

Note that MSVC no longer has this problem, neither does gcc. Clang, as you mentioned, traditionally didn't have this problem, but it recently broke (llvm/llvm-project#56532), hopefully they will fix it. Once that happens, all three major compilers should do the lazy implicit conversion which should then support this.

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