1
我在其中一個C++代碼中遇到了這個ptr_fun事情,我試着從cplusplus.com上讀到它,但我真的無法弄清楚這個函數指針應該做什麼。我不明白ptr_fun
感興趣的代碼非常簡單,修剪掉字符串開頭的空白部分。
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;
}
http://en.cppreference.com/w/cpp/utility/functional/ptr_fun – Maxqueue
你不應該指定模板參數,'ptr_fun(:: isspace)'應該這樣做。 'ptr_fun'的唯一目的是包裝'isspace'並提供''unary_negate''所需的成員'typedef'' argument_type'(http://en.cppreference.com/w/cpp/utility/functional/unary_negate)('not1'返回的東西)。所以'find_if'調用將返回一個迭代器到第一個元素,其中'!isspace'爲真。 – Praetorian