I want to know if it is possible to chain a bunch of lambdas so that I can use them all at once, something like this:
std::vector<int> vec{1, 2, 3};
auto f1 = [](int i){return i == 1;};
auto f2 = [](int i){return i == 2;};
// What template type can I use for logical_or ?
auto f = combine(std::logical_or, f1, f2);
vec.erase(std::remove_if(vec.begin(), vec.end(), f), vec.end());
So far I was thinking something like this:
template <typename OP, typename T>
T combine(const OP& op, const T& t1, const T& t2) {
return t1 op t2;
}
template <typename OP, typename T, typename... Ts>
T combine(const OP& op, const T& t1, const T& t2, const Ts&... ts) {
return t1 op t2 op combine(op, ts...);
}
But lambda || lambda doesn't make sense.
Is what I'm trying to do possible?
op(t1(arg), t2(arg))auto f = [&](int i) { return f1(i) || f2(i); };?vec.erase(std::remove_if(vec.begin(), vec.end(), f), vec.end());is problematic? The outererasecall seems to be useless.