View mode: basic / threaded / horizontal-split · Log in · Help
May 01, 2011
traits and class protection
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 03, 2011
Re: traits and class protection
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.
Top | Discussion index | About this forum | D home