On 1/12/16 1:32 PM, Brook Milligan wrote:
On Jan 12, 2016, at 1:50 PM, Robert Ramey
wrote:
It seems that the best correspondence might be something like the following:
typedef safe_int
narrow_type; int x = { /* potentially something large */ }; if (checked::cast (x).no_exception()) { do_something_with_small_values(); } else { do_something_with_large_values(); } Is that the correct semantics?
Looks OK. Should I be worried about the following comment from your docs: "Note that this type is an internal feature of the library and shouldn't be exposed to library users because it has some unsafe behavior.”? That seems worrisome and was a reason this did not register earlier. I don't remember what I was thinking when I wrote that. But it might be that I didn't want users to use the function without checking the return value.
This solution suggests that wrapping this particular construct in something that is unambiguously safe would be a good idea:
template < typename R, typename T > bool is_convertible<R>(T const& t) { return checked_cast<R>(t).no_exception(); }
Does that make sense?
I'd have to think about it. but it looks OK. BTW there is a function in mpl "is_convertible" which implements this behvaior at compiler time - not runtime as here. So you might want to change the name
Cheers, Brook
_______________________________________________ Unsubscribe & other changes: http://lists.boost.org/mailman/listinfo.cgi/boost