extern(C++, NS)

Timon Gehr via Digitalmars-d digitalmars-d at puremagic.com
Mon Nov 30 06:22:15 PST 2015


On 11/29/2015 12:13 PM, Ola Fosheim Grøstad wrote:
> On a related note, does D support inline namespaces? Apparently it
> affects mangling:
>
> http://stackoverflow.com/questions/29764869/can-inline-namespaces-be-used-to-keep-backwards-compatibility-in-a-shared-librar
>

Namespaces affect mangling. The inline keyword doesn't.

>
> I use inline namespaces quite a bit and am curious of how D resolves those.
>
>

string inlineNamespace(alias ns)(){
     string s;
     foreach(m;__traits(allMembers,ns))
         s~=`alias `~m~`=`~__traits(identifier,ns)~`.`~m~`;`;
     return s;
}

extern(C++,std){
     extern(C++,version1){
         void bar(){}
     }
     mixin(inlineNamespace!version1);
     extern(C++,version2){
         void bar(){}
     }
}



More information about the Digitalmars-d mailing list