is __traits(allMembers) usable in a non-deprecated way?
captaindet via Digitalmars-d
digitalmars-d at puremagic.com
Tue Jul 5 22:28:37 PDT 2016
On Friday, 8 April 2016 at 09:50:52 UTC, Atila Neves wrote:
> 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
i just tried this trick for the first time. it does not seem to
work for me (Windows/DMD32 D Compiler v2.071.1): it alway returns
false, even for private members. is there another way? (i have
the same problem as OP.
More information about the Digitalmars-d
mailing list