Operator overloading through UFCS doesn't work
Artur Skawina
art.08.09 at gmail.com
Mon Oct 15 04:00:44 PDT 2012
On 10/15/12 10:17, Maxim Fomin wrote:
> On Sunday, 14 October 2012 at 19:50:54 UTC, Artur Skawina wrote:
>> On 10/14/12 08:13, Maxim Fomin wrote:
>>> The only mentioned reason is to allow writing operator overloading methods outside type scope - just because somebody (currently two people) consider it logical to broaden UFCS usage.
>>
>> It's more than two people... Also, it's not about "broadening UFCS usage", it's about making UFCS work properly.
>
> When UFCS was added to the language its purpose was to call free functions pretending you are invoking methods. It does it job pretty well and actually works properly. But some questions arise: how this addition interacts with other parts of the language:
> - with calling through pointer (8603)
> - with template alias parameters (8692)
> - with function imports (6185)
> - with typeof operator (8661)
> - with operator overloading
> - ...
> - probably other issues which are not encountered yet.
UFCS has pros and cons. I could agree that it has problems and should be removed
from the language completely. But if the feature is there, it should work, w/o any
unnecessary special cases.
An overloaded operator is just another normal method; you get the same type of
problems when dealing with "normal" methods - eg in types having an "alias this" -
an UFCS "method" must take precedence over one reachable via the alias - just like
in the overloaded op case. The only sane alternative would be disallowing UFCS
for types with an "alias this" (which would be a severe limitation).
> Each time there should be a decision to choose which language feature has higher priority. That is why this is broadening UFCS usage on areas of the language where it has never been before rather than making work properly in existing areas of usage.
>
>>> This doesn't solve ay practical issue.
>>
>> Obviously, it does. Otherwise this issue wouldn't come up repeatedly.
>
> Actually not - the only purpose mentioned in the thread was to place operator overloading methods outside scope of declaration.
And the purpose of UFCS is?... "operator overloading methods" are /not/ special.
There have been several threads in the past where this missing functionality was
mentioned. It's how it should work, if UFCS is here to stay. If you think that
would causes problems and UFCS should instead be removed from the language then
I can understand that - UFCS /does/ have issues. But it's also useful and I'm not
yet convinced that the problems it introduces justifies killing the feature.
Nothing justifies special casing just certain combinations like op-overloading
and UFCS however, especially when it's not necessary.
artur
More information about the Digitalmars-d-learn
mailing list