Skip to content

Instantly share code, notes, and snippets.

@pocarist
Created May 29, 2015 14:57
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save pocarist/881583ee19c9d1c897db to your computer and use it in GitHub Desktop.
Save pocarist/881583ee19c9d1c897db to your computer and use it in GitHub Desktop.
sample of has_mem_xxx.
// 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