Removal from std.container.Array.
Steven Schveighoffer
schveiguy at yahoo.com
Mon Feb 10 13:54:58 PST 2014
On Mon, 10 Feb 2014 16:47:34 -0500, Ty Overby <ty at pre-alpha.com> wrote:
> So I'm using a std.container.Array for storing systems in my program,
> and I need to search through the array to find the system that I want to
> remove and then shift from that.
>
> In Java I'd write
>
> ArrayList<System> systems;
> ....
> systems.remove(system);
>
> And in D I was hoping to write
>
> Array!System systems;
> ....
> systems.linearRemove(systems.equalRange(system));
>
> But for some reason equalRange isn't defined on std.container.Array, nor
> is it a module function.
equalRange is only valid for sorted containers or at least containers
where the complexity to iterate over the range is sublinear. An array
search would be linear.
> I also tried
>
> systems.linearRemove(systems[].filter!(a => a == system));
>
> but FilterResult isn't the same type as Array.Range.
>
>
> I have to be missing something really basic. It couldn't possibly be
> this hard to remove an element from an array.
Typically in STL, you use partition and then delete the partitioned
elements.
I would look for something like that, maybe someone with more experience
with std.algorithm can chime in.
-Steve
More information about the Digitalmars-d-learn
mailing list