双模板<>在模板专业化 [英] Double template<> in template specialization

查看:106
本文介绍了双模板<>在模板专业化的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

为什么下面的代码编译?我不是专门化模板类的模板成员函数,因此应该只使用一个 template<> 。但是,g ++编译它没有任何警告,clang ++只给出一个警告


警告:模板中的extraneous模板参数列表
specialization




  template< typename T> 
struct S {};

模板<>模板<> //为什么我们可以这样做?
struct S< int> {};

int main()
{

}


解决方案

因为语法允许它,并且在模板专门化部分下似乎没有任何禁止它的东西:



来自[gram.temp]


显式专业化



template< < / c $ c>





>

显式特化


语法太松懈,已在有效问题列表(#293)。


Why does the code below compile? I am not specializing a template member function of a template class, so only one template<> should be used. However, g++ compiles it with no warnings whatsoever, clang++ gives only a warning

warning: extraneous template parameter list in template specialization

template<typename T>
struct S{};

template<> template<> // why can we do this? 
struct S<int>{};

int main()
{

}

解决方案

Because the grammar allows it, and there doesn't seem to be anything under the template specialization section that prohibits it:

From [gram.temp]

explicit-specialization:

template < > declaration

From [gram.dcl]

declaration:

[...]

explicit-specialization

The fact that the grammar is too lax has been in the active issues list (#293) since 2001.

这篇关于双模板&lt;&gt;在模板专业化的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