Question about ubyte x overflow, any safe way?

matheus matheus at gmail.com
Sun Aug 4 21:49:19 UTC 2019


On Sunday, 4 August 2019 at 18:38:34 UTC, Paul Backus wrote:
> ...
> Use std.experimental.checkedint:
>
> import std.stdio;
> import std.experimental.checkedint;
>
> void main()
> {
>     for(Checked!(ubyte, Throw) u = ubyte(250); u < 256; ++u) {
>         writeln(u.get);
>     }
> }
>
> An exception will be thrown when you attempt to increment u 
> above 255.

Unfortunately I'm using DMD 2.072 which doesn't support this, but 
I'll upgrade soon as I can and will check this out.

Thanks,

Matheus.


More information about the Digitalmars-d-learn mailing list