foreach, an analogy

janderson askme at me.com
Thu Jan 25 23:00:59 PST 2007


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.

-Joel



More information about the Digitalmars-d-announce mailing list