Created
February 2, 2016 21:09
-
-
Save zmij/45af3de2d1f91928f2eb to your computer and use it in GitHub Desktop.
Check if object type is callable
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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