range foreach lambda

ddos via Digitalmars-d-learn digitalmars-d-learn at puremagic.com
Thu Jul 17 05:53:20 PDT 2014


thx alot! its not important to me that the function is not 
evaluated in place
since you gave me such a straight answer i'd like to bother you 
with another question :)

for example i have now two ranges:

immutable a = [1,2,3,4];
immutable b = [2,3,4,5];

how do i add the elements in a and b elementwise in a functional 
style?

a+b == [3,5,7,9]

usually i'd do something like this:

int[4] o;
for(int i=0;i<4;i++)
{
   o[i] = a[i] + b[i];
}


More information about the Digitalmars-d-learn mailing list