fork download
  1. #include <type_traits> // for std::enable_if, std::is_unsigned
  2.  
  3. template<typename A, typename B, typename = typename std::enable_if<std::is_unsigned<B>::value>::type>
  4. void someFunction(A * array, B numEl) {
  5.  
  6. }
  7.  
  8. int main(int argc, char ** argv) {
  9. int array[] = {1, 2, 3, 4, 5};
  10. someFunction(&array[0], (int)5); // call with signed type
  11. someFunction(&array[0], (unsigned int)5); // call with unsigned type
  12. }
Compilation error #stdin compilation error #stdout 0s 0KB
stdin
Standard input is empty
compilation info
prog.cpp: In function ‘int main(int, char**)’:
prog.cpp:10:32: error: no matching function for call to ‘someFunction(int*, int)’
prog.cpp:10:32: note: candidate is:
prog.cpp:4:6: note: template<class A, class B, class> void someFunction(A*, B)
prog.cpp:4:6: note:   template argument deduction/substitution failed:
prog.cpp:3:34: error: no type named ‘type’ in ‘struct std::enable_if<false, void>’
stdout
Standard output is empty