Why can we not use __traits across protection?

drug drug2004 at bk.ru
Wed Apr 3 07:52:42 UTC 2019


On 03.04.2019 3:57, Alex wrote:
> On Tuesday, 2 April 2019 at 15:50:29 UTC, drug wrote:
> 
> 
> private template isPublic(alias aggregate, string member)
> {
>      static if (!is(Identity!(__traits(getMember, aggregate, member))) &&
>                 __traits(compiles, { auto s = __traits(getProtection, 
> __traits(getMember, aggregate, member)); }))
>              enum isPublic = !__traits(getProtection, 
> __traits(getMember, aggregate, member)).privateOrPackage;
>      else
>          enum isPublic = false;
> }
> 
> How does that work to get around the problem? It seems all it does is 
> return false if it fails and so assumes it to be private...
> 
> but this doesn't work in other traits that 

Ok, my usecase is the following - I need to process all members of some 
aggregate. But using traits with not accessible members fails. So I use 
`isPublic` to filter out not accessible members and then use other 
traits to process accessible members.


More information about the Digitalmars-d mailing list