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 bound = boost::lambda::bind(&Test::foo,
&tester, boost::lambda::_1);
Caller >
printer(boost::lambda::bind(bound, value));
//Caller >
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
#include
#include
#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 bound = boost::lambda::bind(&Test::foo,
tester, boost::lambda::_1);
Caller >
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::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::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::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,
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 >,
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 >::type
boost::lambda::lambda_functor<Base>::operator()(A&) const [with A = int,
T = boost::lambda::lambda_functor_base >,
boost::tuples::tuple >,
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::invoke(boost::detail::function::any_pointer, T0) [with FunctionObj
=
boost::lambda::lambda_functor >,
boost::tuples::tuple >,
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::assign_to(FunctionObj,
boost::detail::function::function_obj_tag) [with FunctionObj =
boost::lambda::lambda_functor >,
boost::tuples::tuple >,
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::assign_to(Functor) [with
Functor =
boost::lambda::lambda_functor >,
boost::tuples::tuple >,
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::function1(Functor, typename
boost::enable_if_c::value,
int>::type) [with Functor =
boost::lambda::lambda_functor >,
boost::tuples::tuple >,
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::function(Functor, typename
boost::enable_if_c::value,
int>::type) [with Functor =
boost::lambda::lambda_functor >,
boost::tuples::tuple >,
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::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::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::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'