[challenge] Bounded types

Philippe Sigaud philippe.sigaud at gmail.com
Mon Oct 11 18:27:26 PDT 2010


2010/10/11 Denis Koroskin <2korden at gmail.com>:
> Also, one should be able to define CheckedInt type as follows:
>
> alias Bounded!(int, int.min, int.max) CheckedInt;
>
> CheckedInt would allow easy integer overflow detection.

Does Adam's code do that? I don't know the behaviour of jo overflow;

> Smart compiler would
> also optimize all the (int.min <= value  && value <= int.max) checks as
> redundant, and the type would be very slim and efficient.

That could also be done with static introspection. I gather most use
of this type would be for integral values, so it makes sense to test
for min == T.min or max == T.max.


Philippe


More information about the Digitalmars-d mailing list