Question

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.

Était-ce utile?

La solution

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.

Licencié sous: CC-BY-SA avec attribution
Non affilié à StackOverflow
scroll top