bind, lambda 를 사용한 copy_if

Tags:

#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <iterator>
#include <map>

#include <boost/lambda/lambda.hpp>
#include <boost/lambda/if.hpp>
#include <boost/format.hpp>
#include <boost/lambda/bind.hpp>
#include <boost/lambda/algorithm.hpp>

using namespace std;
using namespace boost::lambda;


int main()
{
    vector<int> vi;
    vi.push_back(1);
    vi.push_back(2);
    vi.push_back(3);
    vi.push_back(4);
    vi.push_back(5);

    vector<int> vi2;

    for_each(vi.begin(), vi.end(),
             if_then(_1 % 2 == 0, bind(&vector<int>::push_back, &vi2, _1)));

    copy(vi2.begin(), vi2.end(), ostream_iterator<int>(cout, " "));

    return EXIT_SUCCESS;
}