我正在使用 std::ptr_fun
如下:
static inline std::string <rim(std::string &s) {
s.erase(s.begin(), std::find_if(s.begin(), s.end(), std::not1(std::ptr_fun<int, int>(std::isspace))));
return s;
}
如 this answer 中所述.
但是,这不能使用 C++17(使用 Microsoft Visual Studio 2017)编译,并出现错误:
error C2039: 'ptr_fun': is not a member of 'std'
如何解决这个问题?
最佳答案
您使用 lambda:
static inline std::string <rim(std::string &s) {
s.erase(s.begin(), std::find_if(s.begin(), s.end(), [](int c) {return !std::isspace(c);}));
return s;
}
您引用的答案来自 2008 年,远在 C++11 和 lambda 出现之前。
关于c++ - c++17 的 std::ptr_fun 替换,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/44973435/