// Example 10.9. Test program for templated swap #include using namespace std; template void swap(T& x, T& y); int main() { char s = '*', t = '$'; cout << "Before swap s = " << s << ", t = " << t << endl; swap(s, t); cout << "After swap s = " << s << ", t = " << t << endl << endl; float u = 3.3, v = 4.4; cout << "Before swap u = " << u << ", v = " << v << endl; swap(u, v); cout << "After swap u = " << u << ", v = " << v << endl; return 0; } // // Templated function to swap the values in two parameters // Pre: x and y have values of the same type. // Post: The values of x and y have been swapped. // template void swap(T& x, T& y) { T temp; temp = x; x = y; y = temp; }