On 1/12/16 11:31 AM, Brook Milligan wrote:
On Jan 12, 2016, at 12:05 PM, Robert Ramey
wrote: int x = { /* something possibly large */ }; safe_int y = x; // clearly this requires a run-time check and may fail Instead, I would like to be able to, for example, branch; something like this:
int x = { /* something possibly large */ }; if (is_convertible
>(x) { do_something_with small values(); } else { do_something_with_large_values(); }
It's going to be a little trickier than that. One basic problem is that
there more than two cases, yes, no, have to check at runtime.
Turns out that similar facilty is used by the library and is available
to users. Downside is there is no example/tutorial so one would
actually have to read the documentation. The general procedure would be:
// create an interval from the safe type
using namespace boost::numeric;
using interval_t = safe_integerstd::int8_t>;
intervalstd::int8_t i = {
std::numeric::limits
In some cases, e.g., if the positions of the int and safe_int<> were reversed above, no runtime checking is required but the appropriate branch is executed. In others, such as actually illustrated, runtime checking is required just as it would be in an assignment.
In either case, however, the result leverages the type system you have developed to inquire about the relative ranges and values in (I feel) an expressive and compact way.
Is this possible currently? Can it be incorporated given the design of the library? Don’t you already have the internals in place to do something equivalent that could be exposed in fashion like this?
I hope that is clearer. Thanks again.
Cheers, Brook
_______________________________________________ Unsubscribe & other changes: http://lists.boost.org/mailman/listinfo.cgi/boost