ADL
Manu via Digitalmars-d
digitalmars-d at puremagic.com
Fri Sep 2 05:15:25 PDT 2016
In C++, there is this ADL thing (argument dependent lookup).
What it does is, when searching for overloads, in addition to looking
in the local namespace, it also looks in the namespace of the function
arguments.
D doesn't seem to have this, and that is proving to be quite problematic.
What's the work around?
C++ example:
namespace bob {
struct S {};
void f(S s);
}
namespace joe {
struct T {};
void f(T t);
void test()
{
T t;
f(t); // obviously works, T is in the local namespace
bob::S s;
f(s); // local namespace can't see `void f(S)`, but given the
argument 's', which is typed bob::S, it will search the bob::
namespace for overloads of f(), so this code compiles successfully.
}
}
I have the same configuration across 2 modules in D.
In one module, I receive the foreign modules type via template arg,
but I haven't imported that type's module, so when I try to call the
function it can't find the overload, because it's not imported, and it
doesn't search the argument type's module (ie, namespace) for
overloads.
More information about the Digitalmars-d
mailing list