Boost logo

Boost Users :

From: Minkoo Seo (minkoo.seo_at_[hidden])
Date: 2006-08-23 03:25:51


Hi list.

I've got a question on calling map::insert using bind. What I'd like to
do is to copy all members in m into m2:

#include <iostream>
#include <algorithm>
#include <map>
#include <utility>
#include <boost/lambda/algorithm.hpp>
#include <boost/lambda/lambda.hpp>
#include <boost/lambda/bind.hpp>

using namespace std;
using namespace boost::lambda;

int main()
{
    map<string, int> m;
    map<string, int> m2;

    m["a"] = 1;
    m["b"] = 2;

    m2["c"] = 3;

    for_each(m.begin(), m.end(),
        bind(&map<string, int>::insert, &m2,
                 bind(&make_pair,
                     bind(&map<string, int>::value_type::first, _1),
                     bind(&map<string, int>::value_type::second, _1))));

    return EXIT_SUCCESS;
}

Unfortunately, the above code fails to compile and I have no idea
why it fails. I'm using g++ and the errors are as follows:

g++ map_test.cpp
map_test.cpp: In function 'int main()':
map_test.cpp:26: error: no matching function for call to 'bind(<unknown
type>, const
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<const std::basic_string<char, std::char_traits<char>,
std::allocator<char> > std::pair<const std::basic_string<char,
std::char_traits<char>, std::allocator<char> >, int>::* const, 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> > >, const
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 std::pair<const std::basic_string<char,
std::char_traits<char>, std::allocator<char> >, int>::* const, 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> > >)'

Any idea on this?

Sincerely,
Minkoo Seo

-- 
View this message in context: http://www.nabble.com/calling-map%3A%3Ainsert-through-bind.-tf2150829.html#a5939489
Sent from the Boost - Users forum at Nabble.com.

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