tmp/tmpqk_utdki/{from.md → to.md}
RENAMED
|
@@ -1,59 +1,88 @@
|
|
| 1 |
#### Namespace member definitions <a id="namespace.memdef">[[namespace.memdef]]</a>
|
| 2 |
|
| 3 |
-
|
| 4 |
-
|
| 5 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 6 |
|
| 7 |
``` cpp
|
| 8 |
namespace X {
|
| 9 |
-
void f() {
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 10 |
}
|
| 11 |
```
|
| 12 |
|
|
|
|
|
|
|
| 13 |
Members of a named namespace can also be defined outside that namespace
|
| 14 |
by explicit qualification ([[namespace.qual]]) of the name being
|
| 15 |
defined, provided that the entity being defined was already declared in
|
| 16 |
the namespace and the definition appears after the point of declaration
|
| 17 |
in a namespace that encloses the declaration’s namespace.
|
| 18 |
|
|
|
|
|
|
|
| 19 |
``` cpp
|
| 20 |
namespace Q {
|
| 21 |
namespace V {
|
| 22 |
void f();
|
| 23 |
}
|
| 24 |
-
void V::f() {
|
| 25 |
-
void V::g() {
|
| 26 |
namespace V {
|
| 27 |
void g();
|
| 28 |
}
|
| 29 |
}
|
| 30 |
|
| 31 |
namespace R {
|
| 32 |
-
void Q::V::g() {
|
| 33 |
}
|
| 34 |
```
|
| 35 |
|
| 36 |
-
|
|
|
|
| 37 |
If a `friend` declaration in a non-local class first declares a class,
|
| 38 |
-
function, class template or function template[^
|
| 39 |
of the innermost enclosing namespace. The `friend` declaration does not
|
| 40 |
by itself make the name visible to unqualified lookup (
|
| 41 |
[[basic.lookup.unqual]]) or qualified lookup ([[basic.lookup.qual]]).
|
| 42 |
-
|
| 43 |
-
|
| 44 |
-
|
| 45 |
-
|
| 46 |
-
|
| 47 |
-
|
| 48 |
-
|
| 49 |
-
|
| 50 |
-
lookup
|
| 51 |
-
|
| 52 |
-
|
| 53 |
-
|
| 54 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 55 |
|
| 56 |
``` cpp
|
| 57 |
// Assume f and g have not yet been declared.
|
| 58 |
void h(int);
|
| 59 |
template <class T> void f2(T);
|
|
@@ -69,12 +98,12 @@ namespace A {
|
|
| 69 |
};
|
| 70 |
|
| 71 |
// A::f, A::g and A::h are not visible here
|
| 72 |
X x;
|
| 73 |
void g() { f(x); } // definition of A::g
|
| 74 |
-
void f(X) {
|
| 75 |
-
void h(int) {
|
| 76 |
// A::f, A::g and A::h are visible here and known to be friends
|
| 77 |
}
|
| 78 |
|
| 79 |
using A::x;
|
| 80 |
|
|
@@ -83,5 +112,7 @@ void h() {
|
|
| 83 |
A::X::f(x); // error: f is not a member of A::X
|
| 84 |
A::X::Y::g(); // error: g is not a member of A::X::Y
|
| 85 |
}
|
| 86 |
```
|
| 87 |
|
|
|
|
|
|
|
|
|
| 1 |
#### Namespace member definitions <a id="namespace.memdef">[[namespace.memdef]]</a>
|
| 2 |
|
| 3 |
+
A declaration in a namespace `N` (excluding declarations in nested
|
| 4 |
+
scopes) whose *declarator-id* is an *unqualified-id* ([[dcl.meaning]]),
|
| 5 |
+
whose *class-head-name* (Clause [[class]]) or *enum-head-name* (
|
| 6 |
+
[[dcl.enum]]) is an *identifier*, or whose *elaborated-type-specifier*
|
| 7 |
+
is of the form *class-key* *attribute-specifier-seq*ₒₚₜ *identifier* (
|
| 8 |
+
[[dcl.type.elab]]), or that is an *opaque-enum-declaration*, declares
|
| 9 |
+
(or redeclares) its *unqualified-id* or *identifier* as a member of `N`.
|
| 10 |
+
|
| 11 |
+
[*Note 1*: An explicit instantiation ([[temp.explicit]]) or explicit
|
| 12 |
+
specialization ([[temp.expl.spec]]) of a template does not introduce a
|
| 13 |
+
name and thus may be declared using an *unqualified-id* in a member of
|
| 14 |
+
the enclosing namespace set, if the primary template is declared in an
|
| 15 |
+
inline namespace. — *end note*]
|
| 16 |
+
|
| 17 |
+
[*Example 1*:
|
| 18 |
|
| 19 |
``` cpp
|
| 20 |
namespace X {
|
| 21 |
+
void f() { ... } // OK: introduces X::f()
|
| 22 |
+
|
| 23 |
+
namespace M {
|
| 24 |
+
void g(); // OK: introduces X::M::g()
|
| 25 |
+
}
|
| 26 |
+
using M::g;
|
| 27 |
+
void g(); // error: conflicts with X::M::g()
|
| 28 |
}
|
| 29 |
```
|
| 30 |
|
| 31 |
+
— *end example*]
|
| 32 |
+
|
| 33 |
Members of a named namespace can also be defined outside that namespace
|
| 34 |
by explicit qualification ([[namespace.qual]]) of the name being
|
| 35 |
defined, provided that the entity being defined was already declared in
|
| 36 |
the namespace and the definition appears after the point of declaration
|
| 37 |
in a namespace that encloses the declaration’s namespace.
|
| 38 |
|
| 39 |
+
[*Example 2*:
|
| 40 |
+
|
| 41 |
``` cpp
|
| 42 |
namespace Q {
|
| 43 |
namespace V {
|
| 44 |
void f();
|
| 45 |
}
|
| 46 |
+
void V::f() { ... } // OK
|
| 47 |
+
void V::g() { ... } // error: g() is not yet a member of V
|
| 48 |
namespace V {
|
| 49 |
void g();
|
| 50 |
}
|
| 51 |
}
|
| 52 |
|
| 53 |
namespace R {
|
| 54 |
+
void Q::V::g() { ... } // error: R doesn't enclose Q
|
| 55 |
}
|
| 56 |
```
|
| 57 |
|
| 58 |
+
— *end example*]
|
| 59 |
+
|
| 60 |
If a `friend` declaration in a non-local class first declares a class,
|
| 61 |
+
function, class template or function template[^5] the friend is a member
|
| 62 |
of the innermost enclosing namespace. The `friend` declaration does not
|
| 63 |
by itself make the name visible to unqualified lookup (
|
| 64 |
[[basic.lookup.unqual]]) or qualified lookup ([[basic.lookup.qual]]).
|
| 65 |
+
|
| 66 |
+
[*Note 2*: The name of the friend will be visible in its namespace if a
|
| 67 |
+
matching declaration is provided at namespace scope (either before or
|
| 68 |
+
after the class definition granting friendship). — *end note*]
|
| 69 |
+
|
| 70 |
+
If a friend function or function template is called, its name may be
|
| 71 |
+
found by the name lookup that considers functions from namespaces and
|
| 72 |
+
classes associated with the types of the function arguments (
|
| 73 |
+
[[basic.lookup.argdep]]). If the name in a `friend` declaration is
|
| 74 |
+
neither qualified nor a *template-id* and the declaration is a function
|
| 75 |
+
or an *elaborated-type-specifier*, the lookup to determine whether the
|
| 76 |
+
entity has been previously declared shall not consider any scopes
|
| 77 |
+
outside the innermost enclosing namespace.
|
| 78 |
+
|
| 79 |
+
[*Note 3*: The other forms of `friend` declarations cannot declare a
|
| 80 |
+
new member of the innermost enclosing namespace and thus follow the
|
| 81 |
+
usual lookup rules. — *end note*]
|
| 82 |
+
|
| 83 |
+
[*Example 3*:
|
| 84 |
|
| 85 |
``` cpp
|
| 86 |
// Assume f and g have not yet been declared.
|
| 87 |
void h(int);
|
| 88 |
template <class T> void f2(T);
|
|
|
|
| 98 |
};
|
| 99 |
|
| 100 |
// A::f, A::g and A::h are not visible here
|
| 101 |
X x;
|
| 102 |
void g() { f(x); } // definition of A::g
|
| 103 |
+
void f(X) { ... } // definition of A::f
|
| 104 |
+
void h(int) { ... } // definition of A::h
|
| 105 |
// A::f, A::g and A::h are visible here and known to be friends
|
| 106 |
}
|
| 107 |
|
| 108 |
using A::x;
|
| 109 |
|
|
|
|
| 112 |
A::X::f(x); // error: f is not a member of A::X
|
| 113 |
A::X::Y::g(); // error: g is not a member of A::X::Y
|
| 114 |
}
|
| 115 |
```
|
| 116 |
|
| 117 |
+
— *end example*]
|
| 118 |
+
|