Skip to content

Instantly share code, notes, and snippets.

@zmij
Created February 2, 2016 21:09
Show Gist options
  • Save zmij/45af3de2d1f91928f2eb to your computer and use it in GitHub Desktop.
Save zmij/45af3de2d1f91928f2eb to your computer and use it in GitHub Desktop.
Check if object type is callable
namespace detail {
template <typename T>
struct has_call_operator {
private:
struct _fallback { void operator()(); };
struct _derived : T, _fallback {};
template<typename U, U> struct _check;
template<typename>
static std::true_type test(...);
template<typename C>
static std::false_type test(
_check<void (_fallback::*)(), &C::operator()>*);
public:
static const bool value =
std::is_same< decltype(test<_derived>(0)), std::true_type >::value;
};
} // namespace detail
template < typename T >
struct is_callable : std::conditional<
std::is_class< T >::value,
detail::has_call_operator< T >,
std::is_function<T> >::type {
};
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment