Chinaunix首页 | 论坛 | 博客
  • 博客访问: 287899
  • 博文数量: 148
  • 博客积分: 4365
  • 博客等级: 上校
  • 技术积分: 1566
  • 用 户 组: 普通用户
  • 注册时间: 2008-07-05 21:38
文章分类
文章存档

2014年(2)

2013年(45)

2012年(18)

2011年(1)

2009年(54)

2008年(28)

我的朋友

分类: C/C++

2013-01-18 11:10:47

真心看得不是特别明白,看来我还是scott说得那种 normal programmer。侯大师认为是“正常”,我觉得是“普通”吧。


有一点类似函数式编程,但是模板元编程的主要工作是在编译时期,毕竟那会儿在模板展开,运行时期节省内存时间什么的。

书中和wiki上都举得是计算阶乘的例子。不清楚这个东西什么时候能变成主流,对脑力要求太高了。

	  template 
	  struct Factorial 
	  {
		  enum { value = N * Factorial::value };
	  };
	   
	  template <>
	  struct Factorial<0> 
	  {
		  enum { value = 1 };
	  };
	   
	  // Factorial<4>::value == 24
	  // Factorial<0>::value == 1
	  void foo()
	  {
		  int x = Factorial<4>::value; // == 24
		  int y = Factorial<0>::value; // == 1
	  }

阅读(699) | 评论(0) | 转发(0) |
给主人留下些什么吧!~~