Array start index

Bastiaan Veelo via Digitalmars-d-learn digitalmars-d-learn at puremagic.com
Mon Feb 6 06:26:35 PST 2017


On Tuesday, 4 August 2015 at 08:18:50 UTC, Marc Schütz wrote:
>         void opIndexAssign(U : T)(size_t index, auto ref U 
> value) {

Careful here, you've got the arguments reversed. The unit test 
didn't detect this because it was ambiguous. This one isn't:

     unittest {
         OneBasedArray!int arr;
         arr = [1,2,3];
         arr ~= 14;
         assert(arr.length == 4);
         assert(arr[1] == 1);
         assert(arr[2] == 2);
         assert(arr[3] == 3);
         assert(arr[4] == 14);
     }



More information about the Digitalmars-d-learn mailing list