I am reviewing a selection sort algorithm written in C++ and above the functions `template <typename T>` is present. I wonder: What is the purpose of it in this example?
The idea is that the function can be called for any type, whatever T may be, and the compiler will generate a version of the function accepting that type as a parameter, and working on that type within the function (as is typical).
In the case of "find_smallest", it fashions a function that can accept a vector holding any type T, such that all calls to "arr" assume that the vector is holding T's.
Within the function, T smallest will create a variable called "smallest" of type T, as described by the "template parameter".
That receives a copy of a T from "arr[0]", which may not be safe if the vector has no contents (size is zero).