In the CUDA header file, /usr/local/cuda/targets/x86_64/linux/include/texture_fetch_function.h
, there is the following statements:
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. But what does the latter mean? I have never seen such C syntax before. Could anyony explain it? Thanks in advance.
CodePudding user response:
template<>
introduces an explicit specialization of a previously declared (primary) template (here the first line). 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.
Basically it replaces the definition of the template for the specific specialization determined by the template-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.
CodePudding user response:
It's called template specialization.
Edit: Removed low-quality link.