Is there any particular reason why std.range : enumerate is a thing and

    foreach (i, e; range) { ... }

doesn't work from the get-go? I wouldn't have such an issue with it if static foreach would work with enumerate just fine. As far as I can tell,

    foreach (e; range) { ... }

is being lowered to

    for (auto _range = range; !_range.empty; _range.popFront)
    {
        auto e = _range.front;
        ...
    }

So why cant DMD rewrite

    foreach (i, e; range) { ... }

to

for (auto _range = range, index = size_t(0); !_range.empty; _range.popFront, ++index)
    {
        size_t i = index;
        auto e = _range.front;
        ...
    }

Doesn't seem like a big deal, does it? I'm asking because I suspect there's an odd reason I have no idea and I whish to be educated.

Reply via email to