what is the difference between "traits" and "template specilazition"

cornerstone 2002-05-08 12:19:14
用template specilazition 似乎也可以实现trains 所实现的不同的type 选用不同的策率,它们之间有什么不同?
...全文
44 3 打赏 收藏 转发到动态 举报
写回复
用AI写文章
3 条回复
切换为时间正序
请发表友善的回复…
发表回复
cornerstone 2002-05-10
  • 打赏
  • 举报
回复
谢谢cber and prototype ,
mordern c++ design 久闻大名,可惜没有money 原版太贵了,
cber 2002-05-08
  • 打赏
  • 举报
回复
如果你可以找到Mordern C++ Design这本书的话,看看会对你有很大的好处的^_^

用traits可以让你基于不同的policy来组合生成不同的组件,而template specilization只能一次构造一个组件,在弹性方面不能和traits相等。
prototype 2002-05-08
  • 打赏
  • 举报
回复
i agree with cber.

actually, 'traits' is not a parallel concept to 'template specialization'. my understanding of 'traits' is a more general concept, it can be implemented using 'template specialization' (or 'partial specialization'), or 'tag' or whatever method. the application of 'traits' is not restricted to 实现的不同的type 选用不同的策率, either.

as far as 实现的不同的type 选用不同的策率 is concerned, traits can (but don't have to) be essentially the same as template (partial) specialization.

69,382

社区成员

发帖
与我相关
我的任务
社区描述
C语言相关问题讨论
社区管理员
  • C语言
  • 花神庙码农
  • 架构师李肯
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