Boost logo

Boost Users :

Subject: [Boost-users] questions regarding boost::mem_fn and boost::bind
From: Littlefield, Tyler (tyler_at_[hidden])
Date: 2011-04-02 19:15:04


Hello all:
I have a quick question. I was trying to learn how to use boost::mem_fn
to work as a sort of function object, because I need something like this
for my library.
So: If I understand this correctly, it creates a function object that
has () overloaded, correct?
I was curious if someone could then help me figure this out, the
documentation is confusing for me.
lets say I have this class:
class Foo
{
public:
int Add(int a, int b)
{
return (a+b);
}
};

and I could do Foo bar;
how would I create a mem_fn named f, that would let me call it for add?
so: f(3,1).
I would have to tie the instance of foo (bar) to this somehow, correct?
Next, I see that mem_fn creates a function object which basically does
what I want. What then is the point in boost::bind? It looks to do about
the same as mem_fn, just makes my head hurt a little bit more.

I am trying to learn boost by finding uses for some of the libraries.
Some of them sort of makes sense, but I see that mem_fn are the bases
for a lot, so I wanted to learn how to use those. After bind and mem_fn,
what other libraries would it be best to learn that is used all over?
Last, this is the use I will be putting mem_fn to. If this is incorrect,
I still want to learn, but it looked like a great example.
I am writing a quick socket class that will have connect, close, and
send capabilities. I am hooking this to my game engine, and wanted to
use a mem_fn to receive the data. So the server polls all user input,
then it will poll the sockets that were added to another list. It will
pass off any data read by calling the function object with the data as
an argument, as well as the socket.
Sorry for all the questions, and thanks in advance for the
help/clarification.

-- 
Thanks,
Ty

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