fork download
  1. #include <type_traits>
  2.  
  3. template <
  4. typename T,
  5. typename = typename std::enable_if <std::is_same <T, unsigned int>{}>::type
  6. >
  7. void f(T x) { }
  8.  
  9.  
  10. int main ()
  11. {
  12. int x;
  13. unsigned int y;
  14. f(x);
  15. f(y);
  16. }
  17.  
Compilation error #stdin compilation error #stdout 0s 3292KB
stdin
Standard input is empty
compilation info
prog.cpp: In function ‘int main()’:
prog.cpp:14:5: error: no matching function for call to ‘f(int&)’
  f(x);
     ^
prog.cpp:14:5: note: candidate is:
prog.cpp:7:6: note: template<class T, class> void f(T)
 void f(T x) { }
      ^
prog.cpp:7:6: note:   template argument deduction/substitution failed:
prog.cpp:5:2: error: no type named ‘type’ in ‘struct std::enable_if<false, void>’
  typename = typename std::enable_if <std::is_same <T, unsigned int>{}>::type
  ^
stdout
Standard output is empty