●次のテンプレート関数2種(仮引数がポインタ型,仮引数が参照型)を完成させよ
※元のソースファイルはこちらからダウンロード。
 WebClassのこちらから提出すること。

#include <iostream>
using namespace std;

// 通常版 swap関数 (仮引数型はポインタ型)
void swapInt(int * ip1, int * ip2) {
	if (ip1 == 0 || ip2 == 0) return;
	int t;
	t = *ip1;
	*ip1 = *ip2; *ip2 = t;
}


// テンプレート版 myswap関数 (仮引数型はポインタ型)
template<class T> void myswap( /* ここを完成させる */ ) {
     // ここを完成させる
}

// テンプレート版 swap関数 (仮引数型は参照型)
template<class T>  void swapRef( /* ここを完成させる */ ) {
     // ここを完成させる
}


int main() {

	int a = 1, b = 2;
	double c = 10.0, d = 20.0;

	swapInt(&a, &b);
	cout << "a is " << a << " , b is " << b << endl;


	// テンプレート版 myswap関数 (仮引数型はポインタ型)の呼び出し
	myswap(&a, &b);
	cout << "a is " << a << " , b is " << b << endl; // int型でもOKだし…

	myswap(&c, &d);
	cout << "c is " << c << " , d is " << d << endl; // double型でもOK!

	// テンプレート版 myswap関数 (仮引数型は参照型)の呼び出し
	swapRef(a, b);
	cout << "a is " << a << " , b is " << b << endl; // int型でもOKだし…

	swapRef(c, d);
	cout << "c is " << c << " , d is " << d << endl; // double型でもOK!


	char ch; cin >> ch; // プログラムが終了しないようにする。。
	return 0;
}