17.模板元

 1 //模板元实现递归加速,编译的时候慢,代码会增加
 2 //把运行的时间节约在编译的时候
 3 //递归加速,游戏优化
 4 #include <iostream>
 5 using namespace std;
 6 
 7 template<int N>
 8 struct mydata
 9 {
10     enum{res=mydata<N-1>::res+mydata<N-2>::res};
11 };
12 
13 template<>
14 struct mydata<1>
15 {
16     enum { res = 1 };
17 };
18 template<>
19 struct mydata<2>
20 {
21     enum{    res = 2};
22 };
23 
24 void main()
25 {
26     cout << mydata<400>::res << endl;
27     system("pause");
28 }

 

posted @ 2018-03-11 15:02  喵小喵~  阅读(115)  评论(0编辑  收藏  举报