Is there any good reason why C++ namespaces are "closed" in D?
Nicholas Wilson
iamthewilsonator at hotmail.com
Mon Jul 30 02:50:32 UTC 2018
On Monday, 30 July 2018 at 02:09:37 UTC, Walter Bright wrote:
> On 7/29/2018 1:52 PM, Manu wrote:
>> On Sun, 29 Jul 2018 at 05:10, kinke via Digitalmars-d
>> <digitalmars-d at puremagic.com> wrote:
>>> [...]
>>> so that a straight C++ namespace => D module hierarchy mapping
>>> would probably be required in the general case:
>>>
>>> ```
>>> // cppns/package.d
>>> module cppns;
>>> extern(C++, "cppns") { void foo(); }
>>>
>>> // cppns/nested/package.d
>>> module cppns.nested;
>>> extern(C++, "cppns") extern(C++, "nested") { void foo(); }
>>> ```
>>
>> It's beautiful!
>>
>> (but I added the quotes in there for you; without quotes is
>> existing
>> defined behaviour which introduces scopes)
>>
>
> But that works now, I suggested it, and you didn't find it
> acceptable !!?!!
No it doesn't. You missed
>> (but I added the quotes in there for you; without quotes is
>> existing
>> defined behaviour which introduces scopes)
With the above extern(C++, "cppns") (note the quotes) defines the
mangling, the D module defines the scope.
This is consistent with e.g. how the druntime bindings to C's
standard library (with extern(C)) are used with extern(C) only
affects the mangling, not introducing a scope, only that with
extern(C++) you can have multiple things in different namespaces
all called the same thing, so you actually need the scope as well
as the mangling.
More information about the Digitalmars-d
mailing list