A very small update on typefunctions

Stefan Koch uplink.coder at googlemail.com
Tue Jul 28 23:12:28 UTC 2020


Hi there,

After a hunt of segfaults, I wanted to have some fun again.

So ....

I've done some work on my typefunctions.

And out came this working example.
It is very similar to one which I have posted previously.

auto getUDAs(alias T)
{
     return __traits(getAttributes, T);
}

// we can't parse alias[];
alias alias_array = typeof(getUDAs(SerializeTag));

struct SerializeTag {}
struct SuperTag {string s;}

struct TypeWithTags
{
     alias type;
     alias_array tags;
}


TypeWithTags typeWithFilteredTags(alias T)
{
     auto udas = T.getUDAs;
     alias_array syms_to_be_kept = [];
     syms_to_be_kept.length = udas.length;
     size_t n_syms;

     for(size_t i = 0; i < udas.length;i++)
     {
         alias uda;
         uda = udas[i];
         if (uda.stringof[0 .. 3] == "Sup")
         {
             syms_to_be_kept[n_syms++] = uda;
         }
     }

     return TypeWithTags(T, syms_to_be_kept[0 .. n_syms]);
}

@SuperTag("Smoking Super Style") @SerializeTag @SuperTag("Super!")
struct  ThisIsAType  { double y; }

alias x = ThisIsAType;

pragma(msg, "typeWithTags: ", typeWithFilteredTags(x));
//output: TypeWithTags((ThisIsAType), [SuperTag("Smoking Super 
Style"), SuperTag("Super!")]

However there is one important difference.
You can now assign to the length of an alias array.
Removing the use of the inefficient "~=" !

This means efficient implementation of type maps and type filters 
can now be done on the preview branch :)
Which has also been update to run on the latest "stable" release.

Stay tuned very soon I will show first performance comparison 
between staticMap + staticFilter template style.
And a handwritten typefunction.

Cheers,

Stefan


More information about the Digitalmars-d mailing list