For the Weka guys: this fixes your casts

Lionello Lunesu via Digitalmars-d digitalmars-d at puremagic.com
Mon May 9 00:55:35 PDT 2016


I just saw Shachar's lightning talk and wanted to point them to this 
feature that I had done for enhancing Value Range Propagation.

By adding "const" to the index variable, the compiler will actually 
enforce the value-range for a foreach iterator. But, this still requires 
the range to known, so only works for static arrays:


void main() {
   immutable ubyte PARITIES_START = 10;
   ubyte[4] parities = [1, 2, 4, 5];

   foreach(const ubyte i, ref parity; parities) {
     ubyte diskId = PARITIES_START + i;       // look ma, no cast
   }

}


This has been in D for over year now. Try it.

L.


More information about the Digitalmars-d mailing list