Basically, I have a string, and I want to remove all non alpha chars.
I'm trying to do it using algorithm, so I thought I'd do something like this:
The problem is that this removes all the alpha, the oposite of what I want to do.Code:iString.erase(
std::remove_if(iString.begin(), iString.end(), &isalpha),
iString.end()
);
I would use the algorithm std::copy_if or remove_if_not, but they don't exist. My other choice would be to pass std::not1(isalpha), but that doesn't work, since isalpha is not a function object.
I could write this:
But I would rather avoid it.Code:struct isalphafuntor : public std::unary_function<int,bool>
{
bool operator()(int iChar) const
{
return isalpha(iChar);
}
};
So my question is this one:
Can I, in a single line, pass the negated isalpha function to the remove if algorithm? or am I stuck with wrapping isalpha explicitly (or writting isnotalpha)?

