Home > Back-end >  Generic programming and C metaprogramming difference
Generic programming and C metaprogramming difference

Time:10-05

What is a metaprogramming
.

CodePudding user response:

This question is a bit big, it is suggested that to look at "c + + templates,"
Simple said is in fact the generic template programming,
Metaprogramming is a kind of using the template programming for a method of realization of the program logic at compile-time

CodePudding user response:

Generic programming good understanding

CodePudding user response:

If you understand the generic, then the following code is metaprogramming
 
Template
The class Pow3 {
Public:
Enum {
Result=3 * Pow3 & lt; N - 1 & gt; : : result};
};
Template<>
The class Pow3 & lt; 0 & gt; {
Public:
Enum {result=1};
};
Int main ()
{
cout }

CodePudding user response:

Template metaprogramming is the use of a feature: template class, the template function, at compile time depending on the template parameters, in order to realize certain logic
The above code, for example, compile time saw Pow3 & lt; 7 & gt; According to the specific parameters is 7, calculated the Pow3 & lt; 6 & gt; . Last order to Pow3 & lt; 0 & gt; , Pow3 & lt; 0 & gt; Is a specialized, his result=1; Finally returned in turn to calculate Pow3 & lt; 7 & gt; The result of

CodePudding user response:

Above me is the most simple chestnuts
A reflection of the more complex such as c + +

CodePudding user response:

Metaprogramming is a part of generic programming, but not the part instance directly into code

CodePudding user response:

Compile time is running the code called metaprogramming

CodePudding user response:

Yuan programming is programming programming, write a program to generate,
Similarly, metadata is describes data at https://baike.baidu.com/item/%E5%85%83%E6%95%B0%E6%8D%AE/1946090? Fr=Aladdin
Yuan learning is learning how to learn https://blog.csdn.net/qq_34886403/article/details/82664879
Yuan philosophy is the study of philosophy at https://baike.baidu.com/item/%E5%85%83%E5%93%B2%E5%AD%A6/1008459? Fr=Aladdin

Yuan=xx xx xx

When you master this kind of word formation, you can invent new nouns,

For example both you and your wife had a quarrel about whether to fight this problem, you this is yuan quarrel,


For c + + template programming is to write a program (template), is used to control the compiler a template to generate a bunch of code, code generation, code, so is a metaprogramming, any in order to generate the code and code, is a metaprogramming,

CodePudding user response:

You this is not a template specialization?

CodePudding user response:

Although metaprogramming can generate code, but it is ok that macro industry industry, macro can be called metaprogramming, I think I should call the template metaprogramming

CodePudding user response:

The
references to the tenth floor yshuise response:
although metaprogramming can generate code, but it is ok that macro industry industry, macro can be called metaprogramming, I think I should call the template metaprogramming


Macros can also calculate metaprogramming, but its programming is limited, so normally we don't call it programming, but different templates, template is Turing complete, this means that it can realize arbitrary function,

CodePudding user response:

Yuan=meta,

CodePudding user response:

Meta programming c + + is a programming use generic model, typical such as STL, Boost

CodePudding user response:

Yuan programming is used to generate code, manipulation of the code of the program, to create and modify the code at run time rather than programming, the program is called the yuan

CodePudding user response:

C + + template is static, not to create and modify the code at run time, unlike Java, c # generics

CodePudding user response:


Generic metaprogramming, scare away the novice or! Drain the compiler designer brain cells, but also slow down the compilation speed, eat up compilation of memory, generic compiler error is the most obscure, output a lot of,, generics are for library designers, and it is open source library,

CodePudding user response:

This question is a bit big, it is suggested that to look at "c + + templates,"
Simple said is in fact the generic template programming,
Metaprogramming is a kind of using the template programming for a method of realization of the program logic at compile-time

CodePudding user response:

Personal think metaprogramming is c + + is the most difficult part of the deepest inside,

CodePudding user response:

Metaprogramming is application runtime, generics are modal
  • Related