On 2014-04-05 20:47:32 +0000, Walter Bright <newshou...@digitalmars.com> said:
On 4/2/2014 3:07 PM, Walter Bright wrote:
One downside of this proposal is that if we ever (perish the thought!)
attempted
to interface to C++ templates, this design would preclude that.
Yes, this seems to be a fatal flaw. Another design that has evolved
from these discussions and my discussions with Andrei on it:
extern (C++, namespace = A.B) { void foo(); void bar(); }
extern (C++, namespace = C) void foo();
bar(); // works
A.B.bar(); // works
foo(); // error: ambiguous
C.foo(); // works
alias C.foo foo;
foo(); // works, calling C.foo()
I really think the namespace semantics should be attached to the
extern(C++) rather than be a separate pragma. Having the namespace=
thing means that namespace isn't a keyword, and provides a general
mechanism where we can add language specific information as necessary.
I like this idea. But... should this potentially useful thing really be
restricted to extern C++ things? I've seen at least one attempt to
create a namespace using what D currently offers [1], and frankly
something like the above would make much more sense than a class no one
can instantiate.
[1]: http://dlang.org/phobos/std_datetime.html#.Clock
Here's a suggestion:
@namespace A.B { // can create two levels at once, yeah!
void foo();
void bar();
}
@namespace C {
void foo();
}
Make those C++ declarations, it does not look too foreign anymore:
extern (C++) @namespace A.B {
void foo();
void bar();
}
extern (C++) @namespace C {
void foo();
}
--
Michel Fortin
michel.for...@michelf.ca
http://michelf.ca