Discussion:
storing a value in a lambda functor
(too old to reply)
Igor R.
2010-09-08 13:23:39 UTC
Permalink
Hello,

I'm trying to integrate lambdas into a legacy code. The original line
looks like this:
someQueue_->post(bind(&MyClass::func, shared_from_this()));

Now I'd like to use the new lambda feature:
someQueue_->post([&] {func()});

Of course, it captures "this" by reference, but in addition now I have
to store the result of shared_from_this() call.
Is it possible to do this without additional bind's etc?

Thanks.
Igor R.
2010-09-08 13:39:13 UTC
Permalink
Post by Igor R.
someQueue_->post([&] {func()});
Of course, it captures "this" by reference, but in addition now I have
to store the result of shared_from_this() call.
Is it possible to do this without additional bind's etc?
A little addition: I realize it's possible to define a local variable
explicitly and then to capture it by value:

auto self = shared_from_this();
someQueue_->post([&, self] {func()});

But is there a way to do the same in a less verbose way?

Thanks.

Loading...