DMD 0.170 release

Ary Manzana asterite at gmail.com
Wed Oct 18 05:29:38 PDT 2006


Walter Bright wrote:
> Bill Baxter wrote:
>> I don't see how it helps.  If you can already do:
>>    foreach(T item; &collection.reversed()) { }
> 
> That doesn't work for arrays.

Is "foreach_reverse" just there for arrays? To me it dosen't bother to 
have a new keyword, but if it just exists to do:

for(int i = array.length - ; i >= 0; i--) {
	// ...
}

then it is realy superflous.

"foreach_reversed" just is useful for two things: arrays and lists. For 
arrays you can always type the code above. For lists, give them a 
"reversed" method that accepts a delegate, as I wrote. For other types 
the "foreach" dosen't guarantee the order! (map, tree, set, etc.)

So "for(;;)" appears 5% of the time, convert it to "forever". :-)

I repeat: is "foreach_reverse" just there for arrays?



More information about the Digitalmars-d-announce mailing list