C++STL Basic Knowledge

Source: Internet
Author: User
Tags mathematical functions

STL, the standard Template Library, is a highly efficient C + + library with industrial strength.

It is housed in the C + + standard library, which is the newest and most revolutionary part of the Ansi/iso C + + standard. The library contains many basic data structures and basic algorithms commonly used in computer science. For the vast number of C + + programmers to provide a scalable application framework, highly reflects the reusability of software. This behavior is somewhat similar to MFC (Microsoft Foundation Class Library) in Microsoft Visual C + + or VCL in Borland C + + Builder (visual Component Library).


From the logical level, the concept of generic programming is embodied in STL (generic programming), which introduces many new nouns, such as requirements (requirements), concepts (concept), model, Container (container), algorithm (ALGORITHMN), Iteration sub (iterator), etc. As with the polymorphism (polymorphism) in OOP (object-oriented programming), generics are also a reusable technique for software.


From the implementation level, the entire STL is implemented in a type-parameterized (type parameterized) way, based on a language feature that did not appear in the previous C + + standard-template. If you look at any one version of the STL source code, you will find that the template as the cornerstone of the entire STL is a true thing. In addition, there are many new features of C + + that provide convenience for STL implementations.


The STL is a subset of the latest C + + standard library, which occupies approximately 80% of the entire library's component. Templates that play a key role in implementing STL are flooded with almost the entire C + + standard function library. Here, it is necessary to take a look at what is included in the C + + standard library, and which of these are the standard template libraries (i.e. STL).


The C + + standard library provides a scalable, foundational framework for C + + programmers. We can get great convenience from it, and we can extend it by inheriting the existing classes and compiling the containers, algorithms, iterations, etc. that conform to the interface specification. It contains roughly the following components :


C standard Function library , basically maintained a good compatibility with the original C language library, despite a slight change. People will always be tempted to linger over the good old days, if you used to be a C programmer, you must have a deep understanding of this. Perhaps one thing that makes you wonder is that there are two sets of C libraries in the C + + standard library, one with a. h extension (such as <stdio.h>), and the other without (for example, <cstdio>). They are really not quite different.


The Language Support Section contains definitions of standard types and other features that are used elsewhere in the standard library or in specific applications.


Diagnostics (Diagnostics) Section , provides functions for program diagnosis and error, including exception handling (exception handling), assertion (assertions), error code Codes) three different ways.


General Utilities Section , which provides support for other parts of the C + + standard library, but you can also invoke the functionality in your own programs. For example: Dynamic memory management tool, date/time processing tool. Remember, the content here has also been generalized (that is, using a template mechanism).


A string (string) part that is used to represent and manipulate text. It provides plenty of functionality. In fact, the text is a string object, which can be thought of as a sequence of characters, the character type may be char, or wchar_t, and so on. The string can be converted to the char* type so that it can coexist with the previously written C + + code. Because at that time, except char*, nothing else.


The internationalization (internationalization) part , the encapsulation mechanism as one of the OOP features, plays a role in eliminating cultural and geographical differences, using locale and facet to provide a wide range of international support for programs, including support for various character sets , date and time representation, numeric and currency handling, and so on. After all, in China and in America, the habit of saying dates is different.


The container (containers) Section , an important part of the STL, covers a number of data structures, such as the linked list mentioned earlier, as well as vectors (similar to the dynamically increasing size of the array), queue (queue), stack (stacks) .... String can also be thought of as a container, and the method applicable to the container also applies to string. Now you can easily complete the homework for the data structure course.


The Algorithm (algorithms) section , an important part of the STL, contains about 70 general-purpose algorithms for manipulating a variety of containers while also manipulating the built-in arrays. For example, find is used to look up an element in a container equal to a particular value, For_each is used to apply a function to individual elements in the container, and sort is used to order the elements in the container. All of these operations are performed in a way that guarantees execution efficiency, so if the program becomes more efficient after you use these algorithms, you must first not doubt the algorithms themselves, and examine the other places of the program carefully.


The iterator (iterators) Section , an important part of the STL, cannot be combined with a perfect combination of containers and algorithms without the iterator's matchmaking. In fact, each container has its own iterator, and only the container knows how to access its own elements. It's a bit like a pointer, and the algorithm uses iterators to locate and manipulate elements in the container.


The value (numerics) section , which contains some mathematical functions, provides support for complex operations.


The input/output (input/output) section , which is the iostream part of the original standard library that has been templated, provides basic support for C + + program input and output. It is functionally compatible with the original iostream and adds a mechanism for exception handling and supports internationalization (internationalization).

In general, in the C + + standard function library, STL mainly contains containers, algorithms, iterators. String can also be counted as part of the STL.

650) this.width=650; "src="/e/u261/themes/default/images/spacer.gif "style=" Background:url ("/e/u261/lang/zh-cn/ Images/localimage.png ") no-repeat center;border:1px solid #ddd;" alt= "Spacer.gif"/>




 

This article is from the "pin-soil" blog, please be sure to keep this source http://3240611.blog.51cto.com/3230611/1622028

C++STL Basic Knowledge

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.