Argumnentation against external function operator overloading is unconvincing

Timon Gehr via Digitalmars-d digitalmars-d at puremagic.com
Wed Sep 21 14:15:41 PDT 2016


On 21.09.2016 22:53, HaraldZealot wrote:
> On Wednesday, 21 September 2016 at 19:01:40 UTC, Timon Gehr wrote:
>>
>> Basically, the rationale is: external operators cannot be used in
>> generic code that does not import the module defining the operators.
>
> Could you give some elaborate example, for now I can't imagine what your
> mean.

module a;

struct Foo{}

Foo opBinary(string op:"+")(Foo a, Foo b){ return Foo(); }

---

module b;

T add(T)(T a,T b){
     return a + b;
}

---

module c;
import a,b;

void main(){
     Foo x=add(Foo(),Foo()); // error
}



More information about the Digitalmars-d mailing list