The practical differences I think are (somewhat of a newbie so forgive any
inaccuracies)
On one hand function templates:
Are more flexible in that they work for types that don't yet exist!
e.g. A friendly programmer thinking of his collegues in the future, can
provide a function template for 'swap' which in most/many cases it will work
on new types. The current programmer can provide an algorithm that will be
useful to future programmers with future types in future code (as long as
all the types follow the same rules as the orignial type the template was
made for). E.g. 'swap' will for most standard objects. With a template, a
'swap' DOESN'T have to be written for each new type. The overloaded
functions only works for the types that exist. A new overloaded function has
to be created for each new type.
P.S. Even those types, that make sense to use the template function, but
don't quite fit the current template code, can be 'specialized'. Similar to
an overloaded function, in that they work with certain types only, a
particular version of the template must be written to match certain types
that don't generally conform. But there may be cases where no new code is
needed and the original authors function will work on many new types without
alteration.
On the other hand overloaded functions:
Are more flexible in the combinations of parmaters:
Currently I believe, with a function templates you can have a general case
that takes parameters of any type and a special case specialization for a
fixed set of know paramter types. What you can't do currently is partial
specialization where you specify a set of code for when you know the type of
some of the parameters but not all.
e.g. a swap( Unknown a, Unknown b) ok swap( int a, int b) have a special
version ok
swap( int a, Unknown b) not ok can't specify only some of the paramater
types.
Overloaded functions of course allow as many combinations as you are willing
to explicitly specify.
P.S. template classes, contrasting with function templates, do allow
partial specialization.
On the other hand with templates the compiler/you can get at a lot of
information
With templates the compiler knows a lot more about the types it is dealing
with. For instance C++ additions such as Loki and Boost allow a large number
of tests on the template types.
e.g. With a template function that can happily take a single item or a list,
the compiler can deduce what is being passed at compile time and
optimize/change accordingly.
Adding such knowledge to overloaded functions at compile time is harder.
On the other hand overloaded functions are safer?
I know many would disagree but with with vast numbers of template you can
get surprising situations. Because templates can match any type, certain
templates can be picked by the compiler that the programmer wasn't
expecting. I believe a change to class templates was made in respect to
this. When a class inherits a template, and within a function call is made,
which matches a global definition and an inherited template definition,
unlike standard class inheritance, compiler nowadays picks the global
definition. (Unless of course the tighter scope is specified in the call.).
On the other hand templates more fun to use:
I believe templates are extending C++ greatly and so trying to understand
them is a plus. If you have the time try being creative with templates.
[ See
http://www.gotw.ca/resources/clcm.htm for info about ]
[ comp.lang.c++.moderated. First time posters: Do this! ]