Difference between revisions of "DIP61"

From D Wiki
Jump to: navigation, search
Line 22: Line 22:
 
|-
 
|-
 
|Links:
 
|Links:
|[[DIP61/Archive]] — [http://www.digitalmars.com/d/archives/digitalmars/D/announce/dmd_1.046_and_2.031_releases_16320.html#N16448 NG discussion that triggered the DIP]
+
|[[DIP61/Archive]] — [http://www.digitalmars.com/d/archives/digitalmars/D/Specifying_C++_symbols_in_C++_namespaces NG discussion that triggered the DIP]
— [http://www.digitalmars.com/d/archives/digitalmars/D/new_DIP1_DIP_Template_92908.html NG announcement and discussion]
+
— [http://www.digitalmars.com/d/archives/digitalmars/D/DIP61.html NG announcement and discussion]
 
|}
 
|}
  
Line 32: Line 32:
 
Best practices in C++ code increasingly means putting functions and declarations in namespaces. Currently,
 
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
 
there is no support in D to call C++ functions in namespaces. The primary issue is that the name mangling
doesn't match.
+
doesn't match. Need a simple and straightforward method of indicating namespaces.
  
 
== Description ==
 
== Description ==
Line 59: Line 59:
 
Name lookup rules are the same as for mixin templates.
 
Name lookup rules are the same as for mixin templates.
  
== NG Announcement ==
+
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.
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 ==
 
== Copyright ==

Revision as of 07:34, 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/ArchiveNG discussion that triggered the DIP

NG announcement and discussion

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.

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.