Operator overloading through UFCS doesn't work

Timon Gehr via Digitalmars-d-learn digitalmars-d-learn at puremagic.com
Thu May 26 13:32:55 PDT 2016


On 25.05.2016 01:19, Elie Morisse 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.
> ...

Yup. It could be argued that it is essentially a compiler bug.

> Sorry for digging up this thread, just getting irritated by a
> restriction that seems pointless and arbitrary.
> ...

It is, but it has a few vocal proponents.

> 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.

You are perfectly right of course. It's painful for no benefit. (For 
example, there's no way to overload e.g. '+=' for classes in a way that 
reassigns the reference.)


More information about the Digitalmars-d-learn mailing list