Specifying C++ symbols in C++ namespaces
Tove
tove at fransson.se
Sun Apr 6 02:28:42 PDT 2014
On Sunday, 6 April 2014 at 02:33:38 UTC, Walter Bright wrote:
> On 4/5/2014 6:26 PM, Michel Fortin wrote:
>> What if you also have a C++ foo at global scope?
>
> It'll work exactly the same as import does.
>
>
>> module cpptest;
>>
>> extern (C++) void foo();
>> extern (C++, namespace = A) void foo();
>>
>> foo(); // ambiguous
>> A.foo(); // works
>> .foo(); // works?
>
> Yes.
>
>> cpptest.foo(); // works?
>
> Yes.
>
>> Does these two last lines make sense?
>
> Just as much sense as:
>
> module bar;
> void foo();
> .foo(); // works
> bar.foo(); // works
>
> Namespace lookup rules would be exactly the same as for imports
> and mixin templates.
My main reservation against the new suggestion is that one would
be forced to open a new nested namespace even when it's
detrimental, because in some cases the namespace structure is
already reflected in the filesystem(just like for D:s module
system).
I can't assess how widespread this is globally, but at least some
high-quality projects already have guidelines to use
file/namespace mappings.
A random example from boost:
boost::asio::ip::multicast
boost/asio/ip/multicast.hpp
One can of course workaround this issue with an extra alias for
every imported symbol, or use compile-time reflection to
auto-generate all alias statements... (or heaven forbid, put
entire boost in one file ;))
I assume the "namespace = xxx" syntax is some sort of named
parameter, would it be possible to add another similar param,
which only changes mangling and doesn't actually create a new
scope?
More information about the Digitalmars-d
mailing list