不知道什么時候加入了“函數(shù)模板參數(shù)類型推導(dǎo)”和“類模板(改進(jìn)型)”,文檔中也是悄悄出現(xiàn)了。
函數(shù)模板參數(shù)類型推導(dǎo):
template Square(T)
{
T Square(T t)
{
return t * t;
}
}
以前調(diào)用時必須顯式實例化:
writefln("The square of %s is %s", 3, Square!(int)(3));
現(xiàn)在可以使用自動推導(dǎo)了:
writefln("The square of %s is %s", 3, Square(3)); // T is deduced to be int
類模板以前必須這樣寫:
template Bar(T)
{
class Bar
{
T member;
}
}
現(xiàn)在可以寫為:
class Bar(T)
{
T member;
}
含義相同。