Re: count_if(somestr.begin(), somestr.end(), isalpha) fails to compile
on gcc, but compiles on VS2008
* Pete Becker:
Alf P. Steinbach wrote:
* Pete Becker:
Alf P. Steinbach wrote:
* Pete Becker:
In fact what's required is that the predicate can be called with an
argument of type char and that it returns a type that can be
converted to bool. Whenever you're dealing with predicates or other
things that get passed to templates, think in terms of how the
thing will be called, not in terms of how it has to be written. So,
for example, find_if will typically use the predicate like this:
if (pred(*iter))
where *iter has type char or maybe cv char&, depending on where
iter came from. isalpha(*iter) works just fine in an if statement.
Uh, AFAIK ::isalpha, from the C library, can't portably be called
with 'char' actual argument.
But it can be wrapped like
bool isAlpha( char c ) { return !!::isalpha( (unsigned char)c ); }
That has nothing to do with why isalpha can be passed to count_if as
a predicate.
It has a lot to with whether one /should/ pass the C library isalpha
as a predicate.
Which is why it should have been raised in a reply to the original message.
But you didn't.
If you had thought of that then you'd have mentioned it
I answered a specific question.
(you'd not want
to lead the OP astray, would you?),
It's not leading anyone astray to answer the question they asked.
so, you didn't think of it.
Ah, I see. You know better than I do what it is that I'm thinking.
No, I just refuse to believe, in spite of your childish behavior e.g. below and
before, that you'd actively mislead novices.
And so I choose to believe that you just didn't see the point I raised above.
Even when you, with utter disregard for what that implies, protest.
plonk.
Pete, this is the second time in just as many months that you "plonk" me,
putting me in your killfilter whence, presumably, you won't see my articles.
This time you "plonk" me for pointing out something that for whatever reason you
didn't see when you wrote your article (even though you're now protesting,
implying that you /chose/ to mislead the OP, which is just silly), and last time
you plonked me for asking what you meant by a rather dubious statement.
It's very childish behavior you exhibit this way, please stop.
Cheers,
- Alf