foreach, an analogy
Lionello Lunesu
lio at lunesu.remove.com
Thu Jan 25 23:33:14 PST 2007
janderson wrote:
> Walter Bright wrote:
>> Bruno Medeiros wrote:
>>> As of DMD now, the only advantage in 'foreach_reverse' is ephemerous:
>>> it allows efficient reverse iteration of arrays.
>>
>> That's the most important use case.
>>
>>> But couldn't the compiler easily detect this:
>>> foreach(Foo f; &fooarray.opApplyReverse) { ...
>>> and and compile it as if it were a:
>>> foreach_reverse(Foo f; fooarray) { ...
>>
>> Yes, it could. But it looks like a hack. A little syntactic sugar
>> makes a big difference.
>
>
> What about:
>
> foreach (Foo f; array.reverse) {}
>
> The compiler would optimize.
But the array would still be reversed after the foreach.
L.
More information about the Digitalmars-d-announce
mailing list