What is STL?

Source: Internet
Author: User
STL

1. Introduction to STL

STL (Standard Template Library) is a collection of software developed by the HP lab. It was developed by Alexander Stepanov, Meng Lee, and David R musser while working at the HP lab. Although it mainly appears in C ++, this technology has existed for a long time before it was introduced into C ++.

In a broad sense, STL code is divided into three types: algorithm (algorithm), container (container), and iterator (iterator). Almost all the Code uses the template class and template function, this provides a better chance of code reuse than a traditional library composed of functions and classes. In the C ++ standard, STL is organized into the following 13 header files: <algorithm>, <deque>, <functional>, <iterator>, <vector>, <list>, <map>, <memory>, <numeric>, <queue>, <set>, <stack>, and <utility>. Below I will briefly introduce the main features of each part of STL.

Ii. Algorithms

One consensus that everyone can achieve is that the function library plays a crucial role in selecting data types for reusability. For example, the reusability of a square root function when floating-point numbers are used as its parameter type is definitely higher than the parameter class when integer is used as its parameter type. C ++ allows you to postpone the selection of Certain types through the template mechanism until you really want to use the template or make the template special, STL uses this to provide many useful algorithms. It completes these algorithms in an effective framework-you can divide all types into a few categories, then, you can use one type in the template parameter to replace other types in the same type.

STL provides about 100 template functions to implement algorithms. For example, the for_each algorithm calls the specified function for each element in the specified sequence, stable_sort uses the rules you specify to sort the sequence in a stable manner. In this way, as long as we are familiar with STL, many codes can be greatly simplified. By calling one or two algorithm templates, we can complete the required functions and greatly improve the efficiency.

The algorithm consists of the header file <algorithm>, <numeric>, and <functional>. <Algorithm> is the largest of all STL header files (though well understood). It is composed of a large number of template functions. It can be considered that each function is independent to a large extent, the commonly used functions include comparison, exchange, search, traversal, replication, modification, removal, reversal, sorting, and merging. <Numeric> it is very small. It only includes several template functions that perform simple mathematical operations on the sequence, including addition and multiplication operations on the sequence. <Functional> defines some template classes to declare function objects.

Iii. Container

In the actual development process, the importance of the data structure itself is not inferior to the importance of algorithms that operate on the data structure. When the program has a time-demanding part, the selection of data structures becomes more important.

The number of classic data structures is limited, but we often repeat some code written to implement vectors, linked lists, and other structures. These codes are very similar, it is just to adapt to the changes of different data and make some difference in details. The STL container provides us with this convenience. It allows us to reuse existing implementations to construct our own data structures of specific types. By setting some template classes, STL containers provide support for the most common data structures. The parameters of these templates allow us to specify the Data Types of elements in the container, which can simplify a lot of repetitive and tedious work.

The container consists of header files <vector>, <list>, <deque>, <set>, <map>, <stack>, and <queue>. For some commonly used containers and container adapters (which can be seen as containers implemented by other containers), you can summarize their relations with the corresponding header files through the following table.

Data Structure Description implementation header file

Elements continuously stored by vector <vector>

A list is a two-way linked list composed of nodes. Each node contains an element. <list>

An array consisting of pointers to different elements continuously stored in the deque queue <deque>

A set is a red-black tree composed of nodes. Each node contains an element, which is arranged by a certain predicate acting on the element pair, no two different elements can have the same order <set>

Multiple sets (Multiset) allow two sets of elements in the same order <set>

Arrange the values of the stack (stack) before, before, and after <stack>

Queue first-in-first-out orders <queue>

The order of priority_queue elements is determined by a certain predicate acting on the stored value pair. <queue>

Map is a set of {key, value} pairs that act on the predicates of a key pair. <map>

Multimap allows key pairs to be mapped in equal order. <map>

Iv. iterator

The iterator mentioned below is the most basic part in terms of its role, but it is more effort-consuming than the previous two (at least I do ). There is a basic principle in software design. All problems can be simplified by introducing an indirect layer, which is completed by the iterator in STL. In summary, the iterator is used in STL to associate the algorithm with the container and acts as a viscosity and agent. Almost all algorithms provided by STL work through the iterator to access the element sequence. Each container defines its own proprietary iterator to access the elements in the container.

The iterator consists of the header file <utility>, <iterator>, and <memory>. <Utility> is a small header file that includes declarations of several templates used throughout STL. <iterator> provides many methods used by the iterator, however, the description of <memory> is very difficult. It allocates storage space for elements in the container in an unusual way, and also provides a mechanism for temporary objects generated during Algorithm Execution, the main part of <memory> is the template class Allocator, which is responsible for generating default splitters in all containers.

There is also an explanation:

What is STL?

STL stands for scientific and technical accomplishments, but the hidden significance behind this phrase is for everyone.

STL may simply be regarded as a philosophical viewpoint, but it is never the case. It includes a complete set of educational methods, including science and technology in life and ideas of everyone, not only teachers and students but also ordinary citizens and politicians.

In order to meet the requirements of popularizing science and technology, the exclusion of Science and Technology and the attitude of teachers/scientists to science education must be fundamentally changed.

Science education in the classroom should be freed from the teacher-led and syllabus-centered education methods, instead of student-centered design, guidance, and organizational teaching. It is very important to enable students to devote themselves to learning motivation, and this will be stimulated only when science and technology become the daily needs of students.

With this in mind, we are now part of the modern world. This consciousness is more intense than before, and the acquisition of knowledge is increasingly irrelevant to the memory of facts. A micro-mobile phone can directly access the internet. This is the ability to express some factual information at our fingertips. As a result, it is meaningless for students to learn a large amount of facts (this is a very outdated knowledge.

Once these burdens are mitigated, all the students can discover the potential of science and technology. Science and technology are no longer seen as the treasure of the smartest student. The liberation of critical thinking. These ways of thinking that reveal information about challenges that are unreliable and have no justification for personal opinions, whether they come from 'experts' or advertising agencies or politicians.

The exclusive nature of many existing science and technology creates an atmosphere where morality and values come from arts and humanities. In fact, many of the ethical and value issues that need to be solved currently include science and technology, and exist in reality. In a democratic society, public opinions are important.

The purpose of scientific literacy-based education is not to cultivate scientists, but to cultivate citizens with scientific literacy. Scientific and Technological Consciousness provides the foundation for cultivating high-quality labor force and politically conscious citizens, and also provides the foundation for those who intend to become scientists, engineers or technicians.

Ts2000 + (technical science) intends to provide practical introductory knowledge for primary school teachers. Many challenges and ideas have been designed for classroom teaching. Based on their own experience, the author discusses the possible results of the activity, but never directly gives the 'answer '. These cases can be freely applied by everyone and adapted as they wish.

Ts2000 (technical science) is non-descriptive and seems to be ahead of the new era in terms of scientific literacy.

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.