Koenig lookup in D?

Peter Alexander peter.alexander.au at gmail.com
Tue Aug 27 03:00:46 PDT 2013


On Tuesday, 27 August 2013 at 07:45:14 UTC, monarch_dodra wrote:
> I think that D's non-hijack rules are pretty sweet, but I also
> think that D should apply Koenig's rules: If a template is
> dependent on a parameter from a particular module (say "a"), 
> then
> the functions inside that module should also be taken into
> account when building the template instance. It would be
> *partial* hijack in the sense that you can only hijack the
> templates that operate on *your* types anyways, but in no case
> change the behavior of that of others'.

That still makes hijacking a real issue though. It limits the 
hijacking to template functions, but it's still there.

What if ADL was only used with UFCS on an instance of a template 
type?

e.g.

void foo(T)(T t)
{
     import std.stdio;
     writeln(t); // always std.stdio
     t.writeln(); // used ADL, maybe std.stdio, but can be 
specialised by T
     "foo".writeln(); // always std.stdio
}

This kind of makes sense, because T could implement writeln() as 
a member function anyway, so by using UFCS you are voluntarily 
opening yourself up to hijacking.


More information about the Digitalmars-d mailing list