On Sat, 05 Apr 2014 13:47:32 -0700, Walter Bright <newshou...@digitalmars.com> wrote:

On 4/2/2014 3:07 PM, Walter Bright wrote:
One downside of this proposal is that if we ever (perish the thought!) attempted
to interface to C++ templates, this design would preclude that.

Yes, this seems to be a fatal flaw. Another design that has evolved from these discussions and my discussions with Andrei on it:

     extern (C++, namespace = A.B) { void foo(); void bar(); }
     extern (C++, namespace = C) void foo();

     bar();  // works
     A.B.bar(); // works
     foo(); // error: ambiguous
     C.foo();   // works

     alias C.foo foo;
     foo();  // works, calling C.foo()

I really think the namespace semantics should be attached to the extern(C++) rather than be a separate pragma. Having the namespace= thing means that namespace isn't a keyword, and provides a general mechanism where we can add language specific information as necessary.

This seems like a reasonable way to interop with C++ namespace in a D way. I also think that it is something that we should do ASAP. I know that for Aurora, I will not be able to add complete DirectX support until the C++ namespace interop problem is solved. Specifically because the highly optimized DirectXMath functions are inside a namespace. I do not consider pre-mangling a solution, it's a hack for something that is quite common in C++, and it's fragile.

--
Adam Wilson
GitHub/IRC: LightBender
Aurora Project Coordinator

Reply via email to