On Jan 12, 2016, at 12:05 PM, Robert Ramey
On 1/12/16 8:46 AM, Brook Milligan wrote:
On Dec 17, 2015, at 12:16 AM, David Stone
mailto:david@doublewise.net> wrote: I have written a similar library (http://doublewise.net/c++/bounded/ http://doublewise.net/c++/bounded/), and I have a few questions about your implementation.
I am curious whether either of you (Robert and David) have handled the need to evaluate the condition “is X (an object of type with some _potentially_ wide range) within bounds of Y (an object of type with some _potentially_ narrow range)? I have use cases in which I would like use bounded types, but there are situations in which I need to capture the result of something like in_range<Y>(x). I am not seeing this in your libraries but perhaps I am missing something. It does seem quite feasible to include and would seem to incur no runtime cost under the same conditions that the construction Y y = {x} would not.
If I am missing this in your libraries, please let me know; otherwise, I throw this out as a suggested addition.
I'm not 100% sure I understand what you mean, but that's not going to stop me from commenting. The following applies to the safe numerics library.
Perhaps I did not ask my question as clearly as I should have. Sorry.
My understanding, which seems to be reinforced by your response, is that all the normal arithmetic and comparison operations involving safe types either complete with mathematically correct results or fail in some way that depends on the policy. Further, this may or may not involve runtime checks depending on the nature of the specific arguments with respect to ranges, etc.
What I am not seeing in the design is a means of inquiring in advance whether or not an operation will succeed without actually performing the operation. This might be relevant for other cases, but I am most interested in making use of the type system, which by design already includes the relevant range information, to facilitate inquiry regarding assignment or construction. Consider the following code:
int x = { /* something possibly large */ };
safe_int