Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

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:

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.

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

>Solution :

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.

Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading