
On 12/14/15 12:43 AM, Andrzej Krzemienski wrote:
Ok, now I think I understand the scope of the library. You give me the tool for representing a mathematical notion of an integral number within *some* limited range. The contract is:
You guarantee: 1. Either correct result or a compile time error or a run-time exception. 2. No memory management: you will only take the space of one scalar type.
I would (and have) phrase it differently. 1. Either correct result or a compile time error or a run-time exception. 2. Best runtime performance possible subject to 1. above. So "No memory management" isn't a fundamental principle, but rather implied by 2. above in our current machines.
I specify the range of the representable values. I can say: 1. "From -100 to +100", or 2. "Whatever range 'int' as on my machine".
If you look at the code you'll see something like
template ; But if I got it right, I would say that the choice of the name, and the
interface do not indicate the intent as clear as they could. Imagine the
following alternative interface: small_int I call this safe_integer_range<-100, 100> - I don't think that's
significantly different. small_int I'm not sure what this is meant to mean. But note than many of my tests
and examples I often use something like the following to make this clearer
template
using short_int_t = safe_range<0, 32>; In the first case, the user specifies the range, and the library can choose
the best underlying type for the job. that's what safe_... range does. In the second case, the user chooses the underlying type, and this implies
the range [numeric_limits<T>::min(), numeric_limits<T>::max()] that's what safe<T> does.
Robert Ramey