Using zip to copy subarray into another

Craig Dillabaugh cdillaba at cg.scs.carleton.ca
Tue Aug 13 12:22:24 PDT 2013


I have code that attempts to copy a slice of one array into
another using zip. However, the array is not updated.   I am
guessing this is because modifying the returned tuple does not
modify the actual arrays.

Is there any way to do this.


import std.stdio;
import std.range;

void main( string[] args ) {
    int[] array1 = [1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1];
    int[] array2 = [2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2];

    foreach( ref a; zip(array1[2..$], array2[4..6] ) ) {
      a[0] = a[1];
    }

    foreach( int v; array1 ) write(v, ",");
}

prints 1,1,1,1,...

Thanks
Craig


More information about the Digitalmars-d-learn mailing list