Introduction to C + + Standard Template Library (STL)

Source: Internet
Author: User

1. STL Basic Introduction

The C + + STL (Standard Template Library) is a set of powerful C + + template classes, collectively known as a series of software developed by HP Labs. The purpose of the STL is to standardize the components so that they do not have to be re-developed so that the latter can use the ready-made components, and the open source components are a bit the same. There are many versions of STL, including HP STL, PJ STL, SGI STL, etc., and STL libraries are part of the C + + standard library, and they are included.

Since my usual programming environment is mainly under the Linux system, so in the following summary, I will master the GNU ISO C + + library in the STL source (5.2.1 version), supplemented by the SGI STL 2.91 source code to carry out analysis and summary, with SGI mainly because SGI The STL version is relatively early, and the code readability is a little bit better.

As for the source code acquisition method: the GNU C + + library is in the Linux system/usr/include/directory; SGI Library, to search the Internet should have, I was downloaded from this link:

Https://sourceforge.net/projects/sgistl/?source=navbar

bash-4.2$ ls/usr/include/c++/4.8.5/algorithm Cerrno complex cstdint debug Future list Prof Ile stdexcept typeindexarray cfenv complex.h cstdio decimal initializer_list locale que        UE streambuf typeinfoatomic cfloat condition_variable cstdlib deque iomanip map Random String Type_traitsbackward Chrono csetjmp CString exception iOS memory Rati     o system_error unordered_mapbits cinttypes csignal ctgmath ext iosfwd Mutex regex TGMATH.H unordered_setbitset ciso646 cstdalign ctime fenv.h iostream new Scoped_all       Ocator thread Utilitycassert climits cstdarg cwchar forward_list IStream Numeric set       TR1 Valarrayccomplex Clocale cstdbool cwctype fstream iterator ostream Sstream TR2 Vectorcctype cmAth Cstddef cxxabi.h functional limits parallel Stack tuple x86_64-redhat-linux 

STL libraries and C + + standard library relationships:

STL Library and C + + standard library diagram (image from Network)

2. STL Architecture

STL Six components

STL mainly contains six large components, each component is responsible for different functions, but also involves a different knowledge point, which is the most important container and algorithm, the other components play the role of matchmaking, so that the algorithm and container can be fused better and more convenient to use. The general relationship between components such as (Pictures from the network):

The interaction of the six components: container (container) through the allocator (configurator) to obtain data storage space, algorithm (algorithm) through iterator (iterator) access to container (container) content, functor (functor) can assist Algorithm (algorithm) accomplishes different policy changes, adapter (adapter) can modify or socket functor (functor).

3. Analyze the skills required to implement STL

In the first section of effective C + +, we summarize that C + + is a multi-paradigm programming language that supports process forms, object-oriented forms, function forms, generic forms, and meta-programming forms. In our usual development process, the contact is more of the process and object-oriented form. While STL is the generalization of generic programming (GP), then for GP, we must have the foundation of template programming, understand the class template, function template, member function template, template Special, template partial special and so on. Then there is the familiarity with operator overloading, because the elements stored in the STL are indeterminate (generics), and for these user-defined types, there is also a need to have operations that are similar to basic types (like int)

In general, templates and operator overloading are a necessary technical basis for learning STL.

4. Study the gains of STL

When I am learning something, I always ask myself, why should I study this thing? So what does it take to master the STL?

1. First, for the C + + language, C + + can be divided into four parts, c,object-oriented c++,template c++,stl (Effective C + + summary), then in order to have a comprehensive understanding of C + + and master, We need to understand and study STL and master the idea of generics. Of course, now, C + + 11/17/20 and boost the use of the original C + + optimization, related advanced features, as well as some other advanced technology implementation and encapsulation (multi-threaded and multi-process, etc.), is also a modern C + + components, also need us to learn and master.

2. Turing Award winner Pascal's father--nicklaus Wirth once said that program design = algorithm + data structure, just, for those who want to learn or consolidate the data structure and algorithm capabilities, STL is a treasure trove, the bottom of the container is a variety of classical data structure to achieve, The basic algorithms are also included in the mainstream.

Therefore, the analysis and summary of STL, and to achieve, can improve our language mastery and related programming thinking, there is data abstraction ability!

2018-08-29 23:27:46

Introduction to the C + + Standard Template Library (STL)

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.