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

Nicholas Wilson iamthewilsonator at hotmail.com
Sun Jul 29 06:06:23 UTC 2018


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")

That a) doesn't scale in a real dynamic codebase (think 
templates), and b) is platform dependent and so isn't a proper 
solution.

Honestly the only problem with Manu's suggestion is you can't 
expose `a::foo` and `b::foo` with the same signature within the 
same module due to (D) name collisions, although I don't see any 
reason why we can't do both.

Then again I don't see any (non philosophical/compiler front end 
internal) issue why you can't reopen a namespace. D is supposed 
to be pragmatic, after all.


More information about the Digitalmars-d mailing list