c – 模板别名的身份

让我们考虑一组模板别名:
template<class T> using foo = T*;
template<class T> using bar = T*;
template<class T> using buz = foo<T>;

template< template<class>class TT > struct id {};

using id_foo = id<foo>;
using id_bar = id<bar>;
using id_buz = id<buz>;

id_foo,id_bar,id_buz是否相同或不同? foo,bar,buz是相同还是不同的模板?

各种编译器对此有不同的看法.
尤其,

> MSVC 2015和cl ang 3.5对待他们都不同
> gcc 4.9对待buz与foo相同

第14.5.7节“别名模板”中的标准C 11不清楚.

解决方法

正如 T.C.his comment指出的那样,这是 known hole的标准.

The current wording of 14.5.7 [temp.alias] deals only with the equivalence of a specialization of an alias template with the type-id after substitution. Wording needs to be added specifying under what circumstances an alias template itself is equivalent to a class template.

也就是说:foo,bar和buz的任何专业化将代表相同的类型.但不能保证,当用作模板参数时,foo,bar和buz是可互换的.

相关文章

本程序的编译和运行环境如下(如果有运行方面的问题欢迎在评...
水了一学期的院选修,万万没想到期末考试还有比较硬核的编程...
补充一下,先前文章末尾给出的下载链接的完整代码含有部分C&...
思路如标题所说采用模N取余法,难点是这个除法过程如何实现。...
本篇博客有更新!!!更新后效果图如下: 文章末尾的完整代码...
刚开始学习模块化程序设计时,估计大家都被形参和实参搞迷糊...