what's the difference between them?
There is no difference .
In the second case, you allow the compiler to perform type inference from the specialization signature. Therefore, both forms declare Swap<T>() specialization for T = int .
when to use one and when to use the other?
At your discretion, when one form or the other meets your requirements in terms of readability or ease of maintenance.
what is <> after the function name?
When this happens after the function name, this is the syntax for specifying the template arguments:
template<typename T = double, typename U = char> void foo(); foo<int, bool>();
When this happens after the template keyword, this is the syntax for introducing the specialization of the template (class or function).
source share