Difference between revisions of "DIP61"
WalterBright (talk | contribs) (initial edit) |
WalterBright (talk | contribs) |
||
Line 40: | Line 40: | ||
== Usage == | == Usage == | ||
+ | <syntaxhighlight lang="d"> | ||
namespace MyNamespace { int foo(); } | namespace MyNamespace { int foo(); } | ||
+ | </syntaxhighlight> | ||
Namespaces can be nested. Declarations in the namespace can be accessed without qualification in the enclosing | 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: | scope if there is no ambiguity. Ambiguity issues can be resolved by adding the namespace qualifier: | ||
+ | <syntaxhighlight lang="d"> | ||
namespace N { int foo(); int bar(); } | namespace N { int foo(); int bar(); } | ||
namespace M { long foo(); } | namespace M { long foo(); } | ||
Line 52: | Line 55: | ||
N.foo(); // ok | N.foo(); // ok | ||
N.bar(); // ok | N.bar(); // ok | ||
+ | </syntaxhighlight> | ||
Name lookup rules are the same as for mixin templates. | Name lookup rules are the same as for mixin templates. |
Revision as of 07:28, 26 April 2014
Title: | DIP Template |
---|---|
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 |
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.
Description
A namespace scope creates a scope with a name, and inside that scope all declarations become part of the namespace scope.
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.
NG Announcement
When posting the DIP announcement to the NG, please copy the abstract, so people can easily know what is it about and follow the link if they are interested.
Copyright
This document has been placed in the Public Domain.