Boost logo

Boost Users :

From: Mattias Brändström (thebrasse_at_[hidden])
Date: 2004-08-30 03:33:46


Hello,

I really like the BLL and would like to use it as much as possible. I
have run into a small problem though. My code looks like this:

#include <boost/lambda/bind.hpp>
#include <boost/lambda/lambda.hpp>

#include <map>
#include <vector>

class A
{
public:
   A(int a, int b) : a_(a), b_(b) { }
   int a_;
   int b_;
};

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

   std::vector<A> v;
   v.push_back(A(1, 2));

   typedef std::map<int, int> Map;
   Map m;

   for_each(v.begin(), v.end(),
            bind(&Map::insert,
                 std::make_pair(bind(&A::a_, _1), bind(&A::b_, _1))));

   return 0;
}

What I want to do is to populate a map with the information from the
vetctor v. For each element in v I want to insert a value and a key into
the map something like this:

void operator()(const A& a) const {
    m_.insert(std::make_pair(a.a_, a.b_));
}

I found some information on how to use member variables as targets in
the BLL documentation and that is what I have tried to use in the code
above. It won't compile however, using g++ I get the following error:

g++ -c -o test.o test.cpp
test.cpp: In function `int main()':
test.cpp:27: error: no matching function for call to `bind(<unknown type>,
 
std::pair<boost::lambda::lambda_functor<boost::lambda::lambda_functor_base<boost::lambda::action<2,
    boost::lambda::function_action<2, boost::lambda::detail::unspecified> >,
    boost::tuples::tuple<int A::*, const
    boost::lambda::lambda_functor<boost::lambda::placeholder<1> >,
    boost::tuples::null_type, boost::tuples::null_type,
    boost::tuples::null_type, boost::tuples::null_type,
    boost::tuples::null_type, boost::tuples::null_type,
    boost::tuples::null_type, boost::tuples::null_type> > >,
 
boost::lambda::lambda_functor<boost::lambda::lambda_functor_base<boost::lambda::action<2,
    boost::lambda::function_action<2, boost::lambda::detail::unspecified> >,
    boost::tuples::tuple<int A::*, const
    boost::lambda::lambda_functor<boost::lambda::placeholder<1> >,
    boost::tuples::null_type, boost::tuples::null_type,
    boost::tuples::null_type, boost::tuples::null_type,
    boost::tuples::null_type, boost::tuples::null_type,
    boost::tuples::null_type, boost::tuples::null_type> > > >)'
scons: *** [test.o] Error 1
scons: building terminated because of errors.

If someone here has any ideas of how to accomplish this it would be
really nice!

Thanks in advance!

Regards,
Mattias


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