d的betterC版造转换矩

template makeConvMatrix(T...) { // wrapper added
    string helper()
    {
        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;
    }

    enum makeConvMatrix = helper(); // eponymous call
}

extern(C) // for betterC
void main()
{
    import core.stdc.stdio;
    static immutable convMatrix = makeConvMatrix!(byte, ubyte, short, ushort, int, uint, long, ulong); // no more () there

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

posted @ 2021-05-05 14:35  zjh6  阅读(17)  评论(0)    收藏  举报  来源