Arrays are sufficient for ArrayLists? Really??

Steven Schveighoffer schveiguy at yahoo.com
Mon May 16 12:52:05 PDT 2011


On Mon, 16 May 2011 15:53:38 -0400, Timon Gehr <timon.gehr at gmx.ch> 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 .. $];
> }

Hehe, won't work.  Ranges can only support a single foreach parameter.

I think you may have to resort to for loops here (/me purposely ignores  
the hideous beast foreach_reverse).  Be very careful with indexes on that  
one.

-Steve


More information about the Digitalmars-d mailing list