Advertisement
avr39ripe

PV024templateAdvanced

Nov 18th, 2020
124
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.82 KB | None | 0 0
  1. #include <iostream>
  2.  
  3. //template <typename T>
  4. //T max(T a, T b)
  5. //{
  6. //  return a > b ? a : b;
  7. //}
  8.  
  9. template <typename T1, typename T2>
  10. auto max(T1 a, T2 b)->decltype(a > b ? a : b)
  11. {
  12.     return a > b ? a : b;
  13. }
  14.  
  15. //int max(int, int); //std::cout << max(3, 4) << '\n';
  16. //double max(double, double); //std::cout << max(3.5, 4.5) << '\n';
  17. //double max(int, double); //std::cout << max(3, 3.5) << '\n';
  18. //double max(double, int); //std::cout << max(3.5, 3) << '\n';
  19.  
  20.  
  21. //int max(double a, int b)
  22. //{
  23. //  return a > b ? a : b;
  24. //}
  25. //int max(int a, int b)
  26. //{
  27. //  return a > b ? a : b;
  28. //}
  29. //
  30. //double max(double a, double b)
  31. //{
  32. //  return a > b ? a : b;
  33. //}
  34.  
  35.  
  36. int main()
  37. {
  38.     std::cout << max(3, 4) << '\n';
  39.     std::cout << max(3.5, 4.5) << '\n';
  40.     std::cout << max(3, 3.5) << '\n';
  41.     std::cout << max(3.5, 3) << '\n';
  42. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement