fork download
  1. #include <iostream>
  2.  
  3. template<typename A, typename B, typename C>
  4. C mymin (const A& a, const B& b)
  5. {
  6. if ( a < b )
  7. return (C) a;
  8. else
  9. return (C) b;
  10. }
  11.  
  12. int main()
  13. {
  14. double val1 = 66.8, val2 = 75.4 ;
  15.  
  16. std::cout << "min of " << val1 << " and " << val2 << " is: "
  17. << mymin<int,double,double>( val1, val2 ) << '\n' ;
  18.  
  19. std::cout << "min of " << val1 << " and " << val2 << " is: "
  20. << mymin<double,int,double>( val1, val2 ) << '\n' ;
  21.  
  22. std::cout << "min of " << val1 << " and " << val2 << " is: "
  23. << mymin<double,double,char>( val1, val2 ) << '\n' ;
  24.  
  25. char a[] = "12345", b[] = "abcde" ;
  26. std::cout << "min of " << a << " and " << b << " is: "
  27. << mymin<char*,char*,char*>( a, b ) << '\n' ;
  28.  
  29. char c[] = "abcde", d[] = "12345" ;
  30. std::cout << "min of " << c << " and " << d << " is: "
  31. << mymin<char*,char*,char*>( c, d ) << '\n' ;
  32. }
  33.  
Success #stdin #stdout 0s 2852KB
stdin
Standard input is empty
stdout
min of 66.8 and 75.4 is: 66
min of 66.8 and 75.4 is: 66.8
min of 66.8 and 75.4 is: B
min of 12345 and abcde is: 12345
min of abcde and 12345 is: abcde