Boost logo

Boost Users :

From: Arturo_Cuebas_at_[hidden]
Date: 2005-02-18 11:39:44


Given:

#include <map>
#include <boost/mem_fn.hpp>
#include <boost/function.hpp>
#include <boost/lambda/lambda.hpp>
#include <boost/lambda/bind.hpp>

using namespace std;
using namespace boost;
using namespace boost::lambda;

struct s
{
   int key (){return 1;}
   int value(){return 2;}
};

typedef map<int, int> int_map;
int_map m;
var_type<int_map>::type delayed_m(var(m));

template<class F>
void execute(F f)
{
   s o;
   f(o);
}

Why does this work?:

int main()
{
   execute
   (
      delayed_m[lambda::bind(&s::key, lambda::_1)] =
                lambda::bind(&s::value, lambda::_1)
   );
}

But this doesn’t?:

int main()
{
   function<int (s &)> key (mem_fn(&s::key )),
                       value(mem_fn(&s::value));

   execute
   (
      delayed_m[key] = value //compile error instantiation backtrace leads
to here
   );
}

I’m using VC7.1.

Here's the error (sorry that it's so noisy):

c:\Program Files\Microsoft Visual Studio .NET
2003\Vc7\include\boost\lambda\detail\operator_lambda_func_base.hpp(255) :
error C2440: '=' : cannot convert from 'const
boost::tuples::cons<HT,TT>::stored_head_type' to 'int'
        with
        [
            HT=const boost::lambda::detail::parameter_traits_<const
boost::function<int (s &)>,const boost::lambda::detail::IF<false,const
boost::function<int (s &)> &,const boost::function<int (s
&)>>::RET>::type,
 
TT=boost::tuples::detail::map_tuple_to_cons<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::tuples::null_type,boost::tuples::null_type>::type
        ]
        No user-defined-conversion operator available that can perform
this conversion, or the operator cannot be called
        c:\Program Files\Microsoft Visual Studio .NET
2003\Vc7\include\boost\lambda\detail\lambda_functors.hpp(153) : see
reference to function template instantiation 'RET
boost::lambda::lambda_functor_base<Act,Args>::call<boost::lambda::lambda_functor_base<Act,Args>::sig<SigArgs>::type,A,const
boost::tuples::null_type,const boost::tuples::null_type,const
boost::tuples::null_type>(A &,B &,C &,Env &) const' being compiled
        with
        [
 
RET=boost::lambda::lambda_functor_base<boost::lambda::other_action<boost::lambda::assignment_action>,boost::tuples::tuple<boost::lambda::lambda_functor<boost::lambda::lambda_functor_base<boost::lambda::other_action<boost::lambda::subscript_action>,boost::tuples::tuple<boost::lambda::lambda_functor<boost::lambda::identity<int_map
&>>,const boost::lambda::detail::parameter_traits_<const
boost::function<int (s &)>,const boost::lambda::detail::IF<false,const
boost::function<int (s &)> &,const boost::function<int (s
&)>>::RET>::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::tuples::null_type>>>,const
boost::lambda::detail::parameter_traits_<const boost::function<int (s
&)>,const boost::lambda::detail::IF<false,const boost::function<int (s &)>
&,const boost::function<int (s
&)>>::RET>::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::tuples::null_type>>::sig<boost::tuples::tuple<s
&,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::tuples::null_type>>::type,
 Act=boost::lambda::other_action<boost::lambda::assignment_action>,
 
Args=boost::tuples::tuple<boost::lambda::lambda_functor<boost::lambda::lambda_functor_base<boos
t::lambda::other_action<boost::lambda::subscript_action>,boost::tuples::tuple<boost::lambda::lambda_functor<boost::lambda::identity<int_map
&>>,const boost::lambda::detail::parameter_traits_<const
boost::function<int (s &)>,const boost::lambda::detail::IF<false,const
boost::function<int (s &)> &,const boost::function<int (s
&)>>::RET>::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::tuples::null_type>>>,const
boost::lambda::detail::parameter_traits_<const boost::function<int (s
&)>,const boost::lambda::detail::IF<false,const boost::function<int (s &)>
&,const boost::function<int (s
&)>>::RET>::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::tuples::null_type>,
            SigArgs=boost::tuples::tuple<s
&,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::tuples::null_type>,
            A=s,
            B=const boost::tuples::null_type,
            C=const boost::tuples::null_type,
            Env=const boost::tuples::null_type
        ]
        c:\TestApps\GeneralTests\GeneralTests.cpp(27) : see reference to
