Boost logo

Boost :

Subject: Re: [boost] a safe integer library
From: Brook Milligan (brook_at_[hidden])
Date: 2016-01-12 21:57:53


On Jan 12, 2016, at 7:30 PM, Robert Ramey <ramey_at_[hidden]> wrote:
> 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.

Perhaps that is a more useful statement for the documentation. It is certainly more informative.

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

Oops. I forgot the constexpr part. That makes it work at compile time just fine.

It seems to me that the appropriate place for such a function like this is in your safe numeric library, not elsewhere. It is closely allied to the semantics of what a safe numeric type means. Additionally, if nothing else, it serves as an example of the proper use of the checked_result type.

Cheers,
Brook


Boost list run by bdawes at acm.org, gregod at cs.rpi.edu, cpdaniel at pacbell.net, john at johnmaddock.co.uk