Removing an object from a range

Matthias Walter xammy at xammy.homelinux.net
Sun Dec 12 20:37:02 PST 2010


On 12/12/2010 08:43 PM, Andrej M. wrote:
> I can't seem to find an easy remove method in std.algorithm that takes an object and a range (an array in this case) and removes any matches from the range. I'm using this snippet for now:
>
> private DrawingElement[] elements;
>
> public override void Remove(DrawingElement d)
> {
>     foreach (i, child; elements)
>     {
>         if (child == d)
>         {
>             elements = remove(elements, i);
>             break;
>         }
>     }
> }
Just want to mention that this code does not remove "any matches",  but
only the first one! So if you want all removed, you have to improve it a
bit.

Matthias


More information about the Digitalmars-d-learn mailing list