Argumnentation against external function operator overloading is unconvincing
HaraldZealot via Digitalmars-d
digitalmars-d at puremagic.com
Thu Sep 22 01:53:26 PDT 2016
On Thursday, 22 September 2016 at 07:14:52 UTC, H. S. Teoh wrote:
>
> It's not so simple. The UFCS operator overload could be
> declared in a different module from the type itself. Then
> there is no guarantee that it will be found. Multiple calls to
> the same template function with the same argument types may
> result in different semantics, depending on what was imported.
> ...
> T
I mean (in terms of your example) that in `main` before
instantiate an `algorithm` we parse all symbols visible at this
point from `main`, select all possible symbols which can be
called with `UserType` (including templates, meh o_O), make the
set union for the such table for the rest templates params, and
give this symbol table the `algorithm`.
But yes this creates problem that in different module we can have
different instantiation :(
Probably with other radical approach (see bellow *) for generic
we can solve this, but this just destroy true templates (from
which we benefits now) and provide something like Java-like
solution :(
* radical approach for generic: each generic function creates a
pseudo parameter for function pointers on the base of signature
of function used in the body of generic. The caller of generic
just fill this pseudo parameters with real function visible for
caller at call-point.
More information about the Digitalmars-d
mailing list