模板元中的类型分类技术(type classification)
来源:互联网 发布:java 内部类构造函数 编辑:程序博客网 时间:2024/06/05 19:22
如果模板的参数T是指针,引用或者是数组类型,需要判断T究竟是哪一种。比如是指针类型,需要知道其所指的类型baseT和最终所涉及到的基本类型bottomT,
例如对于int **,baseT的类型是int*, botton的类型是 int。 int *&类型,baseT的类型是int*, bottomT的类型是int。 typedef int* parr[]; baseT的类型是int*, bottom的类型是int。
template <typename T>class Type{public:enum{ IsPtr = 0; IsRef = 0; IsArr = 0 };typedef T baseT;typedef T bottomT;};template <typename T> //偏特化版本class Type<T*>{public:enum{ IsPtr = 1; IsRef = 0; IsArr = 0 };typedef T baseT;typedef typename Type<T>::bottomT bottomT; };template <typename T> //偏特化版本class Type<T&>{public:enum{ IsPtr = 0; IsRef = 1; IsArr = 0 };typedef T baseT;typedef typename Type<T>::bottomT bottomT;};template <typename T, size_t N> class Type<T[N]>{public:enum{ IsPtr = 0; IsRef = 0; IsArr = 1 };typedef T baseT;typedef typename Type<T>::bottomT bottomT;};
通过枚举量来标记类型,typedef typename Type<T>::bottomT bottomT; 这句丢掉*, &, [];使bottomT采用上一级的bottomT,这句可能会产生递归,比如对于int** , 则该句为 typedef typename Type<int*>::bottomT bottomT 对于上一级的int * , 则该句为typedef typename Type<int>::bottomT bottomT, 根据非特化版本,bottomT为int类型。
0 0
- 模板元中的类型分类技术(type classification)
- 类型分类技术(type classification)
- 类模板以及其中的traits技术和type classification技术
- CSS 分类 (Classification)(十八)
- [原创]WCF技术剖析之十三:序列化过程中的已知类型(Known Type)
- WCF技术剖析之十三:序列化过程中的已知类型(Known Type)
- 深度学习caffe中的分类程序(classification)制作成动态链接库(dll)
- 计算机视觉中的——图像集分类(image set classification)
- C#中的枚举类型(enum type)
- css手册(七)Classification 分类
- 多标签分类(multilabel classification )
- 多标签分类(multilabel classification )
- 多标签分类(multilabel classification )
- 数据挖掘-目录-分类器(classification)
- 分类(Classification):Probability Generative Model
- 多标签分类(multilabel classification )
- C++模板元编程技术
- C++模板元编程技术
- Algorithm: Multiply permutations in cycle form-2
- 1020. Tree Traversals (25)
- 携程瘫痪非偶然 国内互联网企业漠视数据管理
- 开源 java CMS - FreeCMS2.3 移动app生成站点列表数据
- 网站开发搭建开发环境
- 模板元中的类型分类技术(type classification)
- android启动之子系统切换
- android 镜像汇总
- 独立需求 段阶
- Algorithm: Multiply permutations in cycle form
- js addEventListener如何给触发,事件动态传参与添加/删除
- vc++使用GDI+的准备工作
- opencv实现图像优化
- 托管仓库