traits and class protection

Lutger Blijdestijn lutger.blijdestijn at gmail.com
Tue May 3 06:02:09 PDT 2011


Adam D.  Ruppe wrote:

> Is there a way in today's D to exclude members marked private and
> protected from processing in the __traits(allMembers) family of
> functions?
> 
> I thought if I at least put it in a separate module, trying to get
> a private member would fail to compile, but I tried it and it seems
> to work anyway... my private members are both showing up and being
> called from another module.
> 
> I'm open to filthy hacks too. Worst case is I can use a naming convention
> but I'd really like the public keyword to be the thing that actually
> matters.

Maybe some variation on the pimple idiom with opDispatch could work? It may 
be more trouble than its worth though. 

Most reflection mechanisms allow you to look at private symbols. This is 
probably not helpful to you, but whatever code that uses allMembers should 
just not do that and filter out private/protected members.




More information about the Digitalmars-d-learn mailing list