One way to look at foreach as not so bad

Frits van Bommel fvbommel at REMwOVExCAPSs.nl
Sat Oct 21 00:47:52 PDT 2006


Bill Baxter wrote:
> Julio César Carrascal Urquijo wrote:
>> 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();

That won't work. There is no opAssign.

> Or is there a better way?

In the sense that it works, yes. Something like this:

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


This somewhat abuses the property syntax, but should result in the 
syntax above.



More information about the Digitalmars-d-announce mailing list