On Friday, 2 March 2018 at 10:32:08 UTC, Jonathan M Davis wrote:
foreach does not support indices for ranges, only arrays. When
it gets lowered to
foreach(auto __range = range; !__range.empty;
auto e = __range.front;
There are no indices involved there, and if a range isn't a
random-access range, it doesn't support any kind of indices
anyway. The compiler would have to add a variable to count the
elements, and it doesn't support that.
I understand. I guess I was expecting the compiler to
automatically do something along the lines of what enumerate
does. Although, a nicer error message would have saved the day
just as well.