文章标题
来源:互联网 发布:开源的cms 编辑:程序博客网 时间:2024/06/01 23:51
模板超编程是通过使用已经实例化出的代码来编程
#include <tuple>#include <iostream>#include <string>using namespace std;template <int IDX, int max, typename... Args>struct TUPLE_PRINT{ static void print(ostream& strm,const tuple<Args... >& t)//1 少const { strm << get<IDX>(t) << (IDX+1==max ? "" : ",") ; //IDX + 1 = max ? TUPLE_PRINT(max, t) : IDX ++; //注意1 TUPLE_PRINT<IDX+1,max,Args...>::print(strm,t); }};//partial specialization to end the recursiontemplate <int max, typename... Args>//注意2struct TUPLE_PRINT<max, max, Args...>{ static void print(ostream& strm, const tuple<Args... args>& t) { }}template <typename... Args>ostream& operator<<(ostream& strm, const tuple<Args...> &t){ strm << "[" << TUPLE_TUPLE<0,sizeof...(Args), Args...>::print(strm, t); return strm << "]";}void main(){ tuple<int,float,string> t(77,1.36,"more light"); cout << " " << t << endl;}//模板部分递归,之前在E中就不明白怎么结束递归//只知道用一个偏特化来结束,也不知道这个偏特化该怎么写://1:从注意1,可以看出我现在的念想还是,用值来控制,事实情况也确实是idx == max//结束递归,但事实情况是,让编译器自己去决定什么时候,跟重载一样,而且可以确定是//他一定可以工作的很好,另外两点,a,递归调用的怎么可能是类(除非他有operator())/*b:一个模板类用的时候,必须加上他的模板参数 2:注意2,A实在说不上是总结,因为我实在不懂,这个偏特化为什么是空的函数体?至少应该 把第max个元素输出吧 B 不得不注意的是,他的名字后面还有<paras>,且参数个数与原模板保持一致*/void main1(){ tuple<int,int,int>t{1,1,1}//have a try}
0 0
- 文章标题文章标题文章标题文章标题文章标题文章标题文章标题文章标题文章标题文章标题文章标题文章标题文章标题文章标题文章标题文章标题文章标题
- 文章标题
- 文章标题
- 文章标题
- 文章标题 文章标题 文章标题 文章标题
- 文章标题
- 文章标题
- 文章标题
- 文章标题
- 文章标题
- 文章标题
- 文章标题
- 文章标题
- 文章标题
- 文章标题
- 文章标题
- 文章标题
- 文章标题
- 跨平台线程库——pThread
- 收录常用正则表达式
- 水池数目
- NYOJ - 喷水装置(二)
- iOS开发实战:如何将非ARC的项目转换成ARC项目
- 文章标题
- matlab2014a中help与参考页翻译 roots
- 支付宝在ios中的应用1
- MVC设计模式与多层架构
- 1.JavaScript如何使用
- 嵌入式的精髓 —— 操作系统
- android raw与assets区别
- iOS Status bar 颜色改为白色
- windowManager.addView()抛出WindowManager$InvalidDisplayException异常