gpt4 book ai didi

c++ - c++17 的 std::ptr_fun 替换

转载 作者:IT老高 更新时间:2023-10-28 22:23:00 27 4
gpt4 key购买 nike

我正在使用 std::ptr_fun 如下:

static inline std::string &ltrim(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 &ltrim(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/

27 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com