简体   繁体   English

我不懂ptr_fun

[英]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. 我在一个c ++代码中遇到了ptr_fun的问题,我尝试从cplusplus.com上读取它,但是老实说我无法弄清楚该函数指针应该做什么。

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;
}

From Effective STL (Item 40) by Scott Meyers: 摘自Scott Meyers的有效STL(第40项):

The only thing ptr_fun does is make some typedefs available. ptr_fun唯一要做的就是使一些typedef可用。 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. 这些typedef是not1所必需的,这就是为什么将not1应用于ptr_fun但将not1直接应用于...不起作用的原因。 ... lacks the typedefs that not1 demands. ...缺少not1要求的typedef。

This is basically the same answer given by Praetorian in comments above but Effective STL provides a more general explanation. 这与Praetorian在上面的评论中给出的答案基本相同,但是有效的STL提供了更一般的解释。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM