Assigning map result, and in-place map

Bert van Leeuwen bert at e.co.za
Fri Sep 3 02:42:03 PDT 2010


I'm a D n00b, so excuse my question if it is silly. I've cursorily "followed" D for a few years, but only now bought "The D Programming Language" (great book, very nicely written!) and started to really play with it.

I've run into two questions which I have not been able to find the answers to online.

1) I have an int array which I want to replace elements of with compile-time string expression, e.g.

i=new int[100];
auto b=map!("(a==0)?42:a")(i);
writeln(b);

Cool, that works. But now I want to get at the resulting array. If I replace "auto b" with:
int[] b = map ...
that does not work ("cannot implicitly convert expression (map(i)) of type Map!(result,int[]) to int[]")... fine, but how do I get to the int[] ?

2) Related to above, I want to do something like map, but not return a new array, I want to modify elements in-place in the array. How do I do that? (without explicitly iterating with foreach etc.)


More information about the Digitalmars-d mailing list