|
Boost Users : |
From: Arnaldur Gylfason (arnaldur.gylfason_at_[hidden])
Date: 2006-10-19 07:54:47
a) You want to use _1 instead of _2
b) _1/_2 are in namespace boost::lambda
boost::function<float(float)> f =
boost::lambda::bind(fx,boost::lambda::_1,2);
It is actually possible to use _2 but then the functor takes to args and
ignores the first:
boost::function<float(float,float)> f =
boost::lambda::bind(fx,boost::lambda::_2,2);
std::cout << f(100,3) << std::endl; // returns 5
cheers
Arnaldur
"Chris Weed" <chrisweed_at_[hidden]>
Sent by: boost-users-bounces_at_[hidden]
19.10.2006 05:04
Please respond to
boost-users_at_[hidden]
To
boost-users_at_[hidden]
cc
Subject
[Boost-users] [function][lambda] Create a boost function to a bind functor
Hi,
I would like to create a boost::function to a lambda::bind functor such as
float fx(float a, float b) { return a+b; }
int main()
{
boost::function<float(float)> f = boost::lambda::bind(fx,_2,2);
std::cout << f(3) << std::endl;
return 0;
}
I would expect this to bind 2 to the "b" argument of fx, and print "5".
Instead with msvc-8.0 I get a bunch or compile errors.
Any help would be greatly appreciated.
Chris
_______________________________________________
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