is __traits(allMembers) usable in a non-deprecated way?

Atila Neves via Digitalmars-d digitalmars-d at puremagic.com
Fri Apr 8 02:50:52 PDT 2016


On Thursday, 7 April 2016 at 05:41:06 UTC, E.S. Quinn wrote:
> __traits(allMembers, <symbol>) has always been pretty much 
> essential to any non-trivial struct, class, or module-based 
> introspection, but given the visibility rules changes in 
> 2.071.0, it looks like it's not even allowed to check whether a 
> given symbol is public. (i.e. with __traits(getProtection, 
> Type, member))
>
> Is there a new, approved way of doing this?

I just had to change unit-threaded to get it to compile without 
deprecation warnings (and in one case a compiler error). I don't 
know of any approved way of doing it, I just did the first thing 
that worked, which was to check if something was private by:

private template isPrivate(alias module_, string moduleMember) {
     mixin(`import ` ~ fullyQualifiedName!module_ ~ `: ` ~ 
moduleMember ~ `;`);
     static if(__traits(compiles, 
isSomeFunction!(mixin(moduleMember)))) {
         enum isPrivate = false;
     } else {
         enum isPrivate = true;
     }
}


Notice the mixed-in import.

Atila


More information about the Digitalmars-d mailing list