views:

113

answers:

3

I'm having a look at the Boost libraries that were included in C++'s Technical Report 1 and trying to understand what each does.

I've just finished running an example for boost::mem_fn and now I'm wondering what's the point of using it instead of the better boost::bind. As far as I understand, both of them return a function object pointing to a member function. I find mem_fn so limited that I can't find a scenario where using it would be better than bind.

Am I missing something? Is there any case in which bind cannot replace mem_fn?

+3  A: 

Well, bind depends on mem_fun so there you go. How and why I'll leave for you to discover since although interesting, I haven't got the time to investigate right now (bind is complicated).

Noah Roberts
+1  A: 

boost::lambda has a similar overlap of functionality with the two you mentioned. I think they all sort of evolved with similar intent, about the same time, with different approaches, resulting in confusion and incompatibility issues. It'd be nice if they all merged under one lambda umbrella.

So, no, there is no overarching design that calls for both libraries to co-exist.

John
The curious thing is that both `bind` and `mem_fn` have made it to the C++ Technical Report 1, and the C++ comittee is supposed to be quite strict. Didn't they realize they we're duplicating functionalities?
TheOm3ga
+1  A: 

mem_fn is much smaller than bind, so if you only need the functionality of mem_fn it's a lot less code to pull in.

Jeff Hardy