// Program to demonstrate function templates for a swap function. // Assignment-09 // swptmplt.cpp, Author - Krishna Kumar Khatri. // Uncomment ONLY the following line if you are using Turbo/Borland compiler. // #define TC #ifdef TC #include #else #include using namespace std; #endif #include // For getch. template void my_swap(T& a, T& b) { a = a - b; b = a + b; a = b - a; } int main() { #ifdef TC clrscr(); #endif int a = 1, b = 2; char x = 'x', y = 'y'; double p = 2.8, q = 8.2; cout << "Values before swap, " << endl; cout << "a = " << a << ", b = " << b << ", "; cout << "x = " << x << ", y = " << y << ", "; cout << "p = " << p << ", q = " << q << endl; swap(a, b); swap(x, y); swap(p, q); cout << endl << "Values after swap, " << endl; cout << "a = " << a << ", b = " << b << ", "; cout << "x = " << x << ", y = " << y << ", "; cout << "p = " << p << ", q = " << q << endl; cout << endl << endl << "Program over. Press any key to exit..."; getch(); return 0; // Successful termination. }