ADL

Andrei Alexandrescu via Digitalmars-d digitalmars-d at puremagic.com
Mon Sep 5 01:17:15 PDT 2016


On 9/5/16 6:23 AM, Manu via Digitalmars-d wrote:
> But the point of my post is that
> I feel the problem is of very high importance.

Let me make sure I understand it. The core structure is this:

=====
module bob;
struct S {}
void f(S s);

module myalgorithm;
void test(T)(T t)
{
   f(t);
}
=====

The core issue here is that f is not considered for lookup. It is a free 
function in the same module as S. That's not a frequent case and it 
seems right to not support it in the lookup rules.

The simplest solution, which has already been discussed, is to make f a 
member of S. It is important that does not affect modularity; all 
protection in D has module-level granularity, so the premise of 
http://www.drdobbs.com/cpp/how-non-member-functions-improve-encapsu/184401197. 
So it's for the most part a clerical matter: move the body of f inside 
S, or if f is already generic define an alias for it inside of S.

This is the baseline solution, and it is reasonable. This needs to be 
properly understood before we look into any others: by a simple 
mechanical intervention, everything works properly. Every language has 
such minute needs for minor scaffolding.

It must also be understood that changing the lookup rules to make this 
scaffolding unnecessary bring with them a host of unpleasant consequences.

Are we in agreement about the baseline solution?


Andrei



More information about the Digitalmars-d mailing list