Filter a Range Based on a Passed In Variable
jsako
spam at spam.com
Sat Jan 20 19:04:06 UTC 2018
I want to be able to filter a range based on a variable known at
runtime. Something like this:
[code]
int id = getFilterID();
auto filteredRange = filter!(a => a.id == id)(rangeToBeFiltered);
[/code]
This doesn't seem to be possible, however as .filter only takes
unary predicates. I tried:
[code]
filterString = "a.id == " ~ to!string(id);
filter!filterString(rangeToBeFiltered);
[/code]
But that also doesn't work. Is there another range algorithm that
should be used in this case? Do I roll my own?
More information about the Digitalmars-d-learn
mailing list