Removing an object from a range

Jonathan M Davis jmdavisProg at gmx.com
Sun Dec 12 18:05:54 PST 2010


On Sunday 12 December 2010 17:43:12 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;
>         }
>     }
> }
> 
> Ugly! :)
> 
> It's a direct port from some C# code so don't mind the silly variable
> names.

Hmm. I thought that there was such a functon, but apparently not. The various 
remove functions are normally implemented on a container and are listed in 
std.container. However, arrays obviously don't have them built in, so they'd 
need them in std.array (just like popFront() and the like are in std.array), but 
they aren't there. So, they obviously need to be added. They may not have been 
created yet because std.container is still fairly experimental, but certainly 
once we're sure of what std.container's remove functions should look like, 
std.array should have them for arrays.

I created an enhancement request for it: http://is.gd/iDSqj

- Jonathan M Davis


More information about the Digitalmars-d-learn mailing list