fork(1) download
  1. #include <string>
  2. #include <type_traits>
  3.  
  4. void foo(int, int){}
  5. void foo(std::string, std::string) {}
  6.  
  7. template <bool Val1, bool Val2, bool ...Rest>
  8. struct And
  9. {
  10. enum {value = And<Val1 && Val2, Rest...>::value};
  11. };
  12. template <bool Val1, bool Val2>
  13. struct And<Val1, Val2>
  14. {
  15. enum {value = Val1 && Val2};
  16. };
  17.  
  18. template <typename ...Params, typename ...Args, typename = typename std::enable_if<
  19. And<std::is_convertible<Args, Params>::value...>::value
  20. >::type>
  21. void Invoke(void (*fn)(Params...), Args ...args){}
  22.  
  23. int main() {
  24. Invoke(&foo, "a", "b");
  25. return 0;
  26. }
Compilation error #stdin compilation error #stdout 0s 15232KB
stdin
Standard input is empty
compilation info
prog.cpp: In function ‘int main()’:
prog.cpp:24:23: error: no matching function for call to ‘Invoke(<unresolved overloaded function type>, const char [2], const char [2])’
  Invoke(&foo, "a", "b");
                       ^
prog.cpp:21:6: note: candidate: template<class ... Params, class ... Args, class> void Invoke(void (*)(Params ...), Args ...)
 void Invoke(void (*fn)(Params...), Args ...args){}
      ^~~~~~
prog.cpp:21:6: note:   template argument deduction/substitution failed:
prog.cpp:18:49: error: mismatched argument pack lengths while expanding ‘std::is_convertible<Args, Params>::value’
 template <typename ...Params, typename ...Args, typename = typename std::enable_if<
                                                 ^~~~~~~~
stdout
Standard output is empty