Reading about iterators online, I came across this declaration of the std::distance
function:
template<class InputIterator>
typename iterator_traits<InputIterator>::difference_type // What is this line?
distance (InputIterator first, InputIterator last);
The first and third lines are clear to me, but I don't entirely understand the syntax of the second line.
I understand that iterator_traits<InputIterator>::difference_type
will generate a class from the iterator_traits
class template in order to figure out the difference_type
suitable for this particular InputIterator
. Please correct me if my understanding is wrong.
But what I certainly don't understand is the use of typename
in this context. I've never seen it outside a template < ... >
clause.
Please explain this syntax and its usage.