Closed jhwest closed 10 years ago
Thanks for sharing this issue.
I don't know if taking it in account only on debug mode is a solution.
std::future seems to suffer from the same issue.
Agreed, handling in debug mode only isn't ideal. Perhaps allowing the user to specify a custom function to call (say, a logging function) would be better, but that gets more complex.
On Sun, Dec 29, 2013 at 2:39 AM, Vicente J. Botet Escriba < notifications@github.com> wrote:
Thanks for sharing this issue.
I don't know if taking it in account only on debug mode is a solution.
std::future seems to suffer from the same issue.
— Reply to this email directly or view it on GitHubhttps://github.com/ptal/Boost.Expected/issues/2#issuecomment-31314864 .
IHMO, a function returning an expected
expected<int> fun(int& data) { ...}
int main(int argc, char* argv[]) {
int i = 0;
fun(i);
// The value of i might be something not expected (since we didn't test the return value).
}
In this last case, the designer of the function has maybe misused the expected class.
Anyways, it's not in the spirit of C++ to add a "read" boolean (as in the SO link you posted) just to be sure the user didn't ignore the value.
Our very basic home grown version has CMExpected
I have reached to define a ensured_read
expected<T, ensured_read<int>> e = make_unexpected(make_ensured_read(1));
int errc = e.error(); // avoids termination.
This should not work yet for expected<T, ensured_read<exception_ptr>>
.
Great - I look forward to trying it out.
Jay
On Sun, Apr 6, 2014 at 10:12 PM, Vicente J. Botet Escriba < notifications@github.com> wrote:
I have reached to define a ensured_read class that terminates if its underlying value has not been read. This class can be used with expected as follows
expected> e = make_unexpected(make_ensured_read(1)); int errc = e.error(); // avoids termination.
This should not work yet for expected> .
Reply to this email directly or view it on GitHubhttps://github.com/ptal/Boost.Expected/issues/2#issuecomment-39696689 .
I have added an specialization of expected_traits<ensured_read<exception_ptr>>
.
expected<T, ensured_read<exception_ptr>>
should work now as expected ;-)
As the above code example runs without producing any error. This shows that it's still possible to completely ignore any error conditions. http://stackoverflow.com/questions/14923346/how-would-you-use-alexandrescus-expectedt-with-void-functions addresses this.
Destructor of
expected
could have an assert check that triggers if the return status has been completely ignored.