Iterators are fundamental
The STL uses iterators to navigate the elements of its container classes. Most containers include begin()
and end()
iterators. These are usually implemented as member functions that return an iterator object. The begin()
iterator points to the initial container element, and the end()
iterator points past the final element:
The end()
iterator may function as a sentinel for containers of indeterminate length. We'll see some examples of that in this chapter.
Most STL containers define their own specific iterator type. For example, for a vector
of int
:
std::vector<int> v;
The iterator type would be defined as:
std::vector<int>::iterator v_it;
You can see how this could easily get out of hand. If we had a vector
of vector
of string
:
std::vector<std::vector<int, std::string>> v;
Its iterator type would be:
std::vector<std::vector<...