-
Notifications
You must be signed in to change notification settings - Fork 4
expected<void> + return #18
Comments
BTW, Adding such code to expected.hpp helps: template Then I do this: return nonstd::make_expected(); But it is not elegant... maybe you have a better solution ! I should just use "return" (Like I do at the end of the function) |
Like so on Wandbox:
|
I have to revisit expected lite to see if |
Also note that |
Thanks a lot Martin, I see... but then 'maybe' you should remove the make_expected. But, don't you think that is it not 'natural' (not easy to use) to return an empty expected ! We 'should' have an automatic type deduction ! Notice that at the end of the function we don't need to return anything, only with the 'return' keyword ! |
I think the language should not be changed to allow to not return an object for a non-void function(), just to accommodate a library type.
That's likely because its unreachable code after the Changing
|
For expected lite I may retain |
I understand your point, and agree ;-) BTW, it will be great to have more examples, more uses cases. On my side, I try to make it work with std::error_code... to have a more strict error reporting mecanism. I know that the type is optional, but still it is interesting to show such use case ;-) |
BTW, thanks and great work ;-) |
Hi, I tried to compile something like that, but I got a compilation error (MSVC2017):
"error C2561: 'initialize': function must return a value"
The code :
nonstd::expected<void, int> initialize() {
if (true)
return; // <-- Compilation error here
}
Any idea to solve this case ?
The text was updated successfully, but these errors were encountered: