STL generic programming and design new thinking
Foreword always remember, the purpose of writing code is to make it clear, do not use the language of the language, play smart, and important is to write your understanding code, understand the code you write, so you may do better. --- Herb SUTTER
In 1998, the international C standard was officially passed, and the standardization of C is the most important contribution to "powerful abstraction concept" gives more powerful support to reduce the complexity of software, and C provides two powerful abstract methods: Object-oriented programming and generic programming. Object-oriented programming, you must be very familiar, here no longer. Remove generic programming, some people may not be familiar, but mentioned STL, you will have to hear. STL (Standard Template Library) is actually the implementation of generic programming, STL is developed by Alexander Stepanov (Father), David R Musser and Meng Lee, is incorporated into C standard procedures in 1994 Library. Although STL is relatively late to join the C standard library, it is the most revolutionary part of the C standard library, and is also the most important part of the C standard library. Because almost everything in the new C standard library is made by template, of course, STL will not exceed So, there is a need to first explain the concept of the template. Template concept With a template to make the program better code reuse. Remember, the template is reused the source code, not by inheriting and combining reuse object code, when the user uses templates, the parameters are replaced by the compiler. The template consists of two parts of the class template and function template, with the description of the data type as the parameter is called class template, and the description of the data type is called a function template. Template parameters can be composed of type parameters or non-type parameters. The type parameters can be specified by Class and TypeName keywords. The two senses are the same, which means that the back parameter name represents a potential built-in or user-defined type, non-type parameters A normal parameter declaration composition. Here is a simple usage of class templates and function templates:
Template