How can I create a functor, which would assign to a member variable,
when invoked? I mean, something like this:
int member_;
//...
lambda::bind(my_obj::member_, this, 5);
The above bind itself compiles, but if I try to invoke it or to assign
to a function<void()>, it doesn't compile.
Thanks.
_______________________________________________
Boost-users mailing list
Boost...@lists.boost.org
http://lists.boost.org/mailman/listinfo.cgi/boost-users
Igor R wrote:
> How can I create a functor, which would assign to a member variable,
> when invoked? I mean, something like this:
>
> int member_;
> //...
>
> lambda::bind(my_obj::member_, this, 5);
>
> The above bind itself compiles, but if I try to invoke it or to assign
> to a function<void()>, it doesn't compile.
>
(lambda::var(member_) = 5)
In Christ,
Steven Watanabe
Did you mean &my_obj::member_? But anyway, it doesn't compile.
My real code should look like this:
io_service.post(lambda::var(member_)=5); // posts to another thread
and performs the assignment there
Igor R wrote:
>> (lambda::var(member_) = 5)
>>
>
> Did you mean &my_obj::member_?
No. I meant exactly what I said.
> But anyway, it doesn't compile.
>
The following works fine.
#include <boost/lambda/lambda.hpp>
#include <boost/function.hpp>
#include <cassert>
struct S {
int member_;
void f() {
boost::function<void()> f_(boost::lambda::var(member_) = 5);
f_();
}
};
int main() {
S s;
s.f();
assert(s.member_ == 5);
}
> My real code should look like this:
>
> io_service.post(lambda::var(member_)=5); // posts to another thread
> and performs the assignment there
>
In Christ,
Steven Watanabe