1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22
#include <iostream> #include <string> using namespace std; template <typename T> int compare(const T &v1, const T &v2) { if (v1 < v2) return -1; if (v2 < v1) return 1; return 0; } int main(void) { cout << compare(1, 0) << endl; cout << compare(string("hi"), string("world")) << endl; return 0; }