Boost logo

Boost Users :

From: Jaakko Jarvi (jarvi_at_[hidden])
Date: 2006-09-29 13:06:43


On Sep 29, 2006, at 9:15 AM, Patrik Jonsson wrote:

> Hi,
>
> I've used BLL off an on for a while, but right now even the most basic
> bind won't work. Two of the following three binds don't work for
> me, and
> they are basically a copy if the bind examples... At this point I'm
> sure
> I'm doing something incredibly stupid, so can someone set me straight?
>
> #include <iostream>
> #include "boost/lambda/lambda.hpp"
> #include "boost/lambda/bind.hpp"
> using namespace boost::lambda;
>
> int g(int i) {std::cout << i<<std::endl; return i;};
>
> int main() {
> bind(_1, 1)(g); // works
> bind(g, _1)(1); // nope
> bind(&g, _1)(1); // nope
> }

There are two errors in your code.
When C++ gets rvalue references, the two last calls will start
working, but at this point,
lambda functors do not accept non-const rvalues. 1 is a non-const
rvalue.

You can fix the two calls as:

   bind(g, _1)(make_const(1)); // nope
   bind(&g, _1)(make_const(1)); // nope

Or there are other ways too, see

http://www.boost.org/doc/html/lambda/
using_library.html#lambda.actual_arguments_to_lambda_functors

   Jaakko

> This is with gcc 4.0.1 and boost 1.33.1. Thanks,
>
> /Patrik
>
> The errors are:
>
> junk.cc: In function 'int main()':
> junk.cc:10: error: no match for call to '(const
> boost::lambda::lambda_functor<boost::lambda::lambda_functor_base<boost
> ::lambda::action<2,
> boost::lambda::function_action<2, int> >, boost::tuples::tuple<int
> (&)(int), 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, boost::tuples::null_type> > >) (int)'
> /Users/patrik/include/boost/lambda/detail/lambda_functors.hpp:137:
> note:
> candidates are: 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, int> >, boost::tuples::tuple<int
> (&)(int), 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, boost::tuples::null_type> >]
> /Users/patrik/include/boost/lambda/detail/lambda_functors.hpp:145:
> note: 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<2,
> boost::lambda::function_action<2, int> >, boost::tuples::tuple<int
> (&)(int), 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, boost::tuples::null_type> >]
> junk.cc:11: error: no match for call to '(const
> 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<int (* const)(int), 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, boost::tuples::null_type> > >) (int)'
> /Users/patrik/include/boost/lambda/detail/lambda_functors.hpp:137:
> note:
> candidates are: 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<int (* const)(int), 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, boost::tuples::null_type> >]
> /Users/patrik/include/boost/lambda/detail/lambda_functors.hpp:145:
> note: 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<2,
> boost::lambda::function_action<2,
> boost::lambda::detail::unspecified> >,
> boost::tuples::tuple<int (* const)(int), 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, boost::tuples::null_type> >]
>
>
> _______________________________________________
> Boost-users mailing list
> Boost-users_at_[hidden]
> http://lists.boost.org/mailman/listinfo.cgi/boost-users


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