Colon class § 3.2: Super Paradigm

Source: Internet
Author: User

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. ”

Related Article

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.