Reputation: 6646
I noticed STL containers (including vector
, list
, etc.) have a difference_type
typedef, which is usually an alias for std::ptrdiff_t
.
What is it used for? It is used by any member functions?
Upvotes: 0
Views: 323
Reputation: 7788
It's used to compute difference between iterators.
For example cont.end() - cont.begin().
It's not used directly by stl container, but is widely used by iterator library.
Example:
template< class InputIt >
typename std::iterator_traits<InputIt>::difference_type
distance( InputIt first, InputIt last );
Upvotes: 2