Comment by spacechild1

Comment by spacechild1 6 months ago

0 replies

> The author explained a concrete way in which the std::function abstraction leaks:

But that's not an issue with std::function at all! His comment is really about lambdas and I don't understand why he conflates these two. Just don't put the actual code in a lambda:

    std::function<void()> cb([widget]() { widget->onButtonClicked(); });
Here the code is in a method and the lambda is only used to bind an object to the method. If you are old-school, you can also do this with std::bind:

    std::function<void()> cb(std::bind(&Widget::onButtonClicked, widget));