
2017-03-11 20:22 GMT+03:00 Robert Ramey via Boost <boost@lists.boost.org>:
On 3/11/17 7:52 AM, Steven Watanabe via Boost wrote:
AMDG
On 03/11/2017 02:00 AM, Antony Polukhin via Boost wrote:
I'd like to see an additional statefull ExceptionPolicy that remembers that an UB was triggered, but does not throw at all. Here's how it could be used:
This also requires an extra function to combine two ExceptionPolicies for binary operators. You'll run into problems with comparison operators, though, as a bool can't hold an ExceptionPolicy.
Couldn't the addressed by a variation of the "ignore exception" policy which is meant to just return?
A simple extension to log such errors could be crafted from this idea and would make a great example on how to make one's own exception policy.
What is missing from this idea?
State of the Policy is missing. In many cases it could be useful to have a Policy with state to be able to get the UB info. This may be useful for different try_* functions that must not throw, usually are in hot path and rarely trigger UB: bool try_do(int x_native) noexcept { bool was_an_error = false; safe<int, native, lazy> x(x_native, &was_an_error); // remembers that error was triggered in the `was_an_error` variable ++x; // ... other operations on `x` // ... // `x` is bad, after comparison `y` is also bad safe<int, native, lazy> y = x; // also copies pointer to `was_an_error` if (x < y) { // ... other operations on `y` } return was_an_error; } Throwing and catching an exception in such function may affect performance. Rewriting the whole function using functions from include/checked.hpp may take a lot of effort and will make the function harder to read. But this is more like a feature request, not a blocker to the library acceptance. looks like they could be added later. -- Best regards, Antony Polukhin