我在一段 C++ 代码中遇到了这个 ptr_fun 问题,我试着从 cplusplus.com 上阅读它,但老实说我无法弄清楚这个函数指针应该做什么。
感兴趣的代码非常简单,删除字符串开头的空部分。
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;
}
最佳答案
来自 Scott Meyers 的 Effective STL(第 40 项):
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.
这与 Praetorian 在上面的评论中给出的答案基本相同,但 Effective STL 提供了更一般的解释。
关于c++ - 我不明白 ptr_fun,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/34010925/