Specifying C++ symbols in C++ namespaces
Jacob Carlborg
doob at me.com
Thu Apr 3 06:19:53 PDT 2014
On 03/04/14 00:07, Walter Bright wrote:
> Here's Andrei's proposal:
>
> extern (C++) template nspace() {
> int foo();
> }
>
> It would be accessed in D by:
>
> nspace!().foo();
>
> A possible enhancement would be to allow (for all templates with no
> parameters):
>
> nspace.foo();
>
> Note that:
>
> template nspace() {
> extern (C++) int foo();
> }
>
> would not put foo() in a C++ namespace, although it would still be
> accessed from D as:
>
> nspace.foo();
>
> One downside of this proposal is that if we ever (perish the thought!)
> attempted to interface to C++ templates, this design would preclude that.
I like using a UDA or pragma better:
@namespace("nspace")
{
extern (C++) int foo ();
}
Or
pragma(cpp_namespace, "nspace")
{
extern (C++) int foo ();
}
Then it's also possible to use this syntax:
@namespace("nspace"):
extern (C++) int foo ();
The only advantage I can see with using "template" is that templates can
be mixed in, it would be similar to the using declarative in C++.
--
/Jacob Carlborg
More information about the Digitalmars-d
mailing list