New syntax for bindings to C++ and namespaces - question

Cecil Ward d at cecilward.com
Sat Nov 3 05:49:53 UTC 2018


Considering the syntax

     extern( C++, "myCppNamespace" ) void cppFunc();

If you want to still be able to use the namespace-qualified form 
myCppNamespace.cppFunc() in your D, even with the string type of 
reference, what about something like

     extern( C++, "myCppNamespace" alias myCppNamespaceAlias ) 
void cppFunc();

which declares that the name myCppNamespaceAlias is an alias in D 
for the C++ namespace myCppNamespace, and so would then permit 
the use of myCppNamespaceAlias.cppFunc().

Would such a thing even be a worthwhile enhancement?

That could get very repetitive though, so it would be better to 
be able to declare an association between the C++ namespace 
string and its alias just once. There are many many possible ways 
that might be done. Perhaps something such as :

     alias myCppNamespaceAlias = extern( C++, "myCppNamespace" );
     /*either */ extern( C++, "myCppNamespace" ) void cppFunc();
     /* or */      extern( C++, myCppNamespaceAlias ) void 
cppFunc();

Or merely:

     extern( C++, "myCppNamespace" alias myCppNamespaceAlias );
     /*either */ extern( C++, "myCppNamespace" ) void cppFunc();
     /* or */      extern( C++, myCppNamespaceAlias ) void 
cppFunc();

Any thoughts?

Would such a thing even be a worthwhile enhancement?




More information about the Digitalmars-d mailing list