DbI checked integral
deadalnix via Digitalmars-d
digitalmars-d at puremagic.com
Sat Jun 25 14:46:23 PDT 2016
On Saturday, 25 June 2016 at 14:38:43 UTC, Robert burner Schadek
wrote:
> I think there is a major problem with the proposed design.
>
> when Checked!(int, void) is to behave as an int, why do we need
> it in the first place. I mean we have int as a basic type.
> Can't we do:
>
> alias Int = int;
> alias Int = Checked!(int, SomeUsefulHook);
>
> On second thought, the only feature of Checked!(int, void) is
> to be a slower int ;-)
>
> IMO the default CheckedInt!(int, void) needs a NaN like
> init/failure state. After any operation that overflows the
> value should be NaN.
IMO this is the same problem as for the test function with no
arguments. What if your policy does nothing ? This is the end
case, and while probably not very useful on its own, is very
important to not push a ton of complexity on user code.
Just like multiplying by 0 or 1 is not very useful, yet the MUL
instruction and * operator accept these as operands. Like adding
0 is not useful, yet ADD and the + operator accept these as
operand.
It is important for library code to handle degenerate cases
gracefully.
Also I'd run the code in LLVM's opt to see what comes out, but
I'd be pretty sure if we are careful, it can optimize everything
away and get us back to ints.
More information about the Digitalmars-d
mailing list