Boost.Bindで述語を否定する

boost::bindでoperator!()が使えたようです。知らなかった。

#include <iostream>
#include <vector>
#include <boost/range/adaptor/filtered.hpp>
#include <boost/range/algorithm/for_each.hpp>
#include <boost/bind.hpp>

bool is_even(int x) { return x % 2 == 0; }
void disp(int x) { std::cout << x << ' '; }

int main()
{
    using namespace boost::adaptors;

    const std::vector<int> v = {1, 2, 3, 4, 5};

    boost::for_each(v | filtered( boost::bind(&is_even, _1)), disp); std::cout << std::endl;
    boost::for_each(v | filtered(!boost::bind(&is_even, _1)), disp);
}
2 4 
1 3 5