Skip to content

Instantly share code, notes, and snippets.

@Rapptz
Last active August 29, 2015 14:07
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save Rapptz/f756f50610af91f2b29d to your computer and use it in GitHub Desktop.
Save Rapptz/f756f50610af91f2b29d to your computer and use it in GitHub Desktop.
template<typename Function, typename Signature>
struct is_callable : std::false_type {
static_assert(std::is_function<Signature>::value, "Signature must be a function type");
};
struct is_callable_impl {
template<typename Function, typename Return, typename... Args,
typename R = decltype(std::declval<Function>()(std::declval<Args>()...))>
static std::is_same<Return, R> test(int);
template<typename...>
static std::false_type test(...);
};
template<typename Function, typename Return, typename... Args>
struct is_callable<Function, Return(Args...)> : public decltype(is_callable_impl::test<Function, Return, Args...>(0)) {};
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment