General paradigm of the third lesson (2)
3.2 Super Paradigm--raising the level of language
Intelligent Reproduction: Robot production Robot--preface
Keywords: programming paradigm, Template meta programming, metaprogramming, language-oriented programming, production programming
Absrtact: A brief talk on meta-programming
? Questions
What is metaprogramming? How is it different from the usual programming?
What's the use of metaprogramming? What are its applications?
What are the drawbacks of automatically generated code with the IDE compared to a custom metaprogramming program?
What are the advantages of language-oriented programming? How does it relate to metaprogramming?
What are the similarities and differences between meta programming and production programming?
Why is the META program a superlative program?
: Explain
Question Mark suddenly remembered one thing, asked: "Has a book called" C + + template Meta Programming "books, since mentions the template, wants to also belong to the generic programming? ”
The colon replied: "Template metaprogramming is template metaprogramming, closely related to generic programming, but it is subordinate to another programming paradigm-metaprogramming (metaprogramming), referred to as MP. Here the prefix ' meta-' often translated ' yuan ', in fact, is ' super ', ' the line ' means. For example, metadata (Metadata) is data about the data, the Meta object (MetaObject) is the object, and so on, metaprogramming is naturally about the program, or write, manipulate the program. ”
The exclamation mark frowned: "It sounds a little round." ”
The colon projects another piece of code--
C++(元编程):
template <int N>
struct factorial
{
enum { value = N * factorial<N - 1>::value };
};
template <> // 特化(specialization)
struct factorial<0> // 递归中止
{
enum { value = 1 };
};
void main()
{
cout << factorial<5>::value << endl; // 等价于 cout << 120 << endl;
}
The above uses the template element programming to realize the factorial operation. "The colon explains," is fundamentally different from the factorial implementations of the previous three core paradigms: the value of factorial is computed at compile time and not at runtime. In other words, this code generates new code in the form of a template and is executed during compilation. ”