First life-signs of type functions

Stefan Koch uplink.coder at googlemail.com
Sun May 10 08:43:42 UTC 2020


On Saturday, 9 May 2020 at 06:39:20 UTC, Stefan Koch wrote:
> On Wednesday, 6 May 2020 at 12:01:11 UTC, Stefan Koch wrote:
>> On Wednesday, 6 May 2020 at 11:58:36 UTC, Stefan Koch wrote:
>>> Now works on the Talias branch
>>>
>>
>> https://github.com/dlang/dmd/compare/master...UplinkCoder:talias?expand=1
>>
>> As you can see the modifications aren't even that heavy.
>> I am confident this will take significantly less time than 
>> re-implementing CTFE.
>> Because it's a new feature and bugs can be fixed as they are 
>> discovered.
>
> As of a few minutes ago the following code compiles without 
> errors!
>
> string fqn(alias t)
> {
>     string result = t.stringof;
>     alias p;
>     p = t;
>     bool good = is(typeof(__traits(parent, p)));
>     while(good)
>     {
>         p = __traits(parent, p);
>         result = p.stringof ~ "." ~ result;
> //        result = __traits(identifier, parent) ~ "." ~ result;
>         good = is(typeof(__traits(parent, p)));
>
>     }
>
>     return cast(string) result;
> }
>
> struct S
> {
>     struct X
>     {
>         int xx;
>         static assert( fqn!xx == "module " ~ __MODULE__ ~ 
> ".S.X.xx" );
>     }
> }

__traits(identifier) works now making the code a little bit nicer.

string fqn(alias t)
{
     string result = t.stringof;
     alias p;
     p = t;
     bool good = is(typeof(__traits(parent, p)));

     while(good)
     {
         p = __traits(parent, p);
         result = __traits(identifier, p) ~ "." ~ result;
         good = is(typeof(__traits(parent, p)));

     }

     return result;
}

struct S
{
     struct X
     {
         int xx;
         static assert( fqn!xx == __MODULE__ ~ ".S.X.xx" );
     }
}

I am not super happy with how this looks ... especially that I am 
getting __traits(parent) twice. If anyone has a suggestion of how 
to write this better.
Please tell me :)

Also I am documenting the process of implementing this on my 
youtube channel 
(https://www.youtube.com/channel/UCdZpjZcilNRQH2GDY-P5yVA) 
(whenever I remember to press record and having something 
interesting to show)



More information about the Digitalmars-d mailing list