c – 模板别名的身份

前端之家收集整理的这篇文章主要介绍了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是可互换的.

原文链接:https://www.f2er.com/c/112646.html

猜你在找的C&C++相关文章