Is there any good reason why C++ namespaces are "closed" in D?

Atila Neves atila.neves at gmail.com
Tue Jul 31 08:52:17 UTC 2018


On Tuesday, 31 July 2018 at 08:33:52 UTC, Daniel N wrote:
> On Monday, 30 July 2018 at 13:48:46 UTC, Atila Neves wrote:
>> On Sunday, 29 July 2018 at 03:20:29 UTC, Walter Bright wrote:
>>> On 7/28/2018 11:18 AM, Manu wrote:
>>>> Make a PR that implements namespace as a string... I will 
>>>> use that fork of D forever.
>>>
>>> 1. Look how it is mangled on the C++ side. (Use "grep" on the 
>>> object file.)
>>>
>>> 2. Use:
>>>
>>>    pragma(mangle, "the mangled name")
>>
>> This doesn't work for templates. If it did I wouldn't have an 
>> issue since libclang tells me what the mangling is.
>
> What is the deal-breaker with templates? For simple functions 
> libclang + pragma seems the best option right now.
>
> template fun()
> {
>     pragma(mangle, "_ZN2ns3funEv")
>     extern(C++)
>     void fun() {}
> }
>
> mixin fun;

extern(C++) {
     void foo(T)() {
     }
}

It doesn't have a mangling until it has an instantiation. Even if 
it were possible to know which exact instantitations the code 
that imports this uses, there's no way I can declare the mangling 
scheme to the D compiler.


More information about the Digitalmars-d mailing list