Hi list.
I'm trying to implment copy_if using boost::lambda:
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <iterator>
#include <map>
#include
#include
#include
#include
#include
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 == 1, vi2.push_back(_1)));
return EXIT_SUCCESS;
}
This fails with the errors:
lambda_test.cpp: In function 'int main()':
lambda_test.cpp:30: error: no matching function for call to
'std::vector::push_back(const
boost::lambda::lambda_functor >&)'
/usr/lib/gcc/x86_64-redhat-linux/4.0.2/../../../../include/c++
]/4.0.2/bits/stl_vector.h:602:
note: candidates are: void std::vector<_Tp, _Alloc>::push_back(const
_Tp&) [with _Tp = int, _Alloc = std::allocator<int>]
Does anybody know how to push _1 into vi2? I've tried bind( ), but no
luck.
Sincerely,
Minkoo Seo