Nordlöw:

This may be a good start:

https://github.com/nordlow/justd/blob/master/bound.d

I presume some ways to improve it are to add to core.bitop some D standard intrinsics to detect overflows and carry, to increase run-time performance to sufficient levels. If they are not fast, people will be less willing to used them.

Another way to improve it is to add to D something like the "enum preconditions" I've discussed in past. So this bug can be detected at compile-time:

Bound!byte b = 200;

A third possible improvement is to add a __traits(value_range, exp) trait that returns the value range of an expression. This could be useful to implement the bound integers well.

Other possible more complex problems are shown in that talk about bounded::integer.

Bye,
bearophile

Reply via email to