Is it possible/achievable to negate a boost filtered adaptor, e.g.
std::vector<int> v = {1, 2, 3, 4, 5};
for(auto i : v | !filtered(is_even))
std::cout << i << std::endl; // prints 1,3,5
instead of doing the negation inside the lambda expression?
Motivation: I work a lot with filtered and lambda functions, however when I use a filter more than once I usually refactor it into a custom filter, e.g.
for(auto i : v | even) // note: my filters are more complex than even.
std::cout << i << std::endl; // prints 2,4
Right now when I need the negation I am building a custom filter for them, e.g.
for(auto i : v | not_even)
std::cout << i << std::endl; // prints 1,2,3
but I would find it nicer to just be able to negate a filter, e.g.
for(auto i : v | !even)
std::cout << i << std::endl; // prints 1,2,3
return i % 2 != 0;
instead since it's easier? – Karonkarossfor(auto& i : v | filtered(!is_even))
? I actually think that's the cleanest solution I can see. – Karonkarossoperator!
on your adaptor type, such that it returns a negated form of itself. A simple matter of programming. – Lexicalconst auto not_even = filter(not_(even));
is really as clear at it can get. – Alliterate