Meta programming 学习 <二> Template parameter
来源:互联网 发布:最近网络流行的词语 编辑:程序博客网 时间:2024/05/20 23:04
三类元素可以做为模板变量:
Type template parameter
Non-type template parameter: int/short/char/enum , object ptr (必须指向全局/静态对象), function ptr, object refrence.
template as template parameter
具体参见如下代码:
#include<iostream>//all kinds of template parameters//1. type template parametertemplate<class T>struct tpl_type{ typedef T type;};//2. Non-type tmeplate paramter//2.1 inttemplate<int N>struct tpl_int{ enum {value = N};};//2.2 enumenum EType{ e_type_0 = 0, e_type_1 = 1};template<EType eType>struct tpl_enum{ static const EType value = eType;};//2.3 object ptr;class A {};template<A* ptr>struct tpl_obj_ptr{ static A* get_value(){ return ptr;}};A g_a;//2.4 func ptrtypedef int (*fun_ptr)(int);int fun_1(int c){ std::cout << c << std::endl; }template<fun_ptr f_ptr>struct tpl_fun_ptr{ static fun_ptr get_value(){ return f_ptr; }};//2.5 obj_reftemplate<A& ref>struct tpl_obj_ref{ static A& get_value(){ return ref;}};//template template parametertemplate< class T1, template<class T> class inner_tpl >struct tpl_tpl{ typedef inner_tpl<T1> type;};int main(){ //type template parameter tpl_type<int>::type tpl_type_instance; tpl_type< tpl_type<int> >::type tpl_type_instance_2; //non-type template paramter tpl_int<3>::value; tpl_enum<e_type_1>::value; tpl_obj_ptr< &g_a >::get_value(); tpl_obj_ref< g_a >::get_value(); (tpl_fun_ptr<fun_1>::get_value())(3); //template template parameter tpl_tpl<int,tpl_type>::type tpl_tpl_instance; system("pause");}
- Meta programming 学习 <二> Template parameter
- 感受Template Meta Programming
- Template Meta-programming
- C++: template meta programming, emample 1
- template programming学习(1) ---- member template
- 《C++ primer》学习笔记之二十六:None-type template parameter
- template template parameter
- template programming 学习(3) Argument dependent lookup
- template programming学习(2) ---- function template arguments type deduction
- meta programming
- XSLT学习(二)template
- template template parameter模板模板参数笔记----C++学习之路
- c++ template template parameter以及error C3201
- Template template parameter(模板参数) example
- C++: typename in a template template parameter
- Programming Ruby学习笔记二
- 《Programming.C#》学习笔记二
- Meta programming 学习〈一〉Meta programming 是一种新语言,一种新的编程方式
- dig命令使用大全(linux上域名查询)
- hdu 1009
- 简明Linux命令行笔记:tr
- 简明Linux命令行笔记:uniq
- 简明Linux命令行笔记:wc
- Meta programming 学习 <二> Template parameter
- linux net_bridge结构简介
- 简明Linux命令行笔记:fmt
- 《Windows网络与通信程序设计》读书笔记----可伸缩服务器系统设计实例
- 不需要显式地声明tld路径了
- ubuntu下emacs的配置(cedit,ecb)
- 在一台Windows电脑上安装多个Mysql服务的方法
- 简明Linux命令行笔记:comm
- 链表的基本操作