Skip to content

Instantly share code, notes, and snippets.

@zmij
Last active February 1, 2017 08:33
Show Gist options
  • Save zmij/27dd10a80b7c9474b2fed303cd8d4f3e to your computer and use it in GitHub Desktop.
Save zmij/27dd10a80b7c9474b2fed303cd8d4f3e to your computer and use it in GitHub Desktop.
Metafunctions for checking for existence of member and free functions
template < typename T >
class has_FUNCTION_NAME_function {
template < typename U = T >
static ::std::true_type test(decltype(FUNCTION_NAME(::std::declval<T>()), void())*);
static ::std::false_type test(...);
public:
using type = decltype(test(nullptr));
static constexpr bool value = type::value;
};
template< typename T >
class has_MEMBER_NAME_member {
template < typename U = T>
static ::std::true_type test( decltype( &U::MEMBER_NAME )* );
static ::std::false_type test(...);
public:
using type = decltype(test(nullptr));
static constexpr bool value = type::value;
};
template < typename T, typename ... Args >
class has_MEMBER_NAME_member {
template < typename U = T>
static ::std::true_type
test( decltype(::std::declval<U>().MEMBER_NAME(::std::declval<Args>()...), void())* );
static ::std::false_type test(...);
public:
using type = decltype(test(nullptr));
static constexpr bool value = type::value;
};
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment