天天看点

dlang,不必要串插件的类型提升.

auto opBinary(string op, M:Matrix!O, O)(M other) {
    alias P = typeof(T.init * O.init);//编译器计算类型
    //p=提升
    //,在实际改变每操作返回值时更灵活
    static if(op == "*") {//编译时参数,用.静如
        Matrix!P result;//返回类型
        if(columns == other.rows) {
            result = new Matrix!P(rows, other.columns);
        } else {
            result = new Matrix!P(0,0);
        }
        return result;
    } else static assert(0,"未实现"~op~"操作符");
    //静如,可以静断定
}
           
}//索引赋值,这里完全是插入串
    mixin(define_opbinary(int.stringof));
    mixin(define_opbinary(uint.stringof));
    //不能下面这样
    mixin define_opbinary!(int);
    mixin define_opbinary!(uint);
    //这里不一样
           

继续阅读