Arrays are sufficient for ArrayLists? Really??
Mehrdad
wfunction at hotmail.com
Mon May 16 12:52:23 PDT 2011
On 5/16/2011 12:53 PM, Timon Gehr wrote:
>> In fact I even need to take that back. In order to work correctly, the
>> function would have to iterate downwards. It _is_ indeed buggy, and I
>> should stop emitting opinions when I'm short on time...
>>
>> Andrei
>
> Whoops, you are right:
>
> void removeAt(T)(ref T[] arr, size_t index)
> {
> foreach (i, ref item; retro(arr[1 .. index+1]))
> item = arr[i - 1];
> arr = arr[1 .. $];
> }
>
> Timon
Wouldn't that stomp on the super-slice of arr, though?
As was pointed out on SO, the problem is actually always there: if
someone passes arr[0 .. $] to a function, it will look as if the
original array was passed, although it wasn't. Seems like it's a lot
uglier than I'd thought...
More information about the Digitalmars-d
mailing list