According to the documentation, __traits(hasMember, ...) is supposed to work with any type that has members, but I can't get code that uses it with classes to compile. Observe the following snippet:
struct A {
int foo;
}
static assert(__traits(hasMember, A, "foo"));
This compiles (though it won't link because there's no main). But if I change "struct A" to "class A", the static assert fires and the code will not compile. I can't find anything in the bug tracker and it seems like this is a big E on the eye chart sort of thing. Am I doing something wrong?
--Edit: Following the example of getMember, it appears that hasMember only works on the class if foo is static. Alternatively, I can instantiate an A and test the instance with for a non-static foo. The problem is, I need to test the existence of a non-static member of a class at compile time.