Do you like bounded integrals?

Andrei Alexandrescu via Digitalmars-d digitalmars-d at puremagic.com
Mon Aug 29 10:49:28 PDT 2016


On 08/29/2016 11:33 AM, Marco Leise wrote:
> The following could make it
> more accessible, much like the two Exception constructors we
> have:
>
> alias CheckedInt(T, T min, T max, Hook = Abort) =
>       CheckedIntImpl!(T, Hook, min, max);
> alias CheckedInt(T, Hook = Abort) =
>       CheckedIntImpl!(T, Hook, T.min, T.max);
>
> struct CheckedIntImpl(T, Hook = Abort, T min, T max);

Since then I've decided to confine static bounds computation to a 
separate type. Checked does naturally allow for hooks that impose 
dynamic bounds enforcement.

One interesting tidbit - I was looking at a bounded integer library for 
C++ and it looks like it didn't implement the most interesting parts - 
computing bounds for logical operations: 
https://bitbucket.org/davidstone/bounded_integer/src/cd25b513c508498e882acb6543db5e08999243fb/include/bounded/detail/arithmetic/bitwise_and.hpp?at=default&fileviewer=file-view-default


Andrei




More information about the Digitalmars-d mailing list