Boost logo

Boost :

Subject: Re: [boost] a safe integer library
From: Robert Ramey (ramey_at_[hidden])
Date: 2016-01-12 21:30:35

On 1/12/16 1:32 PM, Brook Milligan wrote:
> On Jan 12, 2016, at 1:50 PM, Robert Ramey <ramey_at_[hidden]> wrote:

> It seems that the best correspondence might be something like the following:
> typedef safe_int<int8_t> narrow_type;
> int x = { /* potentially something large */ };
> if (checked::cast<narrow_type>(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

> 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:

Boost list run by bdawes at, gregod at, cpdaniel at, john at