Introduction to the six major components of STL

STL (Standard Template Library), the standard template library, is an efficient C++ library. Contains many basic data structures and basic algorithms commonly used in the field of computer science. From the logical level, the idea of ​​generic programming is embodied in STL. From the implementation level, the entire STL is implemented in a type parameterized way.

The six components of STL are as follows:

  1. Container 
  2. Adapter (adapter) 
  3. Algorithm 
  4. Iterator (iterator) 
  5. Function object (function object) 
  6. Allocator

The basic functions of the six components:

  1. Container (container)     Various data structures, such as Vector, List, Deque, Set, Map, are used to store data. The STL container is a Class Template. In terms of volume, this part is very similar to the ratio of iceberg to sea surface.
  2. Adapter (adapter)     is a thing used to modify the interface of containers (Containers) or functors (Functors) or iterators (Iterators) , for example: Queue and Stack provided by STL, although it looks like a container, it can only be regarded as a container Adapters, because their bottom is completely deque-based, all operations are supplied by the underlying Deque. Those who change the Functor interface are called Function Adapters; those who change the Container interface are called Container Adapters; those who change the Iterator interface are called Iterator Adapters. The implementation technology of the adapter is difficult to sum up in one word, and must be analyzed one by one.
  3. Algorithm (algorithm)   Various common algorithms such as Sort, Search, Copy, Erase, from the perspective of implementation, STL algorithm is a kind of Function Templates.
  4. Iterator (iterator)    acts as the glue between the container and the algorithm. It is a so-called "generic pointer". There are five types in total, as well as other derivative changes. From an implementation point of view, an iterator is a kind of Operators* , Operator->, Operator++, Operator-- and other related operations to be overloaded Class Template. All STL containers come with their own iterators - yes, only the container designer knows how to traverse their elements, and native pointers (Native pointers) are also iterators.
  5. Function object (function object)    behaves like a function and can be used as a policy of an algorithm. From an implementation point of view, a functor is a Class or Class Template that overloads Operator(). General function pointers can be regarded as functors in a narrow sense.
  6. Allocator (allocator)   is responsible for space configuration and management. From the perspective of implementation, the configurator is a Class Template that implements dynamic space configuration, space management, and space release.

The principle analysis and use of the six components are as follows:

C++ STL six major components-1-Container (container) 

C++ STL six major components -2-Adapter (adapter) 

C++ STL six major components-3-Algorithm (algorithm) 

C++ STL six major components -4-Iterator (iterator) 

C++ STL six major components -5-Function object (function object) 

C++ STL six major components -6-Allocator (allocator)

STL (Standard Template Library), the standard template library, is an efficient C++ library. Contains many basic data structures and basic algorithms commonly used in the field of computer science. From the logical level, the idea of ​​generic programming is embodied in STL. From the implementation level, the entire STL is implemented in a type parameterized way.

The six components of STL are as follows:

  1. Container 
  2. Adapter (adapter) 
  3. Algorithm 
  4. Iterator (iterator) 
  5. Function object (function object) 
  6. Allocator

The basic functions of the six components:

  1. Container (container)     Various data structures, such as Vector, List, Deque, Set, Map, are used to store data. The STL container is a Class Template. In terms of volume, this part is very similar to the ratio of iceberg to sea surface.
  2. Adapter (adapter)     is a thing used to modify the interface of containers (Containers) or functors (Functors) or iterators (Iterators) , for example: Queue and Stack provided by STL, although it looks like a container, it can only be regarded as a container Adapters, because their bottom is completely deque-based, all operations are supplied by the underlying Deque. Those who change the Functor interface are called Function Adapters; those who change the Container interface are called Container Adapters; those who change the Iterator interface are called Iterator Adapters. The implementation technology of the adapter is difficult to sum up in one word, and must be analyzed one by one.
  3. Algorithm (algorithm)   Various common algorithms such as Sort, Search, Copy, Erase, from the perspective of implementation, STL algorithm is a kind of Function Templates.
  4. Iterator (iterator)    acts as the glue between the container and the algorithm. It is a so-called "generic pointer". There are five types in total, as well as other derivative changes. From an implementation point of view, an iterator is a kind of Operators* , Operator->, Operator++, Operator-- and other related operations to be overloaded Class Template. All STL containers come with their own iterators - yes, only the container designer knows how to traverse their elements, and native pointers (Native pointers) are also iterators.
  5. Function object (function object)    behaves like a function and can be used as a policy of an algorithm. From an implementation point of view, a functor is a Class or Class Template that overloads Operator(). General function pointers can be regarded as functors in a narrow sense.
  6. Allocator (allocator)   is responsible for space configuration and management. From the perspective of implementation, the configurator is a Class Template that implements dynamic space configuration, space management, and space release.

The principle analysis and use of the six components are as follows:

C++ STL six major components-1-Container (container) 

C++ STL six major components -2-Adapter (adapter) 

C++ STL six major components-3-Algorithm (algorithm) 

C++ STL six major components -4-Iterator (iterator) 

C++ STL six major components -5-Function object (function object) 

C++ STL six major components -6-Allocator (allocator)

Guess you like

Origin blog.csdn.net/yangSHU21/article/details/131537902