std::ptr_fun replacement for c++17

You use a 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;
}

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.


According to cppreference, std::ptr_fun is deprecated since C++11 and discontinued since C++17.

Similarly, std::not1 is deprecated since C++17.

So best don't use either, but a lambda (as explained in other answers).

Tags:

C++

C++17