TypeFunction example creatiing a conversion matrix

Stefan Koch uplink.coder at googlemail.com
Fri Oct 2 03:11:34 UTC 2020


On Thursday, 1 October 2020 at 21:04:29 UTC, Walter Bright wrote:
> 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);
> }

This code produces a binary which
  - is 4 times biggger
  - has more symobls.
  - doesn't work for -betterC

See: 
https://forum.dlang.org/post/wdaamjqqvjlnwaopamzn@forum.dlang.org
Where I address the differences.



More information about the Digitalmars-d mailing list