Advertisement
Guest User

9

a guest
Jun 19th, 2019
71
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.92 KB | None | 0 0
  1. #include<iostream>
  2. #include<array>
  3. #include<algorithm>
  4.  
  5. //template <class T, class U>
  6. //std::pair<U, T> My_Swap(T a, U b) {
  7. // return std::make_pair(b, a);
  8. //}
  9. //
  10. //template <class T>
  11. //class MyClass {
  12. // T arr[3];
  13. //public:
  14. // MyClass(T a, T b, T c) :arr[0](a), arr[1](b), arr[2](c){}
  15. // T* get_arr() { return arr; }
  16. //};
  17.  
  18.  
  19. void main() {
  20. int a = 5;
  21. double b = 5.5;
  22. std::cout << "\n Before swap: " << a << " " << b;
  23.  
  24. auto temp = My_Swap(a, b);
  25. a = temp.second;
  26. b = temp.first;
  27. std::cout << "\n After swap: " << a << " " << b;
  28.  
  29. MyClass<int> c(0, 1, 2), d(5, 7, 9);
  30.  
  31. auto temp_2 = My_Swap(c, d);
  32. std::cout << "\n Before swap: ";
  33. for (int i = 0; i < 3; i++)
  34. std::cout << c.get_arr()[i] << " " << d.get_arr()[i] << std::endl;
  35. c = temp_2.second;
  36. d = temp_2.first;
  37. std::cout << "\n After swap: ";
  38. for (int i = 0; i < 3; i++)
  39. std::cout << c.get_arr()[i] << " " << d.get_arr()[i] << std::endl;
  40. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement