On Tue, Jun 23, 2009 at 2:52 PM, Steven Watanabe
AMDG
Zachary Turner wrote:
Thanks. On a related note, if a lambda placeholder refers to a structure, is there any way to access its members short of using bind and making a fake function to perform the access?
For example
struct foo { int x; int y; }; struct bar { int x, int y; };
foo f;
options.add_options() ("test", value<bar>()->notifier( var(f.x) = _1.x)));
is what I want. I've tried a variety of different things, most promising seemed to be
options.add_options() ("test", value<bar>()->notifier( var(f.x) = bind(&bar::x, _1)));
but this doesn't work either.
It ought to work. What's the error?
The following works for me:
#include
#include #include <iostream> struct foo { int x; int y; }; struct bar { int x; int y; };
int main() { foo f = { 1, 2 }; const bar b = { 3, 4 }; (boost::lambda::var(f.x) = boost::lambda::bind(&bar::x, boost::lambda::_1))(b); std::cout << f.x << std::endl; }
Ok so the problem is that I was using boost::bind instead of boost::lambda::bind. Should only boost::lambda::bind be used inside lambda expressions? And why isn't there just a single bind that works in all cases?