More powerful foreach statements

Ben Phillips Ben_member at pathlink.com
Thu Jul 20 11:23:57 PDT 2006


In article <e9ogh7$b1b$1 at digitaldaemon.com>, kris says...
>
>1)  foreach (int i, Foo f; ManyFooInstance)
>              if (i is 0)
>                  ....
>
>Or somthing like that.
>

I tested it and it works, AND its documented. My fault.

>
>2) foreach (int element; collection.reverse)
>	    ...
>
>where #2 returns a type which supports foreach. Typically, this would be 
>some kind of Iterator construct. IIRC, someone already has a framework 
>for such things? Was it Oskar?
>

I remember seeing stuff like this in the MinTL code, but having to create a
separate type for each type of iteration that you want to support seems rather
silly (though adding a new language feature to do so may be equally silly as
well).

Also, that still doesn't allow one to go reverse order through a builtin array
with a foreach, unless of course you call ".reverse", which is needlessly
expensive.





More information about the Digitalmars-d mailing list