Difference between revisions of "DIP61"
WalterBright (talk | contribs) |
WalterBright (talk | contribs) |
||
Line 23: | Line 23: | ||
|Links: | |Links: | ||
|[[DIP61/Archive]] — [http://forum.dlang.org/post/lhi1lt$269h$1@digitalmars.com NG discussion that triggered the DIP] | |[[DIP61/Archive]] — [http://forum.dlang.org/post/lhi1lt$269h$1@digitalmars.com NG discussion that triggered the DIP] | ||
− | — [http:// | + | — [http://forum.dlang.org/post/ljfue4$11dk$1@digitalmars.com NG announcement and discussion] |
|} | |} | ||
Revision as of 09:36, 26 April 2014
Title: | Add namespace scopes to support calling external C++ functions in C++ namespaces |
---|---|
DIP: | 61 |
Version: | 1 |
Status: | Draft |
Created: | 2014-04-26 |
Last Modified: | 2014-04-26 |
Author: | Walter Bright |
Links: | DIP61/Archive — NG discussion that triggered the DIP |
Contents
Abstract
Add support for namespaces.
Rationale
Best practices in C++ code increasingly means putting functions and declarations in namespaces. Currently, there is no support in D to call C++ functions in namespaces. The primary issue is that the name mangling doesn't match. Need a simple and straightforward method of indicating namespaces.
Description
A namespace scope creates a scope with a name, and inside that scope all declarations become part of the namespace scope. This involves the addition of a new keyword 'namespace' and a small amount of new grammar. Compiler changes are expected to be minor. The change is additive and should not impact any existing code, unless that code uses 'namespace' as a declaration name.
Usage
namespace MyNamespace { int foo(); }
Namespaces can be nested. Declarations in the namespace can be accessed without qualification in the enclosing scope if there is no ambiguity. Ambiguity issues can be resolved by adding the namespace qualifier:
namespace N { int foo(); int bar(); }
namespace M { long foo(); }
bar(); // ok
foo(); // error, ambiguous
N.foo(); // ok
N.bar(); // ok
Name lookup rules are the same as for mixin templates.
Unlike C++, namespaces in D will be 'closed' meaning that new declarations cannot be inserted into a namespace after the closing }. C++ Argument Dependent Lookup (aka "Koenig Lookup") will not be supported.
Copyright
This document has been placed in the Public Domain.