Template Function vs Function Template

if a function template is
1
2
 template <typename T>
 void f(T) { puts("master"); }


and a template function is
void f(boost::optional<bool>) { puts("optional<bool>"); }

What is so special about the template function?

Code from: https://akrzemi1.wordpress.com/2015/11/19/overload-resolution/
Last edited on
There's no such thing as "template function".
Your second code excerpt is just... a function.

A function template generates functions, as the article mentions. Andrzej's use of "template function" is his own terminology which he notes is not used by the C++ standard itself.

The bigger point is the talk about overload resolution, which is the name of the article.
If you want another article that talks about overload resolution, there's also https://en.cppreference.com/w/cpp/language/overload_resolution

Overload resolution is needed when there is more than one possible candidate when a function call is made. The compiler needs to determine which function it is actually calling; there is only one right answer. Generally, you can think of it being the more specific possible function that is chosen when looking at different templates/functions, but the exact rules are much more detailed.

I think the article you linked does a good job at boiling down the essentials.
Last edited on
The latter is not even considered a template at all, since the boost::optional template class is already instantiated with bool. Therefore, it is just a regular function that takes a regular class instance as a parameter.
Nice, I searched around and did not find anything about " template function". So I believe there is no such a thing either. Thanks guys!
Registered users can post here. Sign in or register to post.