RFC: Value range propagation for if-else

Lionello Lunesu via Digitalmars-d digitalmars-d at puremagic.com
Mon Jun 30 00:47:20 PDT 2014


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


More information about the Digitalmars-d mailing list