I am getting another compiler error when trying to use the lambda
library. Current experiment is string extraction. I'm trying to create
a lambda(x) that pushes any char passed to it onto a particular
string.
string s2;
void (std::string::*ft)(char) = &std::string::push_back;
// extract function pointer because push_back is overloaded
char c = 'n';
bind<void>(ft, var(s2), _1, 1)(c);
// should push one 'n' onto the string. However, it doesn't compile
bind<void>(reinterpret_cast(ft),
var(s2), _1, 1)(c);
// error messages made me think it might be because
push_back returns void
// I know this isn't good practice, but I'm just trying to
figure out what's wrong
// However, this won't compile either.
And then I get this error
/users/user2/ugrad/m/mdw45/boost_1_31_0/boost/lambda/detail/actions.hpp:109:
error: no
matching function for call to `boost::lambda::function_adaptor
::*)(char)>::apply(char (std::basic_string::*const&)(char), std::basic_string&, char&, const int&)'
::*const)(char), const
boost::lambda::lambda_functorstd::string& >,
const boost::lambda::lambda_functor >,
const int, 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&)(char), std::basic_string&, char&, const int&)'
/usr/include/boost/lambda/detail/actions.hpp:109: error: return-statement with
a value, in function declared with a void return type
bash-2.05b$ g++ proj1.cpp -I /users/user2/ugrad/m/mdw45/boost_1_31_0
/users/user2/ugrad/m/mdw45/boost_1_31_0/boost/lambda/detail/actions.hpp: In
static member function `static RET boost::lambda::function_action<4,
T>::apply(A1&, A2&, A3&, A4&) [with RET = void, A1 = char
(std::basic_string, A3 = char, A4 = const int, T = void]':
/users/user2/ugrad/m/mdw45/boost_1_31_0/boost/lambda/detail/lambda_functor_base.hpp:442:
instantiated from `RET
boost::lambda::lambda_functor_base,
Args>::call(A&, B&, C&, Env&) const [with RET = void, A = char, B =
const boost::tuples::null_type, C = const boost::tuples::null_type,
Env = const boost::tuples::null_type, Act =
boost::lambda::function_action<4, void>, Args =
boost::tuples::tuple::*const)(char), const
boost::lambda::lambda_functorstd::string& >,
const boost::lambda::lambda_functor >,
const int, boost::tuples::null_type, boost::tuples::null_type,
boost::tuples::null_type, boost::tuples::null_type,
boost::tuples::null_type, boost::tuples::null_type>]'
/users/user2/ugrad/m/mdw45/boost_1_31_0/boost/lambda/detail/lambda_functors.hpp:151:
instantiated from `typename T::sig >::type
boost::lambda::lambda_functor<Base>::operator()(A&) const [with A =
char, T = boost::lambda::lambda_functor_base >, boost::tuples::tuplestd::string& >,
const boost::lambda::lambda_functor >,
const int, boost::tuples::null_type, boost::tuples::null_type,
boost::tuples::null_type, boost::tuples::null_type,
boost::tuples::null_type, boost::tuples::null_type> >]'
I'm not really sure what the real problem is. Can you tell from
looking at the error message what I should be doing?
Thanks in advance
Max Wilson
(FULL ERROR TEXT FOLLOWS)
/usr/include/boost/lambda/detail/actions.hpp: In static member function `static
RET boost::lambda::function_action<4, T>::apply(A1&, A2&, A3&, A4&) [with
RET = void, A1 = char (std::basic_string::*const)(char), A2 = std::basic_string, A3 = char, A4 = const int, T
= void]':
/usr/include/boost/lambda/detail/lambda_functor_base.hpp:442:
instantiated from `RET
boost::lambda::lambda_functor_base,
Args>::call(A&, B&, C&, Env&) const [with RET = void, A = char, B =
const boost::tuples::null_type, C = const boost::tuples::null_type,
Env = const boost::tuples::null_type, Act =
boost::lambda::function_action<4, void>, Args =
boost::tuples::tuple::*const)(char), const
boost::lambda::lambda_functorstd::string& >,
const boost::lambda::lambda_functor >,
const int, 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:151:
instantiated from `typename T::sig >::type
boost::lambda::lambda_functor<Base>::operator()(A&) const [with A =
char, T = boost::lambda::lambda_functor_base >, boost::tuples::tuple::*)(char)>::apply(char
(std::basic_string
::*)(char)>::apply(char (std::basic_string::*const&)(char), std::basic_string&, char&, const int&)'
/users/user2/ugrad/m/mdw45/boost_1_31_0/boost/lambda/detail/actions.hpp:109:
error: return-statement
with a value, in function declared with a void return type
--
Sometimes I think decisions through, weigh the consequences, decide
it is not a good idea, but blind myself and make it anyway. I do not
think this is a good thing to do, but it might be. Humans are
endowed with both reason and emotion for a reason.
-Tara Greenwood