Re-review the STL
What is STL?
STL (template and Standard Template Library), which implements type-independent algorithms and data types, requires that the type in the implementation be parameterized, allowing the user to make different types according to its needs.
one or one-like introduction
STL, the standard Template Library, is a highly efficient C + + library with industrial strength. It is housed in the C + + standard library, which is the newest and most revolutionary part of the Ansi/iso C + + standard. The library contains many basic data structures and basic algorithms commonly used in computer science. For the vast number of C + + programmers to provide a scalable application framework, highly reflects the reusability of software.
From the logical level, the concept of generic programming is embodied in STL (generic programming), which introduces many new nouns, such as requirements (requirements), concepts (concept), model, Container (container), algorithm (ALGORITHMN), Iteration sub (iterator), etc. Like the polymorphism (polymorphism) in OOP (object-oriented programming), generics are also a reusable technology of software.
From the implementation level, the entire STL is implemented in a type-parameterized (type parameterized) way, based on a language feature that did not appear in the previous C + + standard-template. If you look at any one version of the STL source code, you will find that the template as the cornerstone of the entire STL is a true thing. In addition, many new features of C + + provide convenience for STL implementation.
Second, the six components of the STL
- A container (Container) is a data structure, such as List,vector, and deques, provided as a template class method. To access the data in the container, you can use an iterator that is output by the container class;
- Iterator (Iterator), which provides methods for accessing objects in the container. For example, you can use a pair of iterators to specify a range of objects in a list or vector. An iterator is like a pointer. In fact, C + + pointers are also an iterator. However, iterators can also be class objects that define operator* () and other operator-like methods that are similar to pointers;
- Algorithm (algorithm), which is a template function used to manipulate the data in a container. For example, the STL uses sort () to sort the data in a vector, search for an object in a list with find (), and the function itself is independent of the structure and type of data they manipulate, so they can be used on any data structure from a simple array to a highly complex container;
- The functor (function object, functor (functor), also known as the functional objects, is actually a struct that overloads the () operator, and there is no special place
- Iterative Adapters (Adaptor)
- Space Formulators (allocator) The main work consists of two parts 1. Object creation and destruction 2. Memory acquisition and release
STL General Summary of C + +