I am using std::ptr_fun
as follows:
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;
}
as presented in this answer.
However this does not compile with C++17 (using Microsoft Visual Studio 2017), with the error:
error C2039: 'ptr_fun': is not a member of 'std'
How can this be fixed?
You use a 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;
}
The answer you cited is from 2008, well before C++11 and lambdas existed.
Just use a lambda:
[](unsigned char c){ return !std::isspace(c); }
Note that I changed the argument type to unsigned char
, see the notes for std::isspace
for why.
std::ptr_fun
was deprecated in C++11, and will be removed completely in C++17.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With