|
Boost Users : |
From: Minkoo Seo (minkoo.seo_at_[hidden])
Date: 2006-07-31 09:57:07
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 <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 == 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<int, std::allocator<int> >::push_back(const
boost::lambda::lambda_functor<boost::lambda::placeholder<1> >&)'
/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
Boost-users list run by williamkempf at hotmail.com, kalb at libertysoft.com, bjorn.karlsson at readsoft.com, gregod at cs.rpi.edu, wekempf at cox.net