foreach, an analogy
Bill Baxter
dnewsgroup at billbaxter.com
Thu Jan 25 23:48:27 PST 2007
Lionello Lunesu wrote:
> 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.
Is that what he was talking about? I forgot that 'reverse' was an
actual existing method that mutates the array. If that's what you
meant, then, yeh, what Lionello said.
--bb
More information about the Digitalmars-d-announce
mailing list