title: Why does the C++ standard algorithm "count" return a difference_type instead of size_t?
body: <p>Why is the return type of <a href="http://en.cppreference.com/w/cpp/algorithm/count" rel="noreferrer"><code>std::count</code></a> the <code>difference_type</code> of the iterators (often a <code>ptrdiff_t</code>).</p>
  
  <p>Since count can never be negative, isn't <code>size_t</code> <em>technically</em> the right choice? And what if the count exceeds the range of <code>ptrdiff_t</code> since the theoretical possible size of an array can be <code>size_t</code>?  </p>
  
  <hr>
  
  <p><strong>EDIT:</strong> So far there is no suitable answer as to why the function returns <code>ptrdiff_t</code>. Some explanation gathered from the answers below is that the return type is <code>iterator_traits&lt;InputIterator&gt;::difference_type</code> which is generic and can be anything. Up until that point it makes sense. There are cases where the count may exceed <code>size_t</code>. However, it still does not make sense why the return type is <code>typedef ptrdiff_t iterator_traits&lt;InputIterator&gt;::difference_type</code> for the standard iterators instead of <code>typedef size_t iterator_traits&lt;InputIterator&gt;::difference_type</code>.</p>