• Advertisement
Sign in to follow this  

std::*fun

This topic is 4772 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

I am reading through Josuttis' STL book, and want to make sure I understand something correctly. mem_fun_ptr [edit: er mem_fun_ref, could they make any worse names?] makes a function object which is essentially called like object.functor(); mem_fun makes a function object which is essentially called like object->functor(), and ptr_fun makes a function object which is called like functor()? And that is the only practical difference between these?

Share this post


Link to post
Share on other sites
Advertisement
It's mem_fun and mem_fun_ref, they are actually free-functions, they are just convenience functions that deduces types from function arguments that creates functor instances (its all inlined away) think std::make_pair same thing.

The difference between the two is mem_fun is for when your storing pointers in containers, the definition of the over-loaded function call operator would be something like this:


(obj->*mem_func)(optional_argument);


and for containers that store by value then you use mem_fun_ref, the definition of the over-loaded function call operator would be something like this:


(obj.*mem_func)(optional_argument);


That should make the difference alittle more obvious.

When you come to the standard library binders you will notice that there incorrect and it's not an implementation issue!. Boost binders & member function adaptors over come these issues including mem_fun/mem_fun_ref differences and are being considered to be included into the standard.

Share this post


Link to post
Share on other sites
Sign in to follow this  

  • Advertisement