Template allows to implement a generic functions that works with certain types. During compile time, type specific versions (image) of the function is generated.
template<typename T>
T mymax(T a, T b) {
return b < a ? a : b;
}
// calling mymax function
mymax(3, 4);
mymax<string>("abc", "def"); // can specify the type
template<typename T1, typename T2>
auto mymax(const T1& a, const T2& b) {
return b < a ? a : b;
}
std::common_type_t<T1, T2>