"Siemel Naran" <Si*********@REMOVE.att.net> wrote in message news:<sU********************@bgtnsc04-news.ops.worldnet.att.net>...
"news.hku.hk" <bi******@hkusua.hku.hk> wrote in message news:408a92c6
how to count the occurance of a character in a string ?
std::count
I've noticed a number of people posting alternatives. std::count
is superior, for a number of reasons:
* It's tested
* It's documented
* Someone reading the code later immediately sees the intent
* It may be optimized for your particular implementation
using non-portable tricks (e.g. written in assembly).
The last argument is slightly tricky. You could write similar
optimized code, but then the first three points apply even more.
Worse, your code would be non-portable. Had you used std::count,
you would get a different std::count when you actually port.
Of course, std::count is O(n) so performance is good enough unless
profiling proves otherwise.
Regards,
Michiel Salters