0

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.

Marc Andreson
  • 3,405
  • 5
  • 35
  • 51
  • `boost::function func = (_1 ->* &Foo::bla);` should work but does not compile for me and I haven't figured out why. – pmr Mar 18 '12 at 21:32

1 Answers1

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.

pmr
  • 58,701
  • 10
  • 113
  • 156