static foreach
bearophile
bearophileHUGS at lycos.com
Sun Mar 28 15:49:58 PDT 2010
Andrei Alexandrescu:
> static foreach was part of the plan until recently, but Walter
> encountered severe implementation difficulties so we had to abandon it.
I didn't know this.
It looks like a simple thing to implement, but it must be an illusion.
> I agree that it's odd that the same statement iterates at compile-time
> or run-time depending on the iterated type.
Between implementing a good static foreach that can be used outside functions too, and the current situation, there is an intermediate possibility: to require the prefix keyword "static" before "foreach" when the foreach is done on a tuple, that is when it's static. This changes nothing in the current D2 semantics. But it makes code a little more readable because you can tell apart with no problems the static case of loop on a tuple from the other one.
[Later if Walter finds a way to implement, the static foreach can be made richer, for example letting the compiler translate "static foreach (i; 10 .. 20)" in a "static foreach (i; Range!(10, 20))". And even later if Walter is able the whole thing can be allowed outside functions.]
Bye,
bearophile
More information about the Digitalmars-d
mailing list