I have seen this question which allows one to check for the existence of a member function, but I\'m trying to find out whether a class has a member
I prefer to wrap it in macro.
test.h:
#include
template
struct void_type
{
using type = void;
};
template
using void_t = typename void_type::type;
#define HAS_TYPE(NAME) \
template \
struct has_type_##NAME: std::false_type \
{}; \
template \
struct has_type_##NAME>: std::true_type \
{} \
HAS_TYPE(bar);
test.cpp:
#include
struct foo1;
struct foo2 { typedef int bar; };
int main()
{
std::cout << has_type_bar::value << std::endl;
std::cout << has_type_bar::value << std::endl;
return 0;
}