C ++: Getting to know STL


What is STL

STL (standard template libaray-standard template library): is an important part of the C ++ standard library , not only a reusable component library, but also a software framework that includes data structures and algorithms.

STL version

  • The original version
    Alexander Stepanov and Meng Lee completed the original version in HP Labs. In the spirit of open source, they stated that they allow anyone to use, copy, modify, disseminate, and commercially use these codes at no cost. The only condition is that it also needs to be open source as the original version. HP version – the ancestor of all STL implementation versions.

  • PJ version
    Developed by PJ Plauger, inherited from HP version, adopted by Windows Visual C ++, cannot be disclosed or modified. Defects: low readability, weird symbol naming.

  • The RW version
    was developed by Rouge Wage and inherited from the HP version. It is adopted by C + + Builder and cannot be published or modified. It is generally readable.

  • The SGI version
    was developed by Silicon Graphics Computer Systems, Inc. and inherited from the HP version. It is adopted by GCC (Linux), has good portability, and can be published, modified or even sold. From the perspective of naming style and programming style, it is very readable. STL to learn later to read part of the source code, the main reference is this version.

Six components of STL

Insert picture description here

There is a saying on the Internet: "Do not understand STL, don't say you know C ++". STL is an excellent work in C ++. With its companionship, many of the underlying data structures and algorithms do not need to reinvent the wheel by themselves, standing on the shoulders of the predecessors and developing rapidly.

How to learn STL

Three realms of learning STL:

  1. Usable
  2. reasonable
  3. Expandable

Defects of STL

  1. The update of the STL library is too slow. This is a serious complaint. The last version is reliable C ++ 98, and the middle C ++ 03 is basically revised. It has been 13 years since C ++ 11 came out, and the STL was updated further.

  2. None of STL currently supports thread safety. We need to lock ourselves in a concurrent environment. And the granularity of the lock is relatively large.

  3. STL's extreme pursuit of efficiency has led to internal complexity. Such as type extraction, iterator extraction.

  4. The use of STL will cause code expansion problems, such as the use of vector / vector / vector will generate multiple copies of the code, of course, this is caused by the template syntax itself.


It's another brand new stage in C ++, continue to cheer, rush duck! !

Published 152 original articles · praised 45 · 10,000+ views

Guess you like

Origin blog.csdn.net/AngelDg/article/details/104964332