Thread overview | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
|
April 02, 2014 Specifying C++ symbols in C++ namespaces | ||||
---|---|---|---|---|
| ||||
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. |
April 02, 2014 Re: Specifying C++ symbols in C++ namespaces | ||||
---|---|---|---|---|
| ||||
Posted in reply to Walter Bright | Seems alright. The only downside I can think of is that the namespace wouldn't be semantically analysed until you first try to use it, as it's a template. |
April 02, 2014 Re: Specifying C++ symbols in C++ namespaces | ||||
---|---|---|---|---|
| ||||
Posted in reply to Walter Bright | And what about something like static struct? It seems more natural and less hacky to me. |
April 02, 2014 Re: Specifying C++ symbols in C++ namespaces | ||||
---|---|---|---|---|
| ||||
Posted in reply to Walter Bright | Walter Bright:
> Here's Andrei's proposal:
>
> extern (C++) template nspace() {
> int foo();
> }
I suggest to brainstorm the syntax some more time, because someone could be able to invent a better syntax.
Some seeds:
extern (C++(nspace)) {
int foo();
}
extern (C++) struct nspace {
int foo();
}
extern (C++)(nspace) {
int foo();
}
extern (C++ nspace) {
int foo();
}
Bye,
bearophile
|
April 02, 2014 Re: Specifying C++ symbols in C++ namespaces | ||||
---|---|---|---|---|
| ||||
Posted in reply to bearophile | On Wednesday, 2 April 2014 at 22:33:21 UTC, bearophile wrote:
> Walter Bright:
>
>> Here's Andrei's proposal:
>>
>> extern (C++) template nspace() {
>> int foo();
>> }
>
> I suggest to brainstorm the syntax some more time, because someone could be able to invent a better syntax.
>
> Some seeds:
>
> extern (C++(nspace)) {
> int foo();
> }
>
> extern (C++) struct nspace {
> int foo();
> }
>
> extern (C++)(nspace) {
> int foo();
> }
>
> extern (C++ nspace) {
> int foo();
> }
>
> Bye,
> bearophile
extern (C++) module nspace;
|
April 02, 2014 Re: Specifying C++ symbols in C++ namespaces | ||||
---|---|---|---|---|
| ||||
Posted in reply to Xiaoxi | Xiaoxi:
> extern (C++) module nspace;
They plan to add some kind of modules to C++ in few years :-( So this risks semantic clashes.
Bye,
bearophile
|
April 02, 2014 Re: Specifying C++ symbols in C++ namespaces | ||||
---|---|---|---|---|
| ||||
Posted in reply to Walter Bright | On Wednesday, 2 April 2014 at 22:06:53 UTC, 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.
Walter, some on this list have not been around long enough to understand the motivation for this. Could you please summarize the problem and how this addresses it? Is this for interfacing D to C++, or a way to bring namespace semantics to D?
Mike
|
April 02, 2014 Re: Specifying C++ symbols in C++ namespaces | ||||
---|---|---|---|---|
| ||||
Posted in reply to bearophile | On Wednesday, 2 April 2014 at 22:33:21 UTC, bearophile wrote: > Walter Bright: > >> Here's Andrei's proposal: >> >> extern (C++) template nspace() { >> int foo(); >> } > > I suggest to brainstorm the syntax some more time, because someone could be able to invent a better syntax. > > Some seeds: > ... > extern (C++)(nspace) { > int foo(); > } > > extern (C++ nspace) { > int foo(); > } > > Bye, > bearophile I definitely like the last two. Small and to the point. But where nspace is a wrapper 'static struct' essentially. So: nspace.foo() |
April 03, 2014 Re: Specifying C++ symbols in C++ namespaces | ||||
---|---|---|---|---|
| ||||
Posted in reply to Mike | On Wednesday, 2 April 2014 at 23:04:58 UTC, Mike wrote: > On Wednesday, 2 April 2014 at 22:06:53 UTC, Walter Bright wrote: >> Here's Andrei's proposal: >> >> extern (C++) template nspace() { >> int foo(); >> } >> > Is this for interfacing D to C++, or a way to bring namespace semantics to D? > Well, I'm assuming this is specifically for interfacing D with C++ given the 'extern (C++)' attribution. In that case, I think the proposal abuses the 'template' keyword for something that's not really a template. In that case, I find the syntax proposed by bearophile to be far better... extern (C++ nspace) { int foo(); } ...although I would even prefer it be even more explicit... extern (C++ namespace nspace) { int foo(); } I'd also be interested in hearing the arguments against the UDAs and pragmas proposed in the following two links: * https://d.puremagic.com/issues/show_bug.cgi?id=7961 * https://github.com/D-Programming-Language/dmd/pull/2767 The pragma is especially nice since this isn't really a D thing, although bearophile's proposed syntax is hard to argue against. Mike |
April 03, 2014 Re: Specifying C++ symbols in C++ namespaces | ||||
---|---|---|---|---|
| ||||
Posted in reply to monnoroch | On 4/2/2014 3:30 PM, monnoroch wrote:
> And what about something like static struct? It seems more natural and less
> hacky to me.
Because C++ mangles static member functions of structs differently from members of namespaces.
|
Copyright © 1999-2021 by the D Language Foundation