www.digitalmars.com         C & C++   DMDScript  

digitalmars.D - For the Weka guys: this fixes your casts

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.

May 09 2016