std.algorithm.remove from array of custom classes?
Andrea Fontana via Digitalmars-d-learn
digitalmars-d-learn at puremagic.com
Wed Dec 9 05:29:36 PST 2015
On Wednesday, 9 December 2015 at 13:23:00 UTC, Tim K. wrote:
> On Wednesday, 9 December 2015 at 13:13:36 UTC, BBaz wrote:
>
>> 1) remove works with an index
> I guess I did read it wrong. Sorry.
> Is there a convenience function that allows me to remove an/all
> object(s) with a certain value from an array or do I need to
> write one myself?
>
>> 2) remove does not remove in place
> That's fine.
void main(string[] argv)
{
A a = new A("a", 1);
A b = new A("b", 2);
A[] as = [a, b];
as = as.remove!(x => x == a);
writeln(as);
}
If array is sorted you can find the index of that element and
then remove it by index.
More information about the Digitalmars-d-learn
mailing list