SFINAE time and time again. Here is another parameter that is not specified in the return data types, but allows you to specify arguments.
(For comparison: the approach by @ Jarod42 verifies the exact signature, returns type + arguments, another void_t expression sfinae stuff expression still checks if ham() can be called.)
In addition, it works with the current version of MSVC 2015 Update 1 (unlike the usual void_t material).
template<typename V, typename ... Args> struct is_callable_impl { template<typename C> static constexpr auto test(int) -> decltype(std::declval<C>().ham(std::declval<Args>() ...), bool{}) { return true; } template<typename> static constexpr auto test(...) { return false; } static constexpr bool value = test<V>(int{}); using type = std::integral_constant<bool, value>; }; template<typename ... Args> using is_callable = typename is_callable_impl<Args...>::type;
Use it like
struct foo { void ham() {} void ham() const {} int ham(int) const {} }; int main() { std::cout <<is_callable<foo>::value
Demo on coliru
However, for the βlatestβ sfinae materials, I suggest you take a look at
boost.hana .
source share