www.digitalmars.com         C & C++   DMDScript  

digitalmars.D.learn - traits for function having actual source declaration?

reply bitwise <bitwise.pvt gmail.com> writes:
When I'm using __traits(allMembers), I get a all the invisible 
functions added by the compiler as well "__ctor", "__xdtor", 
"__cpctor", etc..

Is there a way to filter them out?
Sep 01
next sibling parent reply bitwise <bitwise.pvt gmail.com> writes:
On Friday, 1 September 2017 at 14:38:38 UTC, bitwise wrote:
 When I'm using __traits(allMembers), I get a all the invisible 
 functions added by the compiler as well "__ctor", "__xdtor", 
 "__cpctor", etc..

 Is there a way to filter them out?
dlang's "Lexical" page says: "Identifiers starting with __ (two underscores) are reserved." So I suppose I could just filter out functions with leading underscores, but still seems unreliable, as people may not listen.
Sep 01
parent reply ketmar <ketmar ketmar.no-ip.org> writes:
bitwise wrote:

 On Friday, 1 September 2017 at 14:38:38 UTC, bitwise wrote:
 When I'm using __traits(allMembers), I get a all the invisible functions 
 added by the compiler as well "__ctor", "__xdtor", "__cpctor", etc..

 Is there a way to filter them out?
dlang's "Lexical" page says: "Identifiers starting with __ (two underscores) are reserved." So I suppose I could just filter out functions with leading underscores, but still seems unreliable, as people may not listen.
they *should* listen. anyone who doesn't just aksing for troubles, and i see no reason to guard 'em further.
Sep 01
parent bitwise <bitwise.pvt gmail.com> writes:
On Friday, 1 September 2017 at 17:26:11 UTC, ketmar wrote:
 [...]

 they *should* listen. anyone who doesn't just aksing for 
 troubles, and i see no reason to guard 'em further.
Yeah...eventually came to the same conclusion ;) Thanks
Sep 01
prev sibling parent reply Jonathan M Davis via Digitalmars-d-learn writes:
On Friday, September 01, 2017 14:38:38 bitwise via Digitalmars-d-learn 
wrote:
 When I'm using __traits(allMembers), I get a all the invisible
 functions added by the compiler as well "__ctor", "__xdtor",
 "__cpctor", etc..

 Is there a way to filter them out?
You can use std.meta.Filter if you need to filter anything out of an AliasSeq like this, and whether you should be filtering out those functions is highly dependent on what you're doing - e.g. sometimes, you really want to get your hands on __ctor, whereas other times, that's not at all what you're looking for. But because it gives you everything, you have a choice, whereas if they were filtered out, then any code that needed to know about them would be screwed. - Jonathan M Davis
Sep 01
parent bitwise <bitwise.pvt gmail.com> writes:
On Friday, 1 September 2017 at 18:06:04 UTC, Jonathan M Davis 
wrote:
 [...]

 You can use std.meta.Filter if you need to filter anything out 
 of an AliasSeq like this, and whether you should be filtering 
 out those functions is highly dependent on what you're doing - 
 e.g. sometimes, you really want to get your hands on __ctor, 
 whereas other times, that's not at all what you're looking for. 
 But because it gives you everything, you have a choice, whereas 
 if they were filtered out, then any code that needed to know 
 about them would be screwed.

 - Jonathan M Davis
I'm working on a runtime reflection library, so there won't be any access to the actual type. Any access to constructors will have to be done through an interface like these: class Struct : Reflection { size_t size() const; void construct(void[] mem); } class Class : Reflection { Object createInstance() const; } The library is basically done, but needs polishing. Also, I'm stuck waiting for things like __traits() being allowed to bypass protection, which was recently decided upon, but not yet implemented (hopefully this hasn't been overturned again). Thanks
Sep 01