tmp/tmpjrnh_qyr/{from.md → to.md}
RENAMED
|
@@ -13,46 +13,46 @@ namespace-definition:
|
|
| 13 |
nested-namespace-definition
|
| 14 |
```
|
| 15 |
|
| 16 |
``` bnf
|
| 17 |
named-namespace-definition:
|
| 18 |
-
|
| 19 |
```
|
| 20 |
|
| 21 |
``` bnf
|
| 22 |
unnamed-namespace-definition:
|
| 23 |
-
|
| 24 |
```
|
| 25 |
|
| 26 |
``` bnf
|
| 27 |
nested-namespace-definition:
|
| 28 |
-
|
| 29 |
```
|
| 30 |
|
| 31 |
``` bnf
|
| 32 |
enclosing-namespace-specifier:
|
| 33 |
identifier
|
| 34 |
-
enclosing-namespace-specifier '::' identifier
|
| 35 |
```
|
| 36 |
|
| 37 |
``` bnf
|
| 38 |
namespace-body:
|
| 39 |
declaration-seqₒₚₜ
|
| 40 |
```
|
| 41 |
|
| 42 |
-
Every *namespace-definition* shall appear
|
| 43 |
-
|
| 44 |
|
| 45 |
In a *named-namespace-definition*, the *identifier* is the name of the
|
| 46 |
-
namespace. If the *identifier*, when looked up
|
| 47 |
-
|
| 48 |
-
|
| 49 |
-
|
| 50 |
-
of
|
| 51 |
-
|
| 52 |
-
|
| 53 |
-
|
| 54 |
|
| 55 |
Because a *namespace-definition* contains *declaration*s in its
|
| 56 |
*namespace-body* and a *namespace-definition* is itself a *declaration*,
|
| 57 |
it follows that *namespace-definition*s can be nested.
|
| 58 |
|
|
@@ -106,22 +106,22 @@ The optional *attribute-specifier-seq* in a *named-namespace-definition*
|
|
| 106 |
appertains to the namespace being defined or extended.
|
| 107 |
|
| 108 |
Members of an inline namespace can be used in most respects as though
|
| 109 |
they were members of the enclosing namespace. Specifically, the inline
|
| 110 |
namespace and its enclosing namespace are both added to the set of
|
| 111 |
-
associated namespaces used in argument-dependent lookup
|
| 112 |
-
[[basic.lookup.argdep]]
|
| 113 |
-
|
| 114 |
-
|
| 115 |
-
|
| 116 |
-
|
| 117 |
-
|
| 118 |
-
|
| 119 |
-
|
| 120 |
-
|
| 121 |
-
|
| 122 |
-
|
| 123 |
|
| 124 |
These properties are transitive: if a namespace `N` contains an inline
|
| 125 |
namespace `M`, which in turn contains an inline namespace `O`, then the
|
| 126 |
members of `O` can be used as though they were members of `M` or `N`.
|
| 127 |
The *inline namespace set* of `N` is the transitive closure of all
|
|
@@ -132,26 +132,29 @@ namespaces.
|
|
| 132 |
|
| 133 |
A *nested-namespace-definition* with an *enclosing-namespace-specifier*
|
| 134 |
`E`, *identifier* `I` and *namespace-body* `B` is equivalent to
|
| 135 |
|
| 136 |
``` cpp
|
| 137 |
-
namespace E { namespace I { B } }
|
| 138 |
```
|
| 139 |
|
|
|
|
|
|
|
|
|
|
| 140 |
[*Example 3*:
|
| 141 |
|
| 142 |
``` cpp
|
| 143 |
-
namespace A::B::C {
|
| 144 |
int i;
|
| 145 |
}
|
| 146 |
```
|
| 147 |
|
| 148 |
The above has the same effect as:
|
| 149 |
|
| 150 |
``` cpp
|
| 151 |
namespace A {
|
| 152 |
-
namespace B {
|
| 153 |
namespace C {
|
| 154 |
int i;
|
| 155 |
}
|
| 156 |
}
|
| 157 |
}
|
|
@@ -162,21 +165,21 @@ namespace A {
|
|
| 162 |
#### Unnamed namespaces <a id="namespace.unnamed">[[namespace.unnamed]]</a>
|
| 163 |
|
| 164 |
An *unnamed-namespace-definition* behaves as if it were replaced by
|
| 165 |
|
| 166 |
``` bnf
|
| 167 |
-
|
| 168 |
-
|
| 169 |
-
|
| 170 |
```
|
| 171 |
|
| 172 |
where `inline` appears if and only if it appears in the
|
| 173 |
-
*unnamed-namespace-definition* and all occurrences of `unique
|
| 174 |
translation unit are replaced by the same identifier, and this
|
| 175 |
identifier differs from all other identifiers in the translation unit.
|
| 176 |
The optional *attribute-specifier-seq* in the
|
| 177 |
-
*unnamed-namespace-definition* appertains to `unique
|
| 178 |
|
| 179 |
[*Example 1*:
|
| 180 |
|
| 181 |
``` cpp
|
| 182 |
namespace { int i; } // unique::i
|
|
@@ -201,19 +204,19 @@ void h() {
|
|
| 201 |
— *end example*]
|
| 202 |
|
| 203 |
#### Namespace member definitions <a id="namespace.memdef">[[namespace.memdef]]</a>
|
| 204 |
|
| 205 |
A declaration in a namespace `N` (excluding declarations in nested
|
| 206 |
-
scopes) whose *declarator-id* is an *unqualified-id*
|
| 207 |
-
whose *class-head-name*
|
| 208 |
-
|
| 209 |
-
|
| 210 |
-
[[dcl.type.elab]]
|
| 211 |
-
|
| 212 |
|
| 213 |
-
[*Note 1*: An explicit instantiation
|
| 214 |
-
specialization
|
| 215 |
name and thus may be declared using an *unqualified-id* in a member of
|
| 216 |
the enclosing namespace set, if the primary template is declared in an
|
| 217 |
inline namespace. — *end note*]
|
| 218 |
|
| 219 |
[*Example 1*:
|
|
@@ -231,14 +234,14 @@ namespace X {
|
|
| 231 |
```
|
| 232 |
|
| 233 |
— *end example*]
|
| 234 |
|
| 235 |
Members of a named namespace can also be defined outside that namespace
|
| 236 |
-
by explicit qualification
|
| 237 |
-
|
| 238 |
-
|
| 239 |
-
|
| 240 |
|
| 241 |
[*Example 2*:
|
| 242 |
|
| 243 |
``` cpp
|
| 244 |
namespace Q {
|
|
@@ -257,32 +260,32 @@ namespace R {
|
|
| 257 |
}
|
| 258 |
```
|
| 259 |
|
| 260 |
— *end example*]
|
| 261 |
|
| 262 |
-
If a
|
| 263 |
-
function, class template or function template[^
|
| 264 |
-
of the innermost enclosing namespace. The
|
| 265 |
-
by itself make the name visible to unqualified lookup
|
| 266 |
-
[[basic.lookup.unqual]]
|
| 267 |
|
| 268 |
[*Note 2*: The name of the friend will be visible in its namespace if a
|
| 269 |
matching declaration is provided at namespace scope (either before or
|
| 270 |
after the class definition granting friendship). — *end note*]
|
| 271 |
|
| 272 |
If a friend function or function template is called, its name may be
|
| 273 |
found by the name lookup that considers functions from namespaces and
|
| 274 |
-
classes associated with the types of the function arguments
|
| 275 |
-
[[basic.lookup.argdep]]
|
| 276 |
-
|
| 277 |
-
|
| 278 |
-
|
| 279 |
-
|
| 280 |
|
| 281 |
-
[*Note 3*: The other forms of
|
| 282 |
-
|
| 283 |
-
|
| 284 |
|
| 285 |
[*Example 3*:
|
| 286 |
|
| 287 |
``` cpp
|
| 288 |
// Assume f and g have not yet been declared.
|
|
|
|
| 13 |
nested-namespace-definition
|
| 14 |
```
|
| 15 |
|
| 16 |
``` bnf
|
| 17 |
named-namespace-definition:
|
| 18 |
+
inlineₒₚₜ namespace attribute-specifier-seqₒₚₜ identifier '{' namespace-body '}'
|
| 19 |
```
|
| 20 |
|
| 21 |
``` bnf
|
| 22 |
unnamed-namespace-definition:
|
| 23 |
+
inlineₒₚₜ namespace attribute-specifier-seqₒₚₜ '{' namespace-body '}'
|
| 24 |
```
|
| 25 |
|
| 26 |
``` bnf
|
| 27 |
nested-namespace-definition:
|
| 28 |
+
namespace enclosing-namespace-specifier '::' inlineₒₚₜ identifier '{' namespace-body '}'
|
| 29 |
```
|
| 30 |
|
| 31 |
``` bnf
|
| 32 |
enclosing-namespace-specifier:
|
| 33 |
identifier
|
| 34 |
+
enclosing-namespace-specifier '::' inlineₒₚₜ identifier
|
| 35 |
```
|
| 36 |
|
| 37 |
``` bnf
|
| 38 |
namespace-body:
|
| 39 |
declaration-seqₒₚₜ
|
| 40 |
```
|
| 41 |
|
| 42 |
+
Every *namespace-definition* shall appear at namespace scope
|
| 43 |
+
[[basic.scope.namespace]].
|
| 44 |
|
| 45 |
In a *named-namespace-definition*, the *identifier* is the name of the
|
| 46 |
+
namespace. If the *identifier*, when looked up [[basic.lookup.unqual]],
|
| 47 |
+
refers to a *namespace-name* (but not a *namespace-alias*) that was
|
| 48 |
+
introduced in the namespace in which the *named-namespace-definition*
|
| 49 |
+
appears or that was introduced in a member of the inline namespace set
|
| 50 |
+
of that namespace, the *namespace-definition* *extends* the
|
| 51 |
+
previously-declared namespace. Otherwise, the *identifier* is introduced
|
| 52 |
+
as a *namespace-name* into the declarative region in which the
|
| 53 |
+
*named-namespace-definition* appears.
|
| 54 |
|
| 55 |
Because a *namespace-definition* contains *declaration*s in its
|
| 56 |
*namespace-body* and a *namespace-definition* is itself a *declaration*,
|
| 57 |
it follows that *namespace-definition*s can be nested.
|
| 58 |
|
|
|
|
| 106 |
appertains to the namespace being defined or extended.
|
| 107 |
|
| 108 |
Members of an inline namespace can be used in most respects as though
|
| 109 |
they were members of the enclosing namespace. Specifically, the inline
|
| 110 |
namespace and its enclosing namespace are both added to the set of
|
| 111 |
+
associated namespaces used in argument-dependent lookup
|
| 112 |
+
[[basic.lookup.argdep]] whenever one of them is, and a *using-directive*
|
| 113 |
+
[[namespace.udir]] that names the inline namespace is implicitly
|
| 114 |
+
inserted into the enclosing namespace as for an unnamed namespace
|
| 115 |
+
[[namespace.unnamed]]. Furthermore, each member of the inline namespace
|
| 116 |
+
can subsequently be partially specialized [[temp.class.spec]],
|
| 117 |
+
explicitly instantiated [[temp.explicit]], or explicitly specialized
|
| 118 |
+
[[temp.expl.spec]] as though it were a member of the enclosing
|
| 119 |
+
namespace. Finally, looking up a name in the enclosing namespace via
|
| 120 |
+
explicit qualification [[namespace.qual]] will include members of the
|
| 121 |
+
inline namespace brought in by the *using-directive* even if there are
|
| 122 |
+
declarations of that name in the enclosing namespace.
|
| 123 |
|
| 124 |
These properties are transitive: if a namespace `N` contains an inline
|
| 125 |
namespace `M`, which in turn contains an inline namespace `O`, then the
|
| 126 |
members of `O` can be used as though they were members of `M` or `N`.
|
| 127 |
The *inline namespace set* of `N` is the transitive closure of all
|
|
|
|
| 132 |
|
| 133 |
A *nested-namespace-definition* with an *enclosing-namespace-specifier*
|
| 134 |
`E`, *identifier* `I` and *namespace-body* `B` is equivalent to
|
| 135 |
|
| 136 |
``` cpp
|
| 137 |
+
namespace E { \opt{inline} namespace I { B } }
|
| 138 |
```
|
| 139 |
|
| 140 |
+
where the optional `inline` is present if and only if the *identifier*
|
| 141 |
+
`I` is preceded by `inline`.
|
| 142 |
+
|
| 143 |
[*Example 3*:
|
| 144 |
|
| 145 |
``` cpp
|
| 146 |
+
namespace A::inline B::C {
|
| 147 |
int i;
|
| 148 |
}
|
| 149 |
```
|
| 150 |
|
| 151 |
The above has the same effect as:
|
| 152 |
|
| 153 |
``` cpp
|
| 154 |
namespace A {
|
| 155 |
+
inline namespace B {
|
| 156 |
namespace C {
|
| 157 |
int i;
|
| 158 |
}
|
| 159 |
}
|
| 160 |
}
|
|
|
|
| 165 |
#### Unnamed namespaces <a id="namespace.unnamed">[[namespace.unnamed]]</a>
|
| 166 |
|
| 167 |
An *unnamed-namespace-definition* behaves as if it were replaced by
|
| 168 |
|
| 169 |
``` bnf
|
| 170 |
+
inlineₒₚₜ namespace unique '{' '/* empty body */' '}'
|
| 171 |
+
using namespace unique ';'
|
| 172 |
+
namespace unique '{' namespace-body '}'
|
| 173 |
```
|
| 174 |
|
| 175 |
where `inline` appears if and only if it appears in the
|
| 176 |
+
*unnamed-namespace-definition* and all occurrences of *`unique`* in a
|
| 177 |
translation unit are replaced by the same identifier, and this
|
| 178 |
identifier differs from all other identifiers in the translation unit.
|
| 179 |
The optional *attribute-specifier-seq* in the
|
| 180 |
+
*unnamed-namespace-definition* appertains to *`unique`*.
|
| 181 |
|
| 182 |
[*Example 1*:
|
| 183 |
|
| 184 |
``` cpp
|
| 185 |
namespace { int i; } // unique::i
|
|
|
|
| 204 |
— *end example*]
|
| 205 |
|
| 206 |
#### Namespace member definitions <a id="namespace.memdef">[[namespace.memdef]]</a>
|
| 207 |
|
| 208 |
A declaration in a namespace `N` (excluding declarations in nested
|
| 209 |
+
scopes) whose *declarator-id* is an *unqualified-id* [[dcl.meaning]],
|
| 210 |
+
whose *class-head-name* [[class.pre]] or *enum-head-name* [[dcl.enum]]
|
| 211 |
+
is an *identifier*, or whose *elaborated-type-specifier* is of the form
|
| 212 |
+
*class-key* *attribute-specifier-seq*ₒₚₜ *identifier*
|
| 213 |
+
[[dcl.type.elab]], or that is an *opaque-enum-declaration*, declares (or
|
| 214 |
+
redeclares) its *unqualified-id* or *identifier* as a member of `N`.
|
| 215 |
|
| 216 |
+
[*Note 1*: An explicit instantiation [[temp.explicit]] or explicit
|
| 217 |
+
specialization [[temp.expl.spec]] of a template does not introduce a
|
| 218 |
name and thus may be declared using an *unqualified-id* in a member of
|
| 219 |
the enclosing namespace set, if the primary template is declared in an
|
| 220 |
inline namespace. — *end note*]
|
| 221 |
|
| 222 |
[*Example 1*:
|
|
|
|
| 234 |
```
|
| 235 |
|
| 236 |
— *end example*]
|
| 237 |
|
| 238 |
Members of a named namespace can also be defined outside that namespace
|
| 239 |
+
by explicit qualification [[namespace.qual]] of the name being defined,
|
| 240 |
+
provided that the entity being defined was already declared in the
|
| 241 |
+
namespace and the definition appears after the point of declaration in a
|
| 242 |
+
namespace that encloses the declaration’s namespace.
|
| 243 |
|
| 244 |
[*Example 2*:
|
| 245 |
|
| 246 |
``` cpp
|
| 247 |
namespace Q {
|
|
|
|
| 260 |
}
|
| 261 |
```
|
| 262 |
|
| 263 |
— *end example*]
|
| 264 |
|
| 265 |
+
If a friend declaration in a non-local class first declares a class,
|
| 266 |
+
function, class template or function template[^10] the friend is a
|
| 267 |
+
member of the innermost enclosing namespace. The friend declaration does
|
| 268 |
+
not by itself make the name visible to unqualified lookup
|
| 269 |
+
[[basic.lookup.unqual]] or qualified lookup [[basic.lookup.qual]].
|
| 270 |
|
| 271 |
[*Note 2*: The name of the friend will be visible in its namespace if a
|
| 272 |
matching declaration is provided at namespace scope (either before or
|
| 273 |
after the class definition granting friendship). — *end note*]
|
| 274 |
|
| 275 |
If a friend function or function template is called, its name may be
|
| 276 |
found by the name lookup that considers functions from namespaces and
|
| 277 |
+
classes associated with the types of the function arguments
|
| 278 |
+
[[basic.lookup.argdep]]. If the name in a friend declaration is neither
|
| 279 |
+
qualified nor a *template-id* and the declaration is a function or an
|
| 280 |
+
*elaborated-type-specifier*, the lookup to determine whether the entity
|
| 281 |
+
has been previously declared shall not consider any scopes outside the
|
| 282 |
+
innermost enclosing namespace.
|
| 283 |
|
| 284 |
+
[*Note 3*: The other forms of friend declarations cannot declare a new
|
| 285 |
+
member of the innermost enclosing namespace and thus follow the usual
|
| 286 |
+
lookup rules. — *end note*]
|
| 287 |
|
| 288 |
[*Example 3*:
|
| 289 |
|
| 290 |
``` cpp
|
| 291 |
// Assume f and g have not yet been declared.
|