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

Added on slide on std::expected #494

Merged
merged 1 commit into from
Oct 11, 2023
Merged

Added on slide on std::expected #494

merged 1 commit into from
Oct 11, 2023

Conversation

sponce
Copy link
Contributor

@sponce sponce commented Oct 11, 2023

No description provided.

enum class Error {...};
std::expected<int, Error> parse(std::string_view in) {
if (is_valid(in)) return convert_to_int(in);
return std::expected(Error::...);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
return std::expected(Error::...);
return std::unexpected(Error::...);

For the un-happy path, I think the intention is to use std::unexpected, although I have no experience with std::expected yet :)

This is also shown in the example on cppreference: https://en.cppreference.com/w/cpp/utility/expected

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Damn... I did copy the example, so used unexpected, yesterday and when reading it back today, I thought it was a typo and removed it :-D
fixed !

@sponce sponce closed this Oct 11, 2023
@sponce sponce deleted the sponce_expected branch October 11, 2023 13:20
@sponce sponce restored the sponce_expected branch October 11, 2023 13:21
@sponce sponce reopened this Oct 11, 2023
@sponce sponce merged commit bc7e723 into master Oct 11, 2023
10 of 12 checks passed
@sponce sponce deleted the sponce_expected branch September 30, 2024 12:32
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

Successfully merging this pull request may close these issues.

2 participants