Last active
February 1, 2017 08:33
-
-
Save zmij/27dd10a80b7c9474b2fed303cd8d4f3e to your computer and use it in GitHub Desktop.
Metafunctions for checking for existence of member and free functions
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
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; | |
}; |
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
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; | |
}; |
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
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