ADL
Walter Bright via Digitalmars-d
digitalmars-d at puremagic.com
Fri Sep 2 15:38:16 PDT 2016
On 9/2/2016 5:15 AM, Manu via Digitalmars-d wrote:
> In C++, there is this ADL thing (argument dependent lookup).
Yeah, I know about Koening lookup. It was a hack added to C++ to make operator
overloading work.
> D doesn't seem to have this,
That's right, and it's on purpose :-)
> and that is proving to be quite problematic. What's the work around?
Not a workaround, as D does not need ADL. This is how to do it:
extern (C++, bob) {
struct S {}
void f(S s);
}
extern (C++, joe) {
struct T {}
void f(T t);
void test()
{
T t;
f(t); // obviously works, T is in the local namespace
alias f = bob.f; // bring bob.s into current scope
bob.S s;
f(s); // no problemo
}
}
The 'alias' construct gives good control over which symbols are visible in which
scopes.
More information about the Digitalmars-d
mailing list