using __traits to get line number of a member

2021-11-12 Thread forkit via Digitalmars-d-learn
Code below is self explanatory. Any assistance on how to get the line number is welcome ;-) // ++ module test; import std; class myClass{ void foo(){}} void myFunction1(){} void main() { // list the first user defined member of this module (other than main)

Re: using __traits to get line number of a member

2021-11-12 Thread Stanislav Blinov via Digitalmars-d-learn
On Saturday, 13 November 2021 at 05:31:51 UTC, forkit wrote: Code below is self explanatory. Any assistance on how to get the line number is welcome ;-) https://dlang.org/spec/traits.html#getLocation That?

Re: using __traits to get line number of a member

2021-11-12 Thread forkit via Digitalmars-d-learn
On Saturday, 13 November 2021 at 06:05:37 UTC, Stanislav Blinov wrote: On Saturday, 13 November 2021 at 05:31:51 UTC, forkit wrote: Code below is self explanatory. Any assistance on how to get the line number is welcome ;-) https://dlang.org/spec/traits.html#getLocation That? Thanks. That

Re: using __traits to get line number of a member

2021-11-12 Thread Ali Çehreli via Digitalmars-d-learn
On 11/12/21 11:00 PM, forkit wrote: > // nope. writes the line no. of the foreach loop mixin(m) seems to solve the issue, which I think necessitates 'static if': static foreach(m; __traits(allMembers, mixin(__MODULE__))) { static if(m == "std" || m == "object" || m == "main")

Re: using __traits to get line number of a member

2021-11-13 Thread forkit via Digitalmars-d-learn
On Saturday, 13 November 2021 at 07:20:14 UTC, Ali Çehreli wrote: It works because we mix-in the value of the string 'm', which becomes a symbol. ('foreach' instead of 'static foreach' works as well.) Ali Thanks. Really appreciate the help provided in this thread :-) Final working code be

Re: using __traits to get line number of a member

2021-11-13 Thread Stanislav Blinov via Digitalmars-d-learn
On Saturday, 13 November 2021 at 08:04:56 UTC, forkit wrote: int i; foreach(m; __traits(allMembers, mixin(__MODULE__))) // ... __traits(getLocation, mixin(m))[1]); What you really should be doing is this: ```d static import mod = mixin(__MODULE__); foreach (i, name; __traits(a

Re: using __traits to get line number of a member

2021-11-13 Thread forkit via Digitalmars-d-learn
On Saturday, 13 November 2021 at 17:22:16 UTC, Stanislav Blinov wrote: On Saturday, 13 November 2021 at 08:04:56 UTC, forkit wrote: int i; foreach(m; __traits(allMembers, mixin(__MODULE__))) // ... __traits(getLocation, mixin(m))[1]); What you really should be doing is this:

Re: using __traits to get line number of a member

2021-11-13 Thread Stanislav Blinov via Digitalmars-d-learn
On Sunday, 14 November 2021 at 04:05:45 UTC, forkit wrote: However, there is no isClass method. Why not? How do I determine if a member is a class.. I wonder... ``` static if (is(something == class)) { /* ... */ } ``` or, if member is an instance ``` static if (is(typeof(something) == class

Re: using __traits to get line number of a member

2021-11-13 Thread forkit via Digitalmars-d-learn
On Sunday, 14 November 2021 at 04:24:09 UTC, Stanislav Blinov wrote: On Sunday, 14 November 2021 at 04:05:45 UTC, forkit wrote: However, there is no isClass method. Why not? How do I determine if a member is a class.. I wonder... ``` static if (is(something == class)) { /* ... */ } ``` or,

Re: using __traits to get line number of a member

2021-11-14 Thread Ali Çehreli via Digitalmars-d-learn
On 11/13/21 8:05 PM, forkit wrote: > static import mod = mixin(__MODULE__); > > That statement above would not compile. I don't understand myself but all of it as a single string works: mixin("static import mod = " ~ __MODULE__ ~ ";"); Ali