A library is a collection of program components that can be reused in different programs. The first requirement of library function design is universality, and the template (template) brings immeasurable prospect for universality.
The Standard Template Library (Standard Template Library), abbreviated as STL, is one of the most characteristic and practical parts of Ansi/iso C + +. STL includes: Container Class (Container), Iteration sub (iterator), Algorithm (algorithm)
Generic algorithms (generic algorithm) and function objects (functions object) enable the algorithm to get rid of the dependency on individual manipulation of different data types.
Introduction to the Standard Template Library
1. Container Class (Container)
A container class is a class that manages a sequence, a class that holds a set of objects or objects. By using the member functions provided by the container class, you can implement actions such as inserting elements into a sequence, deleting elements, finding elements, and so on, which specify the position of the element in the sequence by returning the iteration child.
Containers are grouped into three main categories: Sequential containers (Sequence Container or sequential Container) associated containers (associative Container) container adapters (Container adopter)
Sequential and associative containers are called first class containers (first-class container), as shown in the following table.
The container provides a similar interface. Many of the basic operations are applicable to all containers, while others apply to a subset of similar containers and can be extended using new classes with similar operations. See table 11.2 Functions shared by all standard library containers
2. Generic algorithm (Generic algorithm)
In a template the algorithm does not depend on the specific data type, and the generic algorithm goes further than the concrete container.
In the generic algorithm, the function object is used to introduce the difference of the same algorithm in different cases. It does not use inheritance and polymorphism, avoids the overhead of virtual functions, and makes the STL more efficient.
3, iterative sub (iterator)
An iterator is a generic form of the pointer concept that points to an element in a container that can be added or subtracted like a pointer, indicating each element in a container in turn. So the iteration is a pointer to an object-oriented version.
Iterations can include pointers, but iterations are more than just a pointer.
The iterative subroutine joins the algorithm with the container. The algorithm only indirectly through the iteration of the container element, the algorithm itself and the container Independent. The algorithm usually returns an iteration.