fork download
  1. template< class T >
  2. auto min( T a, T b ) -> decltype(a)
  3. {
  4. return a < b ? a : b;
  5. }
  6.  
  7.  
  8.  
  9.  
  10. int main()
  11. {
  12. struct A{};
  13. auto x = min( 2, 3 ) ;// success
  14.  
  15. auto a = A{};
  16. auto b = A{};
  17. auto c = min(a,b);// here is error
  18. }
Compilation error #stdin compilation error #stdout 0s 0KB
stdin
Standard input is empty
compilation info
prog.cpp: In function ‘int main()’:
prog.cpp:13:10: warning: unused variable ‘x’ [-Wunused-variable]
     auto x = min( 2, 3 ) ;// success
          ^
prog.cpp:17:10: warning: variable ‘c’ set but not used [-Wunused-but-set-variable]
     auto c = min(a,b);// here is error    
          ^
prog.cpp: In instantiation of ‘decltype (a) min(T, T) [with T = main()::A; decltype (a) = main()::A]’:
prog.cpp:17:21:   required from here
prog.cpp:4:16: error: no match for ‘operator<’ (operand types are ‘main()::A’ and ‘main()::A’)
       return a < b ? a : b;
                ^
prog.cpp: In function ‘decltype (a) min(T, T) [with T = main()::A; decltype (a) = main()::A]’:
prog.cpp:5:4: warning: control reaches end of non-void function [-Wreturn-type]
    }
    ^
stdout
Standard output is empty