DMD 0.170 release

Oskar Linde oskar.lindeREM at OVEgmail.com
Wed Oct 18 01:22:14 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.

In what way does it not work? I have been doing:

foreach(x; "abcd".reverseView())
	writef("%s",x);

prints "dcba"

For any type of built in array for a very long time (long before 0.170), 
and it certainly seems to work for me.

I also do things like:

foreach(x; "aBcDeF".select(&isLowerCase))
	writef("%s",x);

prints "ace"

Making custom foreachable iterators is not a problem in D. It is custom 
single-step iterators that I havn't found a neat solution for yet. I.e., 
as Sean says, being able to iterate through two containers sequentially.

The above versions do use a (as you call it) "dummy" struct that 
contains an opApply. If function-escaping delegates were implemented, I 
don't think even the "dummy" struct would be needed, but I don't agree 
that having a

struct ReverseIterator(T:T[]) {... mixin opApplyImpl; }

is that much of a hack.

/Oskar



More information about the Digitalmars-d-announce mailing list