加入收藏 | 设为首页 | 会员中心 | 我要投稿 李大同 (https://www.lidatong.com.cn/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 百科 > 正文

c – 模板别名的身份

发布时间:2020-12-16 03:05:00 所属栏目:百科 来源:网络整理
导读:让我们考虑一组模板别名: templateclass T using foo = T*;templateclass T using bar = T*;templateclass T using buz = fooT;template templateclassclass TT struct id {};using id_foo = idfoo;using id_bar = idbar;using id_buz = idbuz; id_foo,id_b
让我们考虑一组模板别名:
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是可互换的.

(编辑:李大同)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

    推荐文章
      热点阅读