Arrays are sufficient for ArrayLists? Really??

Mehrdad wfunction at hotmail.com
Mon May 16 11:29:31 PDT 2011


> They're called Arrays, not Lists (or ArrayLists), so way would you expect a delete functions?

I thought they're supposed to substitute for lists (otherwise we'd have an ArrayList type in
Phobos).


> If you want something like an ArrayList in D, have a look at std.container.Array :-)

That doesn't work well the the garbage collector. :\


> As has been mentioned, std.algorithm.remove can be of help. You may want to look at three of its
capabilities in particular: (a) remove multiple offsets in one pass, e.g. remove(a, 0, 4) removes
the first and fifth element, (b) you can remove subranges, e.g. remove(a, tuple(1, 3)) removes the
second through fourth element, and (c) if you don't care about the order in which elements are left
after removal you may want to look into unstable remove, which does considerably less work.

Thanks for the idea. This seems great, except for a couple of things:

- I _do_ need the order to stay the same, so I can't just put in the last element.

- I only need to remove one element at a time.

- I still don't understand how this helps. Either this modifies the array directly, in which case
adding a new element to the array after a removal would still cause a reallocation every time, or
this returns a filtered range, in which case it doesn't do what I need (since it doesn't modify the
array directly)... am I missing something?


More information about the Digitalmars-d mailing list