Created
May 29, 2015 14:57
-
-
Save pocarist/881583ee19c9d1c897db to your computer and use it in GitHub Desktop.
sample of has_mem_xxx.
This file contains hidden or 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
// sample of has_mem_xxx. | |
// this can be compiled with MS VC2012. | |
#include <iostream> | |
#include <utility> | |
#include <type_traits> | |
template< typename T > | |
struct has_mem_xxx { | |
template< typename U > static std::true_type check( decltype( std::declval<U>().xxx )* ); | |
template< typename U > static std::false_type check( ... ); | |
static const bool value = std::identity<decltype(check<T>(nullptr))>::type::value; | |
}; | |
struct A | |
{ | |
int xxx; | |
}; | |
struct B | |
{ | |
int yyy; | |
}; | |
using namespace std; | |
int main() | |
{ | |
cout << has_mem_xxx<A>::value << endl; | |
cout << has_mem_xxx<B>::value << endl; | |
return 0; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment