Last updated
Last updated
As we have already known, iterators are useful to traverse elements in a STL container. However, there are also other types of iterators that are commonly used.
iterator is the normal type of iterators we have learned before. It supports forward traversal of containers. We can use the deference to access the element it points to, and modify it as well.
const_iterator supports forward traversal of containers. We can use the deference to access the element it points to, but cannot modify it, since the deference returns a const
reference to the element.
reverse_iterator supports backward traversal of containers. We can use the deference to access the element it points to, and modify it as well.
Instead of begin() and end() in normal iterators, we use rbegin() and rend() in reverse iterators. rbegin() returns a reverse_iterator to the last element in the container, while rend() returns a reverse_iterator to the one before the first element in the container.
reverse_iterator supports backward traversal of containers. We can use the deference to access the element it points to, but cannot modify it, since the deference returns a const
reference to the element.