The motivation here is to flesh out the error handling path. When an error occurs it's likely that other expected functions may be called to cleanup. At the moment this would look like this:
auto delete_file = [](auto&& err) {
return do_delete()
.error_or(err);
};
on_error is a more powerful or_else, it could conditionally turn an error into a value again. This would also be useful during error handling, perhaps as a "cleanup and try a different technique that might still fail" type function.
error_or
would be the compliment tovalue_or
The motivation here is to flesh out the error handling path. When an error occurs it's likely that other
expected
functions may be called to cleanup. At the moment this would look like this:With
error_or
,delete_file
could look like:on_error
is a more powerfulor_else
, it could conditionally turn an error into a value again. This would also be useful during error handling, perhaps as a "cleanup and try a different technique that might still fail" type function.This is also suggested in the proposal: https://www.open-std.org/jtc1/sc22/wg21/docs/papers/2022/p2505r4.html