fork download
  1. #include <iostream>
  2. using namespace std;
  3.  
  4.  
  5. template<class T>
  6. struct RefValue
  7. {
  8. typedef const T& Tp;
  9. };
  10.  
  11. template<> struct RefValue<int>{typedef int Tp;};
  12.  
  13. template<class T>
  14. typename RefValue<T>::Tp mymin(typename RefValue<T>::Tp a, typename RefValue<T>::Tp b)
  15. {
  16. return a < b ? a : b;
  17. }
  18.  
  19. struct Obj{
  20. bool operator < (const Obj& other)const{return true;}
  21. };
  22.  
  23. int main() {
  24. // your code goes here
  25. Obj o1;
  26. Obj o2;
  27. int i10=10, i12=12;
  28. const int& z = mymin<int>(i10,i12);
  29. std::cout << "i10: " << &i10 <<
  30. " i12: " << &i12 <<
  31. " min: " << &z << "\n";
  32.  
  33. std::cout << mymin<int>(i10, i12);
  34.  
  35. const Obj& om = mymin<Obj>(o1, o2);
  36. std::cout << "\nObj1:" << (void*) &o1 << " Obj2:" << (void*) &o2;
  37. std::cout << "\nObj:" << (void*) &om << "\n";
  38.  
  39. return 0;
  40. }
Success #stdin #stdout 0s 3340KB
stdin
Standard input is empty
stdout
i10: 0xbfe44824 i12: 0xbfe44828 min: 0xbfe4482c
10
Obj1:0xbfe44822 Obj2:0xbfe44823
Obj:0xbfe44822