struct Type
{
auto opBinary(string op)(Type other) const {
return Type(); // #1 return type is Type
return typeof(this)(); // #2 return type is const(Type)
}
}
unittest
{
Type t1, t2;
auto t3 = t1 + t2;
}
在t1.opBinary!("+")(t2),t1成为一个常量,而t2保持非常量。opBinary的返回类型应该是or Type,const(Type)为什么?
const(T)是一个超类型,所以也许它应该返回 a const,但我在实践中几乎没有看到过。当处理使用这些类型或被这些类型使用的类型和函数的层次结构时,事情也会变得相当复杂。