fork download
  1. template< class T >
  2. auto min(T a, T b ) ->decltype(a<b, a)
  3. {
  4. return a < b ? a : b;
  5. }
  6.  
  7.  
  8.  
  9. int main()
  10. {
  11. struct A{};
  12. auto x = min( 2, 3 ) ;// success
  13. auto a = A{};
  14. auto b = A{};
  15. auto c = min(a,b);// here is another error
  16. }
  17.  
Compilation error #stdin compilation error #stdout 0s 0KB
stdin
Standard input is empty
compilation info
prog.cpp: In function ‘int main()’:
prog.cpp:15:29: error: no matching function for call to ‘min(main()::A&, main()::A&)’
             auto c = min(a,b);// here is another error    
                             ^
prog.cpp:15:29: note: candidate is:
prog.cpp:2:14: note: template<class T> decltype (((a < b), a)) min(T, T)
         auto min(T a, T b ) ->decltype(a<b, a)
              ^
prog.cpp:2:14: note:   template argument deduction/substitution failed:
prog.cpp: In substitution of ‘template<class T> decltype (((a < b), a)) min(T, T) [with T = main()::A]’:
prog.cpp:15:29:   required from here
prog.cpp:2:41: error: no match for ‘operator<’ (operand types are ‘main()::A’ and ‘main()::A’)
         auto min(T a, T b ) ->decltype(a<b, a)
                                         ^
prog.cpp:12:18: warning: unused variable ‘x’ [-Wunused-variable]
             auto x = min( 2, 3 ) ;// success
                  ^
stdout
Standard output is empty