One way to look at foreach as not so bad

Bill Baxter wbaxter at gmail.com
Fri Oct 20 21:54:49 PDT 2006


Julio César Carrascal Urquijo wrote:
> Bill Baxter wrote:
> 
>> Maybe I can get used to this version that works now:
>>     obj.each( (int i) {
>>       wrietfln(i);
>>     })
>>
>> But it just looks weird to have my loop body inside the parens, and 
>> will look even weirder if nested
>>     obj.each( (Obj c) {
>>       c.each( (int i) {
>>         writefln(i);
>>       })
>>     })
> 
> 
> I don't understand your point. You can already write something like:
> 
> obj.each = (int i) {
>     writefln(i);
> };
> 

How do you set that up?  Something like this?

class ObjClass
{
    class EachClass {
       void opAssign( void delegate(...) ) {
            [...]
       }
    }
    EachClass each = new EachClass();
}
ObjClass obj = new ObjClass();

Or is there a better way?

--bb



More information about the Digitalmars-d-announce mailing list