taming-cpp

Experiments with C++ and comparisons with C
git clone https://git.tronto.net/taming-cpp
Download | Log | Files | Refs | README

swap.cpp (253B)


      1 #include <iostream>
      2 
      3 template<typename S, typename T>
      4 void swap(S& a, T& b) {
      5 	S tmp = a;
      6 	a = b;
      7 	b = tmp;
      8 }
      9 
     10 int main() {
     11 	int x = 3;
     12 	std::string y = "1.0";
     13 	swap(x, y);
     14 	std::cout << "x: " << x << std::endl;
     15 	std::cout << "y: " << y << std::endl;
     16 }