fork download
  1. #include <iostream>
  2.  
  3. template <typename... Ts> void foo_void(Ts...) = delete;
  4. void foo_void() { std::cout << "foo void" << std::endl; }
  5.  
  6. template <typename... Ts> void foo_int(Ts...) = delete;
  7. void foo_int(int) { std::cout << "foo int" << std::endl; }
  8.  
  9. void foo_both(int) { std::cout << "foo_both int" << std::endl; }
  10. void foo_both() { std::cout << "foo_both void" << std::endl; }
  11.  
  12. namespace detail
  13. {
  14. struct tag1
  15. {
  16. };
  17. struct tag : tag1
  18. {
  19. };
  20. }
  21.  
  22. #define CALL(name) \
  23.   namespace detail \
  24.   { \
  25.   template <typename Int> auto call_##name(Int i, tag1) -> decltype(name(i)) { return name(i); } \
  26.   \
  27.   template <typename Int> auto call_##name(Int, tag) -> decltype(sizeof(Int), name()) { return name(); } \
  28.   } \
  29.   \
  30.   void call_##name(int i) { return detail::call_##name(i, detail::tag{}); }
  31.  
  32. CALL(foo_int)
  33. CALL(foo_void)
  34. CALL(foo_both)
  35.  
  36. int main()
  37. {
  38. call_foo_void(42);
  39. call_foo_int(42);
  40. call_foo_both(42);
  41. }
  42.  
Success #stdin #stdout 0s 3296KB
stdin
Standard input is empty
stdout
foo void
foo int
foo_both void