Skip to content

Add unwrapErr for Results with non-void Error kinds#4

Merged
oktal merged 7 commits intooktal:masterfrom
Nashenas88:master
Jan 10, 2017
Merged

Add unwrapErr for Results with non-void Error kinds#4
oktal merged 7 commits intooktal:masterfrom
Nashenas88:master

Conversation

@Nashenas88
Copy link
Copy Markdown
Contributor

Added unwrapErr to the API of Result.

Comment thread result.h Outdated
typename std::enable_if<
!std::is_same<F, void>::value,
F
>::type
Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

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

I don't think that you need to SFINAE here. I have a static_assert that prevents from having a void error-type: https://github.com/oktal/result/blob/master/result.h#L706

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Why isn't a void error type allowed? I can see that not being too helpful in production code, but having a void error type could still be useful for prototyping or simple applications. It's also allowed in Rust (as Result<T, ()>).

Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

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

Right, but I think it will be a little bit painful to handle.

Currently, you might want to try defining a unit type like struct Unit { } and use it as a void error type, what do you think ?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

That works. I talked about it with a friend and he made the exact same suggestion. I've made and pushed the changes to this PR.

@Nashenas88
Copy link
Copy Markdown
Contributor Author

I think that might work short term. It's not something people will expect when working with the library, but we could work to improve support for void error types, right? As a later feature.

Copy link
Copy Markdown
Owner

@oktal oktal left a comment

Choose a reason for hiding this comment

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

Alright, when the return type of unwrapErr will be fixed, the PR will be ready to be merged in.

Comment thread result.h Outdated
std::terminate();
}

unwrapErr() const {
Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

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

I think you removed the void return type by inadvertence

@Nashenas88
Copy link
Copy Markdown
Contributor Author

Woops, I must have hit something just as I was exiting the file. I fixed it and retested it to make sure it could be called as well.

@oktal
Copy link
Copy Markdown
Owner

oktal commented Jan 10, 2017

Great, looks good to me, thanks for the contribution 👍

@oktal oktal merged commit fee9af7 into oktal:master Jan 10, 2017
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