What is the difference between function template and template function?
+5
A:
The term "function template" refers to a kind of template. The term "template function" is sometimes used to mean the same thing, and sometimes to mean a function instantiated from a function template. This ambiguity is best avoided by using "function template" for the former and something like "function template instance" or "instance of a function template" for the latter. Note that a function template is not a function. The same distinction applies to "class template" versus "template class".
From this FAQ.
Tim Sylvester
2009-07-13 04:58:54
Agree with the general points, however, I don't agree with the FAQ that "instance of a function template" is the term to use. IMHO, "function template specialization" is closer to the standard terminology. There's also the question about what to call functions and classes that are not themselves templates but are members of a class template. They have a lot of behaviour in common with function templates but it's not correct to call them "function templates".
Richard Corden
2009-07-13 08:26:53
I have the impression that when people say "template specialization", they mean an explicitly defined partial or full specialization (obviously always full in the case of a function template), rather than the function/class which the compiler creates from a definition of a template. I've often seen "instantiation" used for the latter. Does the standard refer to the latter as a specialization too?
Steve Jessop
2009-07-13 10:16:11
IMHO a name such as "A < int >" is a specialization no matter what it's context. It may be used as part of an explicit instantiation or an explicit or partial specialization. But I also consider that it is a specialization where it is used to declare an object, eg: "A<int> * a;". Re the standard, 14.2/1 describes how a template specialization (14.7) can be referred to by the grammar term 'template-id' and 14.7 includes implicit instantiations.
Richard Corden
2009-07-13 16:14:34
Thanks for that, I try not to abuse standard terminology.
Steve Jessop
2009-07-14 11:54:31
+3
A:
Comeau Computing (maker of C++ Comeau Compiler) has a FAQ on their site with the answer to that question:
What is the difference between a template function and a function template?
Regards,
Ovanes
ovanes
2009-07-13 09:37:16