array copy/ref question

Jesse Phillips jessekphillips at gmail.com
Wed Aug 13 18:52:43 PDT 2008


On Tue, 12 Aug 2008 14:51:39 +0000, Sclytrack wrote:

> == Extrait de l'article de « Jesse Phillips (jessekphillips at gmail.com) »
>> On Tue, 12 Aug 2008 02:42:17 +0000, Jesse Phillips wrote:
>> > main( string[] args )
>> > {
>> >     int[] test = [ 1, 2, 3, 4 ];
>> >     int[] copy = new int[4];
>> >
>> >     copy[]  = test;
>> >     test[1] = 11;
>> >
>> >     assert( test[1] == 11 );
>> >     assert( copy[1] == 2 );
>> >
>> >     writefln( "Copy: test[1] %d copy[1] %d", test[1], copy[1] );
>> > }
> 
> copy = test.dup;  //Is this what you want?

Yes, I probably should have mentioned this as well. However I did wish to 
give him an idea of what was causing the overlapping. I should also note 
that with the demonstrated method you are able to copy into a slice of an 
array.

copy[1..5] = test[4..8]; or even
test[0..2] = test[3..5]; // As long as they don't overlap :)



More information about the Digitalmars-d mailing list