This is the example-implementation of the count algorithm from https://devdocs.io/cpp/algorithm/count_if:
template<class InputIt, class T>
typename iterator_traits<InputIt>::difference_type
count(InputIt first, InputIt last, const T& value)
{
typename iterator_traits<InputIt>::difference_type ret = 0;
for (; first != last; ++first) {
if (*first == value) {
ret++;
}
}
return ret;
}
My question is, what is the significance of typename iterator_traits<InputIt>::difference_type
?
If I were implementing this, I would have simply used unsigned int
to keep track of the count.