Templates provide a way to make a class, function, or variable operate with different data types without having to rewrite the code for each type.
This example shows a function
that swaps two integer arguments.
void swap(int& a, int& b)
int tmp = a;
a = b;
b = tmp;
To convert this method into a function template that can work with any type, the first step is to add a template parameter declaration before the function. This declaration includes the template keyword followed by the keyword typename and the name of the template type parameter, both enclosed between angle brackets. ...