fork download
  1. #include <string>
  2. #include <type_traits>
  3.  
  4. template<
  5. class T,
  6. class = typename std::enable_if<
  7. std::is_same<float,
  8. typename std::decay<T>::type>::value>::type>
  9. void function(T&& t){/*SNIP*/}
  10.  
  11. int main()
  12. {
  13. float f = 1.0f;
  14. const float& fr = f;
  15.  
  16. function(f); // OK
  17. function (fr); // OK
  18.  
  19. function(std::string()); // !OK
  20.  
  21. return 0;
  22. }
  23.  
Compilation error #stdin compilation error #stdout 0s 0KB
stdin
Standard input is empty
compilation info
prog.cpp: In function ‘int main()’:
prog.cpp:19:27: error: no matching function for call to ‘function(std::string)’
prog.cpp:19:27: note: candidate is:
prog.cpp:9:6: note: template<class T, class> void function(T&&)
prog.cpp:9:6: note:   template argument deduction/substitution failed:
prog.cpp:6:3: error: no type named ‘type’ in ‘struct std::enable_if<false, void>’
stdout
Standard output is empty