天天看點

d省略模闆參數别名

void _messageBox(string title, int style, T...)(T args)
{
    string s = format(args);
    /* etc... */
}

alias _messageBox!(APPNAME, SWT.ICON_INFORMATION) info;
alias _messageBox!("Warning", SWT.ICON_WARNING) warning;
alias _messageBox!("Error", SWT.ICON_ERROR) error;
//
void _messageBox(string title, int style)(...)
{
    char[] msg;
    void f(dchar c) { encode(msg, c); }
    doFormat(&f, _arguments, _argptr);
    messageBox(cast(string)msg, title, style);
}      
template _messageBox(string title, int style)
{
    void _messageBox(T...)(T args)
    {
        import std.format;
        string s = format("%s", args);
        /* etc... */
    }
}

alias _messageBox!("lol", 4) info;
alias _messageBox!("Warning", 4) warning;
alias _messageBox!("Error", 4) error;

void main() {
    info(4, "ok");
}