I don't understand ptr_fun

I ran into this ptr_fun thing in one of the c++ code, I tried reading up on it from cplusplus.com, but I honestly can't figure out what this function pointer is suppose to do.

The code of interest is very simple, trims the empty parts off the beginning of a string.

static inline string & trim_beg(string & s) {
  s.erase(s.begin(), find_if(s.begin(), s.end(), not1(ptr_fun < int, int > (isspace))));
  return s;
}

Answers


From Effective STL (Item 40) by Scott Meyers:

The only thing ptr_fun does is make some typedefs available. That's it. These typedefs are required by not1, and that's why applying not1 to ptr_fun but applying not1 to ... directly doesn't work. ... lacks the typedefs that not1 demands.

This is basically the same answer given by Praetorian in comments above but Effective STL provides a more general explanation.


Need Your Help

How to refresh codemirror when it's parent div style becomes display block?

javascript codemirror

I'm using codemirror with textareas in a tabbed interface, when i'm not in the tab that contains codemirror and then go to it, I get empty white space without line numbers or the cursor, when I ref...