0
点赞
收藏
分享

微信扫一扫

d省略模板参数别名

年夜雪 2022-10-02 阅读 191



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");
}


举报

相关推荐

0 条评论