Functors in Boost

So I'm exploring Boost, and am trying to figure out if/how you can make functors with it. An example of what I want is here:

http://www.newty.de/fpt/functor.html#chapter4

Basically I want class A to have a callback which calls a member function in class B, without A knowing anything about B.

boost::function almost looks like what I want, however the documentation makes it seem like you need to know the type of the class being called (ie: A would need to know about B).

boost::bind also looks like it might be what I want, however the documentation doesn't say anything about the return type it gives (if any!). All it says is "bind(f, 1, 2) will produce a "nullary" function object that takes no arguments and returns f(1, 2).". Which is great, but wtf does it mean? How do I apply it?

All of the examples are ridiculous, and simply illustrate another way to call a function:

bind(f, _2, _1)(x, y); // f(y, x)

Not a very useful example. If I can just call f(y,x), what is the point of using bind here? All of the examples in the docs I have are like that -- not one of them is practical.

What I'd like to do is something like this:

1
2
_somekindatype_ callback = bind(f,_1);
callback( 5 );  // f(5) 


But what would '_somekindatype_' be? And would this work with member functions (ie: for a functor)?

The next thing I checked out was boost::lambda, but the documentation seemed dense. I'm not sure it's what I'd want and I didn't feel like spending another few hours trying to decipher it.

Then I remembered some guys on here are really big on Boost so I figured I'd ask.

Can anyone help me out? I can do this functor stuff without Boost (ie: that page I linked to before shows exactly how to do it), but if Boost provides a way I'd like to familiarize myself with it rather than substitute in my own code.
Topic archived. No new replies allowed.