import core.stdc.stdarg, std.conv;

extern(C) string cToString(string type, ...)
{
    va_list args_list;
    va_start(args_list, type);
    scope(exit) va_end(args_list);

    switch (type)
    {
        case "int":
            auto int_val = va_arg!int(args_list);
            return to!string(int_val);
        case "double":
            auto double_val = va_arg!double(args_list);
            return to!string(double_val);
        case "complex":
            auto re_val = va_arg!double(args_list);
            auto im_val = va_arg!double(args_list);
            return to!string(re_val) ~ " + " ~ to!string(im_val) ~ "i";
        case "string":
            return va_arg!string(args_list);
        default:
            assert(0, "Незнакомый тип");
    }
}

unittest
{
    assert(cToString("int", 5) == "5");
    assert(cToString("double", 2.0) == "2");
    assert(cToString("string", "Test string") == "Test string");
    assert(cToString("complex", 3.5, 2.7) == "3.5 + 2.7i");
}
