Using zip to copy subarray into another
Craig Dillabaugh
cdillaba at cg.scs.carleton.ca
Tue Aug 13 13:22:58 PDT 2013
On Tuesday, 13 August 2013 at 19:50:37 UTC, Jonathan M Davis
wrote:
> On Tuesday, August 13, 2013 21:22:24 Craig Dillabaugh wrote:
>> 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.
>
> Why not just use std.algorithm.copy, or even just assigning one
> array to the
> other? e.g.
>
> dest[2 .. 5] = src[1 .. 4];
>
> - Jonathan M Davis
These work reasonably well and I will likely use your suggestions
here.
The one thing I get with zip that I lose using std.algorithm.copy
or straight assignment of the slices is that it handles
mismatches in slice sizes automatically (it stops as soon as
either slice is exhausted).
For example
copy(array2[4..8], array1[9..$]);
where array1 had 10 elements fails because it copies data off the
end of array1, and if I use straight assignment the slices must
be the same length.
Craig
More information about the Digitalmars-d-learn
mailing list