Arrays are sufficient for ArrayLists? Really??
Andrei Alexandrescu
SeeWebsiteForEmail at erdani.org
Mon May 16 06:52:55 PDT 2011
On 05/16/2011 04:54 AM, Mehrdad wrote:
> Hi!
>
> I posted this question on StackOverflow about D:
>
> http://stackoverflow.com/questions/6015008/how-to-delete-an-element-
> from-an-array-in-d
>
> and the answers are quite surprising to me.
>
> Are arrays really supposed to be substitutes for array lists if we
> can't remove anything from them? It seems to me like that's a really
> basic feature we're missing here... it's really annoying whenever I
> find out that each of my arrays needs its own "counter" variable,
> even though it already has a length and a capacity.
>
> Doesn't that mean we still need an ArrayList(T) type, as powerful as
> arrays are supposed to be in D?
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.
Andrei
More information about the Digitalmars-d
mailing list