digitalmars.D - is __traits(allMembers) usable in a non-deprecated way?
-
E.S. Quinn
(7/7)
Apr 06 2016
__traits(allMembers,
) has always been pretty much - Atila Neves (17/24) Apr 08 2016 I just had to change unit-threaded to get it to compile without
- captaindet (5/31) Jul 05 2016 i just tried this trick for the first time. it does not seem to
__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?
Apr 06 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
Apr 08 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: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.__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
Jul 05 2016