Static Constructors

Gide Nwawudu gide at btinternet.com
Sun Oct 5 14:32:39 PDT 2008


On Sun, 5 Oct 2008 15:31:38 -0400, "Jarrett Billingsley"
<jarrett.billingsley at gmail.com> wrote:

>On Sun, Oct 5, 2008 at 1:26 PM, Gide Nwawudu <gide at btinternet.com> wrote:
>
>> The following code outputs [0 4 2 3], is this a bug in D2?
>>
>> int n = 1;
>> int[] data = [0,1,2,3,4].dup;
>> writeln(data); // [0 1 2 3 4]
>> data[n] = data[$-1];
>
>now data is [0 4 2 3 4]
>
>> data[$-1] = 0;
>
>now data is [0 4 2 3 0]
>
>> data.length = data.length - 1;
>
>now data is [0 4 2 3]
>
>> writeln(data); // [0 4 2 3]
>
>And that's right.
>
>What's the issue?

My main issue was with eraseNth re-ordering elements, but if moving
the end element over the nth is standard, then I suppose it's ok. I
would have expected a 'stable' version, i.e. [0 2 3 4] as the result.

Gide


More information about the Digitalmars-d-learn mailing list