views:

769

answers:

3

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
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
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
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
Thanks for that, I try not to abuse standard terminology.
Steve Jessop
+1  A: 

Function Template is the correct terminology (a template to instantiate functions from).

Template Function is a colloquial synonym.

So, there's no difference whatsoever.

+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