On Monday, 30 June 2014 at 07:47:22 UTC, Lionello Lunesu wrote:
Latest [1] now also supports CTFE:
const i = foo ? -1 : 33;
if (i)
static assert(__traits(intrange, i) == Tuple!(-1, 33));
else
{
static assert(i == 0); // Works now!
static assert(__traits(intrange, i) == Tuple!(0, 0));
}
if (i == 33)
{
static assert(i == 33); // Works now!
static assert(__traits(intrange, i) == Tuple!(33, 33));
}
else
static assert(__traits(intrange, i) == Tuple!(-1, 32));
Next up: support for immutable/const members and "if (i) static
assert(i)"
L.
[1] https://github.com/lionello/dmd/tree/if-else-range
Fantastic work, although I would prefer Bearophile's
'value_range', is there any reason why the same trait could not
be used for float, etc? (I don't need it for float, just as an
example).
I guess an interval_set would be too complicated, slowing down
the compiler? i.e. multiple ranges, or multiple values, just
thinking out loud... Anyway what you did already is kick ass! :)