fork download
  1. #include <iostream>
  2. #include <type_traits>
  3.  
  4. template<typename T>
  5. typename std::enable_if<!std::is_const<T>::value>::type f(T& arg)
  6. {
  7. std::cout << arg << ':' << __PRETTY_FUNCTION__ << std::endl;
  8. }
  9.  
  10.  
  11. int main()
  12. {
  13. int x=0;
  14. const int y=1;
  15. f(x);
  16. f(y); // errror. no matching function
  17. return 0;
  18. }
Compilation error #stdin compilation error #stdout 0s 0KB
stdin
Standard input is empty
compilation info
prog.cpp: In function ‘int main()’:
prog.cpp:16:8: error: no matching function for call to ‘f(const int&)’
     f(y); // errror. no matching function
        ^
prog.cpp:16:8: note: candidate is:
prog.cpp:5:57: note: template<class T> typename std::enable_if<(! std::is_const< <template-parameter-1-1> >::value)>::type f(T&)
 typename std::enable_if<!std::is_const<T>::value>::type f(T& arg)
                                                         ^
prog.cpp:5:57: note:   template argument deduction/substitution failed:
prog.cpp: In substitution of ‘template<class T> typename std::enable_if<(! std::is_const< <template-parameter-1-1> >::value)>::type f(T&) [with T = const int]’:
prog.cpp:16:8:   required from here
prog.cpp:5:57: error: no type named ‘type’ in ‘struct std::enable_if<false, void>’
stdout
Standard output is empty