On 05/20/2013 05:15 PM, John Colvin wrote:
struct S {
     auto opDispatch(string s)(A i){}
}

struct A {}

void main() {
     S s;
     A a;
     s + a; //Error: incompatible types for ((s) + (a)): 'S' and 'A'
}

It would be really nice if opDispatch could catch missing operator
overloads.


Agreed. DMD arbitrarily refuses a combination of language features. I think it is a compiler bug.

Also, would it be a good idea to have free functions of all the
operators (opOpAssign etc...) for builtin types somewhere?

I think built-in members are a better choice than free functions, as the operators are built-in. (Also, note that operator overloading is implemented in DMD in such a way that it is incompatible with UFCS, which does not match the language specification either).

It's occasionally useful in generic wrappers.

Yes. Maybe you could file a bug report against the opDispatch part and an enhancement request for the built-in members part.

http://d.puremagic.com/issues/

Reply via email to