function template instantiation
'boost::lambda::lambda_functor_base<Act,Args>::sig<SigArgs>::type
boost::lambda::lambda_functor<T>::operator ()<s>(A &) const' being
compiled
        with
        [
 Act=boost::lambda::other_action<boost::lambda::assignment_action>,
 
Args=boost::tuples::tuple<boost::lambda::lambda_functor<boost::lambda::lambda_functor_base<boost::lambda::other_action<boost::lambda::subscript_action>,boost::tuples::tuple<boost::lambda::lambda_functor<boost::lambda::identity<int_map
&>>,const boost::lambda::detail::parameter_traits_<const
boost::function<int (s &)>,const boost::lambda::detail::IF<false,const
boost::function<int (s &)> &,const boost::function<int (s
&)>>::RET>::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::tuples::null_type>>>,const
boost::lambda::detail::parameter_traits_<const boost::function<int (s
&)>,const boost::lambda::detail::IF<false,const boost::function<int (s &)>
&,const boost::function<int (s
&)>>::RET>::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::tuples::null_type>,
            SigArgs=boost::tuples::tuple<s
&,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::tuples::null_type>,
 
T=boost::lambda::lambda_functor_base<boost::lambda::other_action<boost::lambda::assignment_action>,boost::tuples::tuple<boost::lambda::lambda_functor<boost::lambda::lambda_functor_base<boost::lambda::other_action<boost::lambda::subscript_action>,boost::tuples::tuple<boost::lambda::lambda_functor<boost::lambda::identity<int_map
&>>,const boost::lambda::detail:
:parameter_traits_<const boost::function<int (s &)>,const
boost::lambda::detail::IF<false,const boost::function<int (s &)> &,const
boost::function<int (s
&)>>::RET>::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::tuples::null_type>>>,const
boost::lambda::detail::parameter_traits_<const boost::function<int (s
&)>,const boost::lambda::detail::IF<false,const boost::function<int (s &)>
&,const boost::function<int (s
&)>>::RET>::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::tuples::null_type>>,
            A=s
        ]
        c:\TestApps\GeneralTests\GeneralTests.cpp(47) : see reference to
function template instantiation 'void
Execute<boost::lambda::lambda_functor<T>>(F)' being compiled
        with
        [
 
T=boost::lambda::lambda_functor_base<boost::lambda::other_action<boost::lambda::assignment_action>,boost::tuples::tuple<boost::lambda::lambda_functor<boost::lambda::lambda_functor_base<boost::lambda::other_action<boost::lambda::subscript_action>,boost::tuples::tuple<boost::lambda::lambda_functor<boost::lambda::identity<int_map
&>>,const boost::lambda::detail::parameter_traits_<const
boost::function<int (s &)>,const boost::lambda::detail::IF<false,const
boost::function<int (s &)> &,const boost::function<int (s
&)>>::RET>::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::tuples::null_type>>>,const
boost::lambda::detail::parameter_traits_<const boost::function<int (s
&)>,const boost::lambda::detail::IF<false,const boost::function<int (s &)>
&,const boost::function<int (s
&)>>::RET>::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::tuples::null_type>>,
 
F=boost::lambda::lambda_functor<boost::lambda::lambda_functor_base<boost::lambda::other_action<boost::lambda::assignment_action>,boost::tuples::tuple<boost::lambda::lambda_functor<boost::lambda::lambda_functor_base<boost::lambda::other_action<boost::lambda::subscript_action>,boost::tuples::tuple<boost::lambda::lambda_functor<boost::lambda::identity<int_map
&>>,const boost::lambda::detail::parameter_traits_<const
boost::function<int (s &)>,const boost::lambda::detail::IF<false,const
boost::function<int (s &)> &,const boost::function<int (s
&)>>::RET>::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::tuples::null_type>>>,const
boost::lambda::detail::parameter_traits_<const boost::function<int (s
&)>,const boost::lambda::detail::IF<false,const boost::function<int (s &)>
&,const boost::function<int (s
&)>>::RET>::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::tuples::null_type>>>
        ]


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