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