Is there any good reason why C++ namespaces are "closed" in D?
Timon Gehr
timon.gehr at gmx.ch
Fri Jul 27 18:28:58 UTC 2018
On 27.07.2018 19:28, Atila Neves wrote:
> I understand that being able to "reopen" namespaces in C++ is
> contentious - anybody can add to the `std` namespace in their own code.
> D doesn't have anything like it, and instead has packages and modules.
> So far, so good.
>
> But why does this not compile?
>
> extern(C++, ns) { void foo(); }
> extern(C++, ns) { void bar(); }
Both of the extern(C++, ns) declarations create a separate namespace
declaration. (Which is needed to allow ns.foo and ns.bar respectively.)
I.e. the reason is that it was easier to implement in the compiler.
There might be a way to add support for it by overriding overloadInsert
in Nspace.
More information about the Digitalmars-d
mailing list