Boost.Lambda - dereference placeholder

2019-09-05 08:50发布

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条回答
【Aperson】
2楼-- · 2019-09-05 09:05

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.

查看更多
登录 后发表回答