array idioms
Andrej Mitrovic
andrej.mitrovich at gmail.com
Fri Feb 25 12:51:53 PST 2011
I have asked for remove before, I got some responses here (in fact,
Jonathan made an enhancement request for it):
http://www.digitalmars.com/d/archives/digitalmars/D/learn/Removing_an_object_from_a_range_23212.html
The topic was derailed, but essentially you can provide a predicate as
a function literal to do the work:
import std.stdio;
import std.algorithm;
void main()
{
int[] elements = [1, 2, 3, 2, 4];
int needle = 2;
elements = remove!((item) {return item == needle;} )(elements);
assert(elements == [1, 3, 4]);
}
More information about the Digitalmars-d-learn
mailing list