const references in C++ and D

bearophile bearophileHUGS at lycos.com
Mon May 31 16:12:43 PDT 2010


Trass3r:
> In which cases does it work/doesn't it work?

This doesn't work, I have shown the given error messages in the original post:

//#3
struct Vec {
    Vec opOpAssign(string Op)(auto ref Vec other) if (Op == "+=") {
        return this;
    }
    Vec opBinary(string Op:"+")(Vec other) {
        Vec result;
        return result += other;
    }
}
void main() {
    Vec v;
    v += Vec() + Vec(); // line 13
}

It works if you remove "auto ref". I think this is a compiler bug. I will put it in bugzilla. The program #1 and 2# are instead correct according to D specs.

Bye,
bearophile


More information about the Digitalmars-d-learn mailing list