[namespace.def.general] (original) (raw)
9 Declarations [dcl]
9.9 Namespaces [basic.namespace]
9.9.2 Namespace definition [namespace.def]
9.9.2.1 General [namespace.def.general]
In a named-namespace-definition D, the identifier is the name of the namespace.
The identifier is looked up by searching for it in the scopes of the namespace Ain which D appears and of every element of the inline namespace set of A.
If the lookup finds a namespace-definition for a namespace N,D extends N, and the target scope of D is the scope to which N belongs.
If the lookup finds nothing, the identifier is introduced as a namespace-name into A.
Because a namespace-definition containsdeclarations in its namespace-body and anamespace-definition is itself a declaration, it follows that namespace-definitions can be nested.
[Example 1: namespace Outer { int i;namespace Inner { void f() { i++; } int i;void g() { i++; } } } — _end example_]
If the optional initial inline keyword appears in anamespace-definition for a particular namespace, that namespace is declared to be an inline namespace.
The inline keyword may be used on a namespace-definition that extends a namespace only if it was previously used on the namespace-definitionthat initially declared the namespace-name for that namespace.
Members of an inline namespace can be used in most respects as though they were members of the innermost enclosing namespace.
Specifically, the inline namespace and its enclosing namespace are both added to the set of associated namespaces used inargument-dependent lookup whenever one of them is, and a using-directive ([namespace.udir]) that names the inline namespace is implicitly inserted into the enclosing namespace as for an unnamed namespace ([namespace.unnamed]).
Furthermore, each member of the inline namespace can subsequently be partially specialized ([temp.spec.partial]), explicitly instantiated ([temp.explicit]), or explicitly specialized ([temp.expl.spec]) as though it were a member of the enclosing namespace.
Finally, looking up a name in the enclosing namespace via explicit qualification ([namespace.qual]) will include members of the inline namespace even if there are declarations of that name in the enclosing namespace.
These properties are transitive: if a namespace N contains an inline namespaceM, which in turn contains an inline namespace O, then the members ofO can be used as though they were members of M or N.
The inline namespace set of N is the transitive closure of all inline namespaces in N.
A nested-namespace-definition with anenclosing-namespace-specifier E,identifier I andnamespace-body Bis equivalent tonamespace E { inline namespace I { B } } where the optional inline is present if and only if the identifier I is preceded by inline.
[Example 2: namespace A::inline B::C { int i;}
The above has the same effect as:namespace A { inline namespace B { namespace C { int i;} } }
— _end example_]