I was really surprised to see that std::count
returned a iterator_traits<InputIterator>::difference_type
, which in turns refers to a long int
on my platform.
Why is that? A negative count elements within a container doesn’t make any sense.
It's actually a std::ptrdiff_t
, which has to be a signed integer. It has to be signed because it can be used as the difference between two iterators, and that can of course be negative.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With