C ++ to STL (2)

xiaoxiao2021-03-06  74

There is no STL without the C language, which is not too much. In general, STL acts as a genericized data structure and algorithm library, does not involve specific languages ​​(of course, in C , it is called STL). That is, if the condition is allowed, it can be implemented in other languages. The conditions mentioned here are mainly a grammar mechanism similar to "template". If you have not skip the content of the previous section, you should see that Alexander Stepanov is early to use a variety of programming languages ​​before choosing a C language as an implementation tool. However, why do you enduring this historic task in the end or C ? The reason is not only the above conditions, but also the superior features of C exhibited in certain aspects, such as efficient and flexible pointers. But if C is seen as an OOP (Object-Oriented Programming, the Object-Oriented Programming) language (in fact we generally think so, isn't it?), Its powerful inheritance mechanism is not given to STL How much is it to help? In the STL source code, there is no too much complex inheritance relationship. Inherited thoughts, even object-oriented ideas, is not enough to achieve generic libraries like STL. C only results in the birth of STL only after the "template" is introduced. This is why, using other more purely object-oriented languages ​​than C unable to achieve an important reason for generic ideas. Of course, things are always changed, like Java in this regard, is a good example, JDK1.4 has already joined the generic characteristics.

The template mechanism in C is an important reason why STL is implemented, not inheriting this useful mechanism.

In addition, STL has promoted the development of C , especially template mechanisms. For example: Template Function Partialization, it is used to provide a series of specialized versions for a particular template function in a specific application. This feature is followed by the ANSI / ISO C Standard Commission, and the Bjarne is discussed by Bjarne and Stepanov, and the Bjarne will be suggested to the Committee. This allows some algorithms in the STL to select a non-generalized manner when processing a special case, thereby ensuring the efficiency of the execution.

转载请注明原文地址:https://www.9cbs.com/read-110399.html

New Post(0)