Removing an object from a range
spir
denis.spir at gmail.com
Mon Dec 13 10:02:47 PST 2010
On Sun, 12 Dec 2010 20:43:12 -0500
"Andrej M." <none at none.com> 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.
A common idiom in various languages for remove is collection.replace(something, nothing). (This indeed works fine in D for strings :-)
Denis
-- -- -- -- -- -- --
vit esse estrany ☣
spir.wikidot.com
More information about the Digitalmars-d-learn
mailing list