I l @ ve RuBoard |
In this section we take a look at the basic concepts that went into the design of the STL and how all these design elements come together to provide a very robust and flexible way of handling items. 25.1.1 ContainersThe core of the STL is the container. We're already familiar with a couple of STL container types, the vector (a single-dimension array) and the stack. The STL divides containers into sequences, which store their elements in order, and associative containers, in which elements are accessed using a key value. The basic STL containers are:
These containers give you a way of storing most data in almost any way you want to. Now that we've got our data stored, we need access to it. 25.1.2 IteratorsIterators allow you to go through a container and access the data inside. One form of this is the forward iterator, which allows you to access each element from first to last. There is a reverse iterator that allows you to go the other way and a bidirectional iterator, which goes both ways. Finally, there is the random access iterator, which allows you to access any element randomly . Not all containers support all iterator types. For example, the vector supports random access iterators, while the list container does not. We'll see how to use iterators in the class program described later in this chapter. 25.1.3 AlgorithmsWe have containers to hold the data and iterators so we can access it. For example, the sort algorithm can be used to sort an ordered container such as a vector. Some of the other algorithms include:
These three elements ”containers, iterators, and algorithms ”make up the STL. Now that we know the basics, let's see how to use this library in the real world. |
I l @ ve RuBoard |