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.

Reply via email to