Boost.Lambda - dereference placeholder

无人久伴 提交于 2019-12-13 04:07:01

问题


Is there a way to dereference a placeholder inside lambda expression ?

boost::function<int(MyClass*)> f = _1->myMethod();
f(myObject);

I know I can make a binding:

boost::function<int(MyClass*)> f = boost::bind(&MyClass::myMethod, _1);

, but I want to build more complex expression, with if statements and so on.


回答1:


In theory this should work:

struct Foo {
  int bla() { return 2; }
};

boost::function<int(Foo*)> func = (_1 ->* &Foo::bla);

There is an old discussion featuring various work-arounds on the Boost mailing list. All of them seem rather ugly. I'd stick with nested bindS or get a modern C++ compiler.



来源:https://stackoverflow.com/questions/9762273/boost-lambda-dereference-placeholder

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!