Boost logo

Boost Users :

Subject: Re: [Boost-users] Passing lambda placeholders to functions
From: Zachary Turner (divisortheory_at_[hidden])
Date: 2009-06-23 17:11:16


On Tue, Jun 23, 2009 at 2:52 PM, Steven Watanabe<watanabesj_at_[hidden]> wrote:
> 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 <boost/lambda/lambda.hpp>
> #include <boost/lambda/bind.hpp>
> #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?


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