Do you like bounded integrals?

Meta via Digitalmars-d digitalmars-d at puremagic.com
Tue Aug 23 14:10:26 PDT 2016


On Tuesday, 23 August 2016 at 20:40:06 UTC, Andrei Alexandrescu 
wrote:
> * When composing, do the limits compose meaningfully?

Just to make sure I understand what you mean by "composing 
limits", do you mean this?

alias NonNegativeInt = CheckedInt!(int, Abort, 0, int.max);
alias Ubyte = CheckedInt!(NonNegativeInt, Abort, 
NonNegativeInt(0), NonNegativeInt(255));
Ubyte b; //b is guaranteed to be in [0, 255]

And then we should expect this to fail:

alias Byte = CheckedInt!(NonNegativeInt, Abort, 
NonNegativeInt(-128), NonNegativeInt(127));




More information about the Digitalmars-d mailing list