int [50]data; foreach(i, datum; data){} // works File file("gasdgasd"); foreach(i, line; file.byLine){} //NOPE. foreach(line; file.byLine){} //works.
I finally noticed in the docs it says "for arrays only." The question is, why?
Every language that I used previously (as far as I can remember) implemented foreach in a way that's consistent / orthogonal.
Is there a way around this? Because currently I have to liter my foreach's with ugly manual index variables that hold scope even after it's gone.
int i = 0; foreach(line; file.byLine){ //do stuff i++; } i = 2; // still exists!