きままにブログ

プログラミングを主とした私のメモ帳です。寂しいのでコメントください笑

tupleを使った変数の交換

まあ、使い道はないです。参照を使うというのもなくはないかな~

int main() {
	using std::tuple;
	int x = 1, y = 2;

	tuple<int&, int&> t(x, y);
	t = std::make_tuple(y, x);
	printf("%d, %d", x, y); // 2, 1

	getchar();
	return 0;
}