[英]What does this C++ syntax( template<> struct __nv_tex_rmnf_ret<char> {typedef float type;}; ) statement mean?
In the CUDA header file, /usr/local/cuda/targets/x86_64/linux/include/texture_fetch_function.h
, there is the following statements:在 CUDA header 文件
/usr/local/cuda/targets/x86_64/linux/include/texture_fetch_function.h
中有以下语句:
template<typename T> struct __nv_tex_rmnf_ret{};
template<> struct __nv_tex_rmnf_ret<char> {typedef float type;};
I understand the first statement is the definition of struct template.我理解第一条语句是struct template的定义。 But what does the latter mean?
但后者是什么意思? I have never seen such C++ syntax before.
我以前从未见过这样的 C++ 语法。 Could anyony explain it?
任何人都可以解释一下吗? Thanks in advance.
提前致谢。
template<>
introduces an explicit specialization of a previously declared (primary) template (here the first line). template<>
引入了先前声明的(主)模板(此处为第一行)的显式特化。 It has otherwise the same syntax as the primary template uses, except that the name in the declarator (here __nv_tex_rmnf_ret
) is replaced by a template-id (here __nv_tex_rmnf_ret<char>
) which should be valid for the primary template.它与主模板使用的语法相同,除了声明符(此处为
__nv_tex_rmnf_ret
)中的名称被替换为对主模板有效的模板 ID(此处__nv_tex_rmnf_ret<char>
)。
Basically it replaces the definition of the template for the specific specialization determined by the template-id.基本上,它替换了由模板 ID 确定的特定专业化的模板定义。
__nv_tex_rmnf_ret<char>
is now a class containing a typedef
for type
, but all other specializations __nv_tex_rmnf_ret<T>
where T
is not char
are completely empty classes. __nv_tex_rmnf_ret<char>
现在是 class 包含type
的typedef
,但所有其他__nv_tex_rmnf_ret<T>
其中T
不是char
是完全空的类。
It's called template specialization.这称为模板专业化。
Edit: Removed low-quality link.编辑:删除了低质量的链接。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.