Automatic Foreach

Bruno Medeiros brunodomedeiros+spam at com.gmail
Tue Apr 29 12:28:28 PDT 2008


janderson wrote:
> while back I wrote a template that works like:
> 
> void foo(int i)
> {
>   printf("B");
> }
> 
> alias AutoForeach!(foo, int) foo;
> 
> Then I could go:
> 
> for(6); //Prints "B"
> int[] array;
> array = 2;
> foo(array); //Prints "BB"
> 
> But then I couldn't specialize it later without removing the alias, 
> because I'd get a name clash.
> 
> The other problem is this won't do cases like:
> 
> result ~= foo(array);
> 

Why not? Didn't you define AutoForeach!(foo, int) to return an int[] ?

> or
> 
> foo(foo1(array));  //Runs foo and foo1 array.length times.
> 
> 

Same as above.

-- 
Bruno Medeiros - Software Developer, MSc. in CS/E graduate
http://www.prowiki.org/wiki4d/wiki.cgi?BrunoMedeiros#D



More information about the Digitalmars-d mailing list