(e-mail address removed)>, (e-mail address removed)
says...
There are two requirements:
1) The element must implicitly convert to the argument type.
2) The return from the predicate must implicitly convert to bool.
Since there are implicit conversions from char to int and from
int to bool, isalpha should work.
It's significantly more complex than that. At the syntax level,
std::count_if doesn't take a bool pred(char&), or anything like
that---it takes a Predicate, which is a template parameter; the
type must thus be deduced by the compiler. If the only function
isalpha visible is the one in <ctype.h>, then that's what the
compiler will use, and it will deduce that Predicate has type
int (*)( int ). Depending on the context, however, it's quite
likely that the std::isalpha in <locale> is also visible---since
that's a function template, the compiler doesn't know its type,
so template type deduction fails. And whether <locale> has been
included or not may depend on the implementation; an
implementation can (but is not required to) include <locale> in
any other standard header. Given that his code works with one
compiler, and not with another, I'd guess that this is the
issue; it can be solved by using ::isalpha (assuming that he did
include <ctype.h>, and not <cctype>).
Of course, all this does is make the code compile. The isalpha
in <ctype.h> may result in undefined behavior if called with a
char; what he really wants is the isalpha in <locale> (which
does work with char). Which can "easily" be called with
something like:
std::count_if(
c.begin(), c.end(),
std::bind2nd(
static_cast< bool (*)( char, std::locale const& ) >(
&std::isalpha ),
std::locale() ) ) ;
(I'm not actually sure, of course. I've got a couple of generic
functional objects which I use in such cases. Makes life a lot
easier. And of course, in more recent code, everything is
UTF-8, which requires slightly different tactics.)