c++ - STL iterators - purpose -
What is the purpose of STL iterations? Why did the programmer create this concept?
The iterators allow you to separate the algorithm from the container. As long as you have a start and end iterator, and know the ability of the iterator (random access etc), you can work on the specified range by iterators. For example, see std :: for_each
, std :: transform
. In this way, you can apply only one version of the algorithm on which you want to operate it, instead of needing to write a new one for each container.
Comments
Post a Comment