Operator overloading through UFCS doesn't work

Jonathan M Davis via Digitalmars-d-learn digitalmars-d-learn at puremagic.com
Tue May 24 16:43:46 PDT 2016


On Tuesday, May 24, 2016 23:19:32 Elie Morisse via Digitalmars-d-learn wrote:
> On Saturday, 13 October 2012 at 22:58:56 UTC, Timon Gehr wrote:
> > Afaik free-function operator overloads (but not in the context
> > of UFCS) were considered and turned down because D did not want
> > to get amidst discussions about adding Koenig lookup. UFCS does
> > not do Koenig lookup.
>
> I don't get it, aren't the current symbol lookup rules enough to
> make free function operator overloads useful? To me it looks like
> they are.
>
> Sorry for digging up this thread, just getting irritated by a
> restriction that seems pointless and arbitrary.
>
> Overloaded operators would suffer from the same potential abuses
> other methods are subjected to if UFCS was enabled, nothing more
> as far as I can see.

If UFCS doesn't work, because there are two free functions with the same
name which take the same arguments, then you can differentiate between them
by not using UFCS and using their full import paths, or you can alias them
so that they don't have the same name. Neither of those would be possible
with operator overloading. If overloaded operators were allowed as free
functions, then if there were ever a symbol conflict, you'd be screwed.

- Jonathan M Davis



More information about the Digitalmars-d-learn mailing list