#include #include using std::string; /* * Template functions can create generic versions of functions. * * Note: There are min() and max() in the standard library, which * should be inaccessible without the std:: prefix, but the code * breaks anyway, so I had to change the names. */ template T minimum(const T a, const T b) { if(a < b) return a; else return b; } template T maximum(const T a, const T b) { if(a < b) return b; else return a; } int main() { std::cout << minimum(15, 46) << " " << maximum(58,32) << std::endl; std::cout << minimum(4.8, -5.6) << " " << maximum(3.45,32.33) << " " << maximum(-4.4, -8.52) << " " << maximum(4.8, 7) << std::endl; std::cout << minimum(string("Fred"), string("Barney")) << " " << maximum(string("Alice"), string("Sally")) << std::endl; }