Operator overloading through UFCS doesn't work

Elie Morisse via Digitalmars-d-learn digitalmars-d-learn at puremagic.com
Wed May 25 16:31:18 PDT 2016


On Wednesday, 25 May 2016 at 21:50:06 UTC, Jonathan M Davis wrote:
> It's not an overloaded operator anymore at that point, and that 
> definitely fails to work for generic code, since not all 
> operators are overloaded operators. Free functions don't have 
> that problem.

Sorry to reiterate the previous post but is that really the case?

   void FuncTemplate(...)(...) {
     X.FreeFunc(Y);
   }

   import ModuleA; // contains FreeFunc
   import ModuleB; // contains a conflicting FreeFunc overload

   FuncTemplate!()(); // fails

Where is the difference with writing generic code with operators 
(overloaded or not)?


More information about the Digitalmars-d-learn mailing list