.
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 understandingCodePudding 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 logicThe 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 chestnutsA 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 codeCodePudding user response:
Compile time is running the code called metaprogrammingCodePudding 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 metaprogrammingCodePudding user response:
The