Taken from Understanding iterator/const_iterator implementation:
"although
iterator
andconst_iterator
are types declared in the scope ofvector
, there is no requirement thatvector
(or any STL container) have a member of either type -iterator
andconst_iterator
are part of the interface ofstd::vector
e.g. overloads of the memberbegin()
returns those types, but nothing is said about how those function obtain the iterator they return"Additionally STL containers must have:
"a begin and end function that returns iterators"
The above states that iterator
and const_iterator
are not required members of a STL container for example vector
. I assume this means that the type returned from .begin
or .end
will differ based on implementation.
So I am wondering why this isn't problematic as I see a lot of people write out std::vector<someType>::iterator
or std::vector<someType>::const_iterator
where iterator
and const_iterator
are specified instead of using auto
for example:
for (std::vector<int>::iterator i = s.begin(); i != s.end(); i++)
{
}