The STL is based on the cooperation of various well-structured components, key of which are containers, iterators, and algorithms:
- Containers are used to manage collections of objects of a certain kind. Every kind of container has its own advantages and disadvantages, so having different container types reflects different requirements for collections in programs.
- Iterators are used to step through the elements of collections of objects. These collections maybe containers or subsets of containers. The major advantage of iterators is that they offer a small but common interface for any arbitrary container type.The interface for iterators is almost the same as for ordinary pointers. To increment an iterator,you call operator ++. To access the value of an iterator, you use operator *.
- Algorithms are used to process the elements of collections. For example, algorithms can search, sort, modify, or simply use the elements for various purposes. Algorithms use iterators. Thus, because the iterator interface for iterators is common for all container types, an algorithm has to be written only once to work with arbitrary containers.
The concept of the STL is based on a separation of data and operations. The data is managed by container classes, and the operations are defined by configurable algorithms. Iterators are the glue between these two components. They let any algorithm interact with any container.