D是否支持模板模板参数?我怎样才能让下面的代码工作呢?
struct Type(alias a, alias b) { alias a A; alias b B; }
template MakeType(alias a, alias b)
{
alias Type!(a, b) MakeType;
}
template Foo(alias a, U) // where U is a Type
{
//...
}
template Foo(alias a, U : MakeType!(a, b), b...) // where U is a specialization
{
//...
}Foo的名字应该是这样的:
alias MakeType!(5, 7) MyType;
alias Foo!(5, MyType) Fooed; // errorError: template instance Foo!(5,Type!(5,7)) Foo!(5,Type!(5,7)) does not match template declaration Foo(alias a,U : MakeType!(a,b),b...)
发布于 2012-12-16 03:26:15
我让它工作了:-)
template Foo(alias a, U) // where U is a Type
{
//...
}
template Foo(alias a, U : X, X) if(is(X == MakeType!(a, U.B)))
{
//...
}在用法上:
alias MakeType!(1, 3) MyType1;
alias MakeType!(5, 7) MyType2;
Foo!(5, MyType1) // calls the first Foo()
Foo!(5, MyType2) // calls the second Foo() with specializationhttps://stackoverflow.com/questions/13889802
复制相似问题