Boost logo

Boost Users :

From: David A. Greene (greened_at_[hidden])
Date: 2006-01-24 10:27:19


David A. Greene wrote:
> I'm having some trouble with BLL and Boost.Function in this simple
> testcase:

I worked around the problem using Boost.Function:

int main(void)
{
   Test tester;
   int value = 10;

   boost::function<void (int)> bound = boost::lambda::bind(&Test::foo,
&tester, boost::lambda::_1);
   Caller<boost::function<void (void)> >
printer(boost::lambda::bind(bound, value));
   //Caller<boost::function<void (void)> >
printer(boost::lambda::bind(boost::lambda::bind(&Test::foo, &tester,
boost::lambda::_1), value));

   printer.bar();

   return(0);
}

I have a couple of questions and another problem, however.

I had to pass "&tester" to the first bind expression because g++
complained about passing "tester" as "const Test &." Is passing by
reference supposed to work?

Also, this workaround gets rid of the error but is the original code
supposed to work as written or did I do something incorrectly?

Finally, the new problem, closer to the actual code I'm working with:

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

#include <iostream>

class Test {
public:
   void foo(int a) { std::cout << "a is " << a << std::endl; };
};

template<typename Function>
class Caller {
private:
   Function func;

public:
   Caller(Function f) : func(f) {};

   void bar(void) { func(); };
};

int main(void)
{
   boost::shared_ptr<Test> tester(new Test);
   int value = 10;

   boost::function<void (int)> bound = boost::lambda::bind(&Test::foo,
tester, boost::lambda::_1);
   Caller<boost::function<void (void)> >
printer(boost::lambda::bind(bound, value));

   printer.bar();

   return(0);
}

g++ comaplains (full trace below):

lambda4.cc:28: instantiated from here
/usr/include/boost/lambda/detail/actions.hpp:96: error: no matching
function for call to 'boost::lambda::function_adaptor<void
(Test::*)(int)>::apply(void (Test::* const&)(int), const
boost::shared_ptr<Test>&, int&)'
/usr/include/boost/lambda/detail/function_adaptors.hpp:245: note:
candidates are: static Result boost::lambda::function_adaptor<Result
(Object::*)(Arg1)>::apply(Result (Object::*)(Arg1), Object*, A1&) [with
RET = void, A1 = int, Object = Test, Arg1 = int, Result = void]
/usr/include/boost/lambda/detail/function_adaptors.hpp:249: note:
           static Result boost::lambda::function_adaptor<Result
(Object::*)(Arg1)>::apply(Result (Object::*)(Arg1), Object&, A1&) [with
RET = void, A1 = int, Object = Test, Arg1 = int, Result = void]
/usr/include/boost/lambda/detail/actions.hpp:96: error: return-statement
with a value, in function returning 'void'

Any ideas? I'd rather not use .get() because of the potential
deallocation that might happen out from under the bound function.

                                  -Dave

