[C++] Introduction to STL (Understanding) [The concept of STL, the historical reasons of STL, the six components of STL, the importance of STL, and explanations of how to learn STL and the defects of STL]




1. What is STL

STL (standard template libaray - Standard Template Library): It is an important part ofC++ standard library, not only a reusable component library, but also a software framework including data structures and algorithms .



2. STL version

1. Original version

The original version completed by Alexander Stepanov and Meng Lee at HP Labs, in the spirit ofopen source, they stated that anyone can use it arbitrarily, There is no charge for copying, modifying, distributing, and commercially using these codes. The only condition is that it needs to be used as open source like the original version. HP version – the ancestor of all STL implementations.

2. P.J. version

Developed by P. J. Plauger, it is inherited from the HP version and adopted by Windows Visual C++. It cannot be disclosed or modified. Defects: low readability and weird symbol naming.

3. RW version

Developed by Rouge Wage Company, it is inherited from the HP version and adopted by C++ Builder. It cannot be made public or modified, and its readability is average.

★ 4. SGI version

was developed by Silicon Graphics Computer Systems, Inc. and inherited from the HP version. Adopted by GCC (Linux), it has good portability, can be disclosed, modified and even sold. From the naming style and programming style, it is very readable. When we learn STL later, we need to read part of the source code, and this version is the one we need to refer to.



3. Six major components of STL

Insert image description here


4. The importance of STL

  1. In the written test
    Binary number layer sequence printing
    Reconstruct the binary tree
    Two stacks to implement a queue< /span>

  2. in interview

  3. At work
    There is a saying on the Internet: "Don't say you know C++ if you don't understand STL." STL is an excellent work in C++. With its company, many underlying data structures and algorithms do not need to reinvent the wheel themselves. They can stand on the shoulders of their predecessors and develop rapidly.



5. How to learn STL

Insert image description here



6. Defects of STL

  1. STL library updates are too slow. This is a serious complaint. The last version was C++98, and the C++03 in the middle was basically revised. It has been 13 years since C++11 came out, and STL has been further updated.
  2. STL currentlydoes not support thread safety. In a concurrent environment, we need to lock ourselves. And the lock granularity is relatively large.
  3. STL’s extreme pursuit of efficiency leads to internal complexity. Such as type extraction, iterator extraction.
  4. The use of STL will causecode expansion. For example, using vector/vector/vector will generate multiple copies of code. Of course, this is Caused by the template syntax itself.

Guess you like

Origin blog.csdn.net/NiNi_suanfa/article/details/134588001