Article Title: C ++ automation (template element) programming basics and applications (1 ). Linux is a technology channel of the IT lab in China. Includes basic categories such as desktop applications, Linux system management, kernel research, embedded systems, and open source.
# If 0
Hello everyone, in this type of article, we will systematically introduce the basic knowledge of template metaprogramming. Most importantly
The purpose of such articles is to allow C ++ fans who are not familiar with the template element to enter the wonderful world of the template element as soon as possible.
Every article will only discuss one topic and try to clarify this topic as much as possible.
Now, let's get down to the truth. We all know that C ++ is a computer language. This is true, but you know that C ++
Does it contain another seed language? I'm afraid there will be no more people to know, and fewer people will be used. However
Since so many years of development, the emergence of this seed language (Template) in the C ++ language naturally has its roots.
This is not discussed in this article. For more information about C ++ development routines, see relevant literature.
The question that will be explained in this article is: why is C ++ template a language?
To answer this question, we must first consider what is a computer language.
Many basic computer tutorials are available. Here I give a narrow definition:
A computer language is used to express the selection structure and cyclic structure on a computer, and to perform four arithmetic operations on integers.
Obviously, C ++ is a computer language, and Basic, Fortran, Pascal, and so on are all computer languages. So many concepts are discussed to illustrate how C ++'s template syntax is a computer language. Because the template is an element of the C ++ language, you can call the C ++ template syntax a second-level or sub-language of C ++. In this article, we will use the template to implement four integer arithmetic operations, and select the structure and the cyclic structure to prove that the C ++ template syntax constitutes a complete computer language.
In addition, it is worth noting that the C ++ template language is completed during compiler compilation, so it is also called a static language, the common C ++ language is also known as the dynamic language or runtime language. It is precisely because the template language is completed during the compilation period that we can achieve the purpose of Automatically Generating Code by means of the computing during the compilation period, so as to implement C ++ automated programming. This will be discussed in detail in subsequent articles.
First, let's take a look at how the template completes the calculation during the compilation period.
[1] [2] [3] Next page