Sign in to follow this  
Storyyeller

huge template error with boost lambda

Recommended Posts

Storyyeller    215
I am trying and failing to use boost lambda at the moment. Does anyone know what these errors mean? Is there anyway to automatically format these errors so it's at least easier to read? ..\zHeaders\boost\lambda\detail\lambda_functor_base.hpp|405|instantiated from `RET boost::lambda::lambda_functor_base<boost::lambda::action<2, Act>, Args>::call(A&, B&, C&, Env&) const [with RET = void, A = const boost::tuples::null_type, B = const boost::tuples::null_type, C = const boost::tuples::null_type, Env = const boost::tuples::null_type, Act = boost::lambda::function_action<2, boost::lambda::detail::unspecified>, Args = boost::tuples::tuple<void (* const)(Portal::ScaffoldController*, char), const boost::lambda::lambda_functor<boost::lambda::lambda_functor_| ..\zHeaders\boost\lambda\detail\lambda_functors.hpp|138|instantiated from `typename T::sig<boost::tuples::null_type>::type boost::lambda::lambda_functor<Base>::operator()() const [with T = boost::lambda::lambda_functor_base<boost::lambda::action<2, boost::lambda::function_action<2, boost::lambda::detail::unspecified> >, boost::tuples::tuple<void (* const)(Portal::ScaffoldController*, char), const boost::lambda::lambda_functor<boost::lambda::lambda_functor_base<boost::lambda::other_action<boost::lambda::comma_action>, boost::tuples::tuple<boost::lambda::lambda_f| ..\zHeaders\boost\function\function_template.hpp|152|instantiated from `static void boost::detail::function::void_function_obj_invoker0<FunctionObj, R>::invoke(boost::detail::function::function_buffer&) [with FunctionObj = 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<void (* const)(Portal::ScaffoldController*, char), const boost::lambda::lambda_functor<boost::lambda::lambda_functor_base<boost::lambda::other_action<boost::| ..\zHeaders\boost\function\function_template.hpp|904|instantiated from `void boost::function0<R>::assign_to(Functor) [with Functor = 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<void (* const)(Portal::ScaffoldController*, char), const boost::lambda::lambda_functor<boost::lambda::lambda_functor_base<boost::lambda::other_action<boost::lambda::comma_action>, boost::tuples::tuple<boost::lambda::lambda_functor<boost::lambda::l| ..\zHeaders\boost\function\function_template.hpp|720|instantiated from `boost::function0<R>::function0(Functor, typename boost::enable_if_c< boost::type_traits::ice_not< boost::is_integral<Functor>::value>::value, int>::type) [with Functor = 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<void (* const)(Portal::ScaffoldController*, char), const boost::lambda::lambda_functor<boost::lambda::lambda_functor_base<boost::lambda::o| ..\zHeaders\boost\function\function_template.hpp|1041|instantiated from `boost::function<R ()()>::function(Functor, typename boost::enable_if_c< boost::type_traits::ice_not< boost::is_integral<Functor>::value>::value, int>::type) [with Functor = 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<void (* const)(Portal::ScaffoldController*, char), const boost::lambda::lambda_functor<boost::lambda::lambda_functor_base<boost::lambda| C:\ActiveProjects\Pickory\Portal\scaffold.cpp|68|instantiated from here| ..\zHeaders\boost\lambda\detail\actions.hpp|86|error: no matching function for call to `boost::lambda::function_adaptor<void (*)(Portal::ScaffoldController*, char)>::apply(void (* const&)(Portal::ScaffoldController*, char), const char&)'| ..\zHeaders\boost\lambda\detail\actions.hpp|86|error: return-statement with a value, in function returning 'void'| ||=== Build finished: 2 errors, 0 warnings ===| By the way, here's the code that caused those errors. It's supposed to create a functor which will call get() on a shared pointer, and then output the value of that pointer.
    template <class T>
    inline void Debug(T message, char endc = '\n')
    {
        std::cout << message << endc;
    }

typedef boost::function<void ()> voidFunct_void;
typedef boost::shared_ptr<ScaffoldController> scaffcont_sptr;

    voidFunct_void ScaffoldCallback(scaffcont_wptr parent)
    {
        scaffcont_sptr testptr; //Should cause an assertion failure when the functor is called, but this is just a test
        return boost::lambda::bind(&Debug<ScaffoldController*>, ( boost::lambda::bind(&scaffcont_sptr::get, testptr), '?'));
    }



[Edited by - Storyyeller on March 15, 2010 8:02:22 PM]

Share this post


Link to post
Share on other sites
El Greco    182
You added a few parenthesis too many, change your call into:


return boost::lambda::bind
( &Debug<ScaffoldController*> // Function to bind
, boost::lambda::bind(&scaffcont_sptr::get, testptr) // First argument
, '?' // Second argument
);

Share this post


Link to post
Share on other sites
Storyyeller    215
Thanks, that worked.

Of course, I'm having second thoughts about Boost Lambda due to all the code required just to do a simple task. I think I may be better off using handwritten functor objects.

Share this post


Link to post
Share on other sites
El Greco    182
Boost lambda is usefull for creating functors inside algorithm calls, such as std::for_each and so. I personally never use it for anything else.

If I want to create function objects to pass around function calls and their arguments, I use boost::bind (without lambda) and boost::function most of the time.

What is it you are trying to do?

Share this post


Link to post
Share on other sites
Storyyeller    215
I was trying to wrap a weak pointer for a callback.

Sort of like this, except with Boost Lambda.

template <class T>
class WeakFunctor
{
typedef boost::shared_ptr<T> t_sptr;
typedef boost::weak_ptr<T> t_wptr;
typedef boost::function<void (T*)> voidfunct;

t_wptr myobject;
voidfunct myfunc;

public:
WeakFunctor( t_wptr object, voidfunct memfunc )
:myobject(object), myfunc(memfunc) {}

void operator ()()
{
t_sptr lockedobject = myobject.lock();

if(lockedobject)
{
myfunc(lockedobject.get());
}
}
};


Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this