Jump to page: 1 29  
Page
Thread overview
Specifying C++ symbols in C++ namespaces
Apr 02, 2014
Walter Bright
Apr 02, 2014
w0rp
Apr 02, 2014
monnoroch
Apr 03, 2014
Walter Bright
Apr 03, 2014
monnoroch
Apr 03, 2014
monnoroch
Apr 03, 2014
monnoroch
Apr 02, 2014
bearophile
Apr 02, 2014
Xiaoxi
Apr 02, 2014
bearophile
Apr 02, 2014
Rikki Cattermole
Apr 03, 2014
Walter Bright
Apr 03, 2014
bearophile
Apr 03, 2014
Michel Fortin
Apr 03, 2014
Walter Bright
Apr 03, 2014
Michel Fortin
Apr 03, 2014
Daniel Kozák
Apr 03, 2014
Walter Bright
Apr 03, 2014
Daniel Kozak
Apr 03, 2014
H. S. Teoh
Apr 03, 2014
Walter Bright
Apr 03, 2014
Michel Fortin
Apr 03, 2014
Robert Clipsham
Apr 02, 2014
Mike
Apr 03, 2014
Mike
Apr 03, 2014
Walter Bright
Apr 03, 2014
Kagamin
Apr 03, 2014
Kagamin
Apr 03, 2014
Andrej Mitrovic
Apr 03, 2014
Daniel Murphy
Apr 04, 2014
Daniel Murphy
Apr 05, 2014
Timon Gehr
Apr 03, 2014
Théo Bueno
Apr 04, 2014
Mason McGill
Apr 04, 2014
David Gileadi
Apr 03, 2014
Jacob Carlborg
Apr 04, 2014
deadalnix
Apr 04, 2014
Walter Bright
Apr 04, 2014
deadalnix
Apr 04, 2014
Dicebot
Apr 04, 2014
Mason McGill
Apr 04, 2014
Walter Bright
Apr 04, 2014
Walter Bright
Apr 04, 2014
Tove
Apr 04, 2014
bearophile
Apr 04, 2014
Mason McGill
Apr 04, 2014
Dicebot
Apr 04, 2014
Simen Kjærås
Apr 04, 2014
Dicebot
Apr 04, 2014
Simen Kjærås
Apr 04, 2014
Dicebot
Apr 04, 2014
deadalnix
Apr 05, 2014
Dicebot
Apr 05, 2014
Dicebot
Apr 05, 2014
Dicebot
Apr 05, 2014
Mason McGill
Apr 05, 2014
Walter Bright
Apr 06, 2014
Jacob Carlborg
Apr 05, 2014
Walter Bright
Apr 05, 2014
Tove
Apr 05, 2014
Walter Bright
Apr 06, 2014
Marc Schütz
Apr 06, 2014
Walter Bright
Apr 05, 2014
Michel Fortin
Apr 05, 2014
Walter Bright
Apr 06, 2014
Walter Bright
Apr 06, 2014
monarch_dodra
Apr 06, 2014
Walter Bright
Apr 07, 2014
Michel Fortin
Apr 07, 2014
Paulo Pinto
Apr 05, 2014
bearophile
Apr 06, 2014
Michel Fortin
Apr 06, 2014
Walter Bright
Apr 06, 2014
Tove
Apr 07, 2014
Adam Wilson
Apr 07, 2014
Dejan Lekic
April 02, 2014
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
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
And what about something like static struct? It seems more natural and less hacky to me.
April 02, 2014
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
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
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
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
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
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
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.
« First   ‹ Prev
1 2 3 4 5 6 7 8 9