Check if a function is callable

Viewed 1055

I am using the is_callable structure defined as follows

template <typename F, typename... Args>
struct is_callable {
  template <typename U>
  static auto test(U* p) -> decltype((*p)(std::declval<Args>()...), void(), std::true_type());

  template <typename U>
  static auto test(...) -> decltype(std::false_type());

  static constexpr bool value = decltype(test<F>(nullptr))::value;
};

I am using this to test a lambda declared as:

template <typename T>
struct runner {
  T t;

  template <typename F, typename = typename std::enable_if<is_callable<F, T&>::value || is_callable<F, T&&>::value>::type>
  void run(F&& f) { 
    return f(t); 
  }
};

runner<int> a{0};
a.run([&] (auto& x) {
  x++;
});

Why does this fail compilation on the enable_if on AppleClang? Shouldn't the autos get deduced correctly?

2 Answers
Related