I have the following trim
function
std::string trim(const std::string& str, std::function<bool(int ch)> isCharToTrim)
{
auto trimmedStart = std::find_if_not(str.begin(), str.end(), isCharToTrim);
if (trimmedStart == str.end())
{
return "";
}
else
{
auto trimmedEnd = std::find_if_not(str.rbegin(), str.rend(), isCharToTrim);
return std::string(trimmedStart, trimmedEnd.base());
}
}
When I pass std::isspace
as second argument, it compiles with MSVC.
But I get an error with gcc: error: cannot resolve overloaded function 'isspace' based on conversion to type 'std::function<bool(int)>'
.
Usage of the function that works on MSVC
const auto trimmed = trim(test, std::isspace);
const auto trimmed2 = trim(test, std::not_fn(std::isgraph));
const auto trimmed3 = trim(test, [](int ch) { return ch == ' '; });
What changes can I make to get it to compile on gcc? Change the argument type?