TypeFunction example creatiing a conversion matrix

Walter Bright newshound2 at digitalmars.com
Thu Oct 1 21:04:29 UTC 2020


Does the same thing, works today:

string makeConvMatrix(T...)()
{
     string result;
     static foreach(t; T)
     {
         result ~= "\t" ~ t.stringof;
     }
     result ~= "\n";
     static foreach(t1; T)
     {
         result ~= t1.stringof;
         static foreach(t2; T)
         {
             result ~=  "\t" ~ (is(t1:t2) ? "yes" : "no");
         }
         result ~= "\n";
     }
     return result;
}

void main()
{
     import core.stdc.stdio;
     static immutable convMatrix = makeConvMatrix!(byte, ubyte, short, ushort, 
int, uint, long, ulong)();

     printf("%s\n", convMatrix.ptr);
}



More information about the Digitalmars-d mailing list