www.digitalmars.com         C & C++   DMDScript  

digitalmars.D.learn - traits and class protection

reply Adam D. Ruppe <destructionator gmail.com> writes:
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.
May 01 2011
parent Lutger Blijdestijn <lutger.blijdestijn gmail.com> writes:
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.
May 03 2011