Six components of STL

Standard Template Library (STL):
STL libraries are written with templates, and templates are the basis of STL libraries. STL roughly consists of the following parts:
  - container (container)
  - iterator (iterator)
  ——Container Adapter (Adapter)
  ——algorithm
  - function object (functor)
  - Configurator (allocator) //The underlying implementation
Containers, iterators, and container adapters are all implemented with class templates. Iterators are used to traverse each element in the container, and algorithms are used to manipulate data.
(Use the new features of C++11, add: -std=c++11 when compiling )


container:
     STL uses the template class library mechanism to provide a complete set of solutions for data storage, search and other operations, which greatly improves the correctness of the program. Not only that, the class library optimizes many commonly used operations, which greatly improves the efficiency of the program.
A container is a class template that can hold some data. In STL, there are containers such as vector, list, deque, (sequential container) set/multiset, map/multimap (associative container) .


iterator:
     In some professional books, iterators are also called cursors . Iterators can be initially understood as generalized pointers . The functions of iterators and pointers are very similar. Returns a value indirectly .
There are 5 types of iterators, in order:
   - Random Access Iterator
   - Bidirectional Iterator
   - Forward Iterator
   - Input Iterator
   - Output Iterator


adapter:
      Adapters are Interfaces, which wrap containers, iterators, and algorithms, but their essence is still containers, iterators, and algorithms. They just don’t depend on specific standard containers, iterators, and algorithm types. Container adapters can be understood as container Template , the iterator adapter can be understood as the template of the iterator, and the algorithm adapter can be understood as the template of the algorithm.
Common container adapters are:
stack、queue、 priority_queue
(Iterator access is not supported)


algorithm:
     STL contains many functions that process containers, and their processing ideas are basically the same: use iterators to identify the data or data segments to be processed, and the storage location of the results, and some functions are also passed as object parameters to another function, Implement data processing.



Guess you like

Origin http://43.154.161.224:23101/article/api/json?id=325309085&siteId=291194637