Re: Why is this code complaining about constness?
On Aug 1, 8:10 pm, markscottwright <markscottwri...@gmail.com> wrote:
I'm using visual studio 8, and the following code is failing. For the
life of me, I can't see what's wrong...
void myTest(std::string const& in)
{
using namespace std;
string::const_iterator lastNonWhitespace = find_if(in.rbegin(),
in.rend(), not1(ptr_fun(isspace)));
Victor has pointed out one of the errors. But the last argument
to find_if can't be correct either. First, of course, because
one of the isspace functions is a template, so argument type
deduction fails if it is visible. (Of course, the one that it a
template takes two arguments, so can't be used here. But the
compiler can't know that until it's instantiated the template,
and it can't instantiate the template until it has chosen the
correct isspace.) And secondly, because calling the one
argument version of isspace (from <cctype> or <ctype.h>) with
the char resulting from the referencing of
std::string::const_reverse_iterator is undefined behavior.
}
--
James Kanze (GABI Software) email:james.kanze@gmail.com
Conseils en informatique orient=E9e objet/
Beratung in objektorientierter Datenverarbeitung
9 place S=E9mard, 78210 St.-Cyr-l'=C9cole, France, +33 (0)1 30 23 00 34