Boost logo

Boost Users :

From: Neal Coombes (nealc_at_[hidden])
Date: 2005-09-15 09:03:44


Bind is very convenient for use with shared_ptr:

struct C { void func() {} };
shared_ptr<C> c(new C);
bind(&C::func, c)(); // calls c->func()

However I've found a snag when trying to do function composition:

class A { shared_ptr<C> func() { return shared_ptr<C>(new C); } };
A a;
bind(&C::func, bind(&A::func, a)); // doesn't work, instead must:
bind(&C::func, bind(&get_pointer<B>, bind(&A::func, a)));

The fact that I can work around this is obviously a good thing. But the
work around is significantly less clear, especially when attempting to
convince a development team that boost and bind are Good Things(tm) and
they should be adopted.

Is it horribly difficult to make the simpler composition work (i.e. was
it tried and impossible or simply overlooked)?

Thanks,
Neal


Boost-users list run by williamkempf at hotmail.com, kalb at libertysoft.com, bjorn.karlsson at readsoft.com, gregod at cs.rpi.edu, wekempf at cox.net