--------------------
/usr/include/boost/lambda/detail/actions.hpp: In static member function
'static RET boost::lambda::function_action<3, T>::apply(A1&, A2&, A3&)
[with RET = void, A1 = void (Test::* const)(int), A2 = const
boost::shared_ptr<Test>, A3 = int, T = boost::lambda::detail::unspecified]':
/usr/include/boost/lambda/detail/lambda_functor_base.hpp:425:
instantiated from 'RET
boost::lambda::lambda_functor_base<boost::lambda::action<3, Act>,
Args>::call(A&, B&, C&, Env&) const [with RET = void, A = int, B = const
boost::tuples::null_type, C = const boost::tuples::null_type, Env =
const boost::tuples::null_type, Act = boost::lambda::function_action<3,
boost::lambda::detail::unspecified>, Args = boost::tuples::tuple<void
(Test::* const)(int), const boost::shared_ptr<Test>, 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>]'
/usr/include/boost/lambda/detail/lambda_functors.hpp:148: instantiated
from 'typename T::sig<boost::tuples::tuple<A&, 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
boost::lambda::lambda_functor<Base>::operator()(A&) const [with A = int,
T = boost::lambda::lambda_functor_base<boost::lambda::action<3,
boost::lambda::function_action<3, boost::lambda::detail::unspecified> >,
boost::tuples::tuple<void (Test::* const)(int), const
boost::shared_ptr<Test>, 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> >]'
/usr/include/boost/function/function_template.hpp:136: instantiated
from 'static void
boost::detail::function::void_function_obj_invoker1<FunctionObj, R,
T0>::invoke(boost::detail::function::any_pointer, T0) [with FunctionObj
=
boost::lambda::lambda_functor<boost::lambda::lambda_functor_base<boost::lambda::action<3,
boost::lambda::function_action<3, boost::lambda::detail::unspecified> >,
boost::tuples::tuple<void (Test::* const)(int), const
boost::shared_ptr<Test>, 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> > >, R = void, T0 = int]'
/usr/include/boost/function/function_template.hpp:479: instantiated
from 'void boost::function1<R, T0, Allocator>::assign_to(FunctionObj,
boost::detail::function::function_obj_tag) [with FunctionObj =
boost::lambda::lambda_functor<boost::lambda::lambda_functor_base<boost::lambda::action<3,
boost::lambda::function_action<3, boost::lambda::detail::unspecified> >,
boost::tuples::tuple<void (Test::* const)(int), const
boost::shared_ptr<Test>, 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> > >, R = void, T0 = int, Allocator =
std::allocator<void>]'
/usr/include/boost/function/function_template.hpp:430: instantiated
from 'void boost::function1<R, T0, Allocator>::assign_to(Functor) [with
Functor =
boost::lambda::lambda_functor<boost::lambda::lambda_functor_base<boost::lambda::action<3,
boost::lambda::function_action<3, boost::lambda::detail::unspecified> >,
boost::tuples::tuple<void (Test::* const)(int), const
boost::shared_ptr<Test>, 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> > >, R = void, T0 = int, Allocator =
std::allocator<void>]'
/usr/include/boost/function/function_template.hpp:294: instantiated
from 'boost::function1<R, T0, Allocator>::function1(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<3,
boost::lambda::function_action<3, boost::lambda::detail::unspecified> >,
boost::tuples::tuple<void (Test::* const)(int), const
boost::shared_ptr<Test>, 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> > >, R = void, T0 = int, Allocator =
std::allocator<void>]'
/usr/include/boost/function/function_template.hpp:637: instantiated
from 'boost::function<R ()(T0), Allocator>::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<3,
boost::lambda::function_action<3, boost::lambda::detail::unspecified> >,
boost::tuples::tuple<void (Test::* const)(int), const
boost::shared_ptr<Test>, 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> > >, R = void, T0 = int, Allocator =
std::allocator<void>]'
lambda4.cc:28: instantiated from here
/usr/include/boost/lambda/detail/actions.hpp:96: error: no matching
function for call to 'boost::lambda::function_adaptor<void
(Test::*)(int)>::apply(void (Test::* const&)(int), const
boost::shared_ptr<Test>&, int&)'
/usr/include/boost/lambda/detail/function_adaptors.hpp:245: note:
candidates are: static Result boost::lambda::function_adaptor<Result
(Object::*)(Arg1)>::apply(Result (Object::*)(Arg1), Object*, A1&) [with
RET = void, A1 = int, Object = Test, Arg1 = int, Result = void]
/usr/include/boost/lambda/detail/function_adaptors.hpp:249: note:
           static Result boost::lambda::function_adaptor<Result
(Object::*)(Arg1)>::apply(Result (Object::*)(Arg1), Object&, A1&) [with
RET = void, A1 = int, Object = Test, Arg1 = int, Result = void]
/usr/include/boost/lambda/detail/actions.hpp:96: error: return-statement
with a value, in function returning 'void'


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