Why does std :: count return a signed integer?

I was very surprised to see that I std::countreturned iterator_traits<InputIterator>::difference_type, which in turn applies to long inton my platform.

Why? Negative counting elements in a container make no sense.

+5
source share
1 answer

Actually it is std::ptrdiff_twhich should be a signed integer. It must be signed because it can be used as the difference between two iterators, and this can, of course, be negative.

+5
source

All Articles