From Jason Turner

[basic.scope.temp]

Diff to HTML by rtfpessoa

Files changed (1) hide show
  1. tmp/tmpnrbzvpwl/{from.md → to.md} +15 -91
tmp/tmpnrbzvpwl/{from.md → to.md} RENAMED
@@ -1,94 +1,18 @@
1
  ### Template parameter scope <a id="basic.scope.temp">[[basic.scope.temp]]</a>
2
 
3
- The declarative region of the name of a template parameter of a template
4
- *template-parameter* is the smallest *template-parameter-list* in which
5
- the name was introduced.
6
-
7
- The declarative region of the name of a template parameter of a template
8
- is the smallest *template-declaration* in which the name was introduced.
9
- Only template parameter names belong to this declarative region; any
10
- other kind of name introduced by the *declaration* of a
11
- *template-declaration* is instead introduced into the same declarative
12
- region where it would be introduced as a result of a non-template
13
- declaration of the same name.
14
-
15
- [*Example 1*:
16
-
17
- ``` cpp
18
- namespace N {
19
- template<class T> struct A { }; // #1
20
- template<class U> void f(U) { } // #2
21
- struct B {
22
- template<class V> friend int g(struct C*); // #3
23
- };
24
- }
25
- ```
26
-
27
- The declarative regions of `T`, `U` and `V` are the
28
- *template-declaration*s on lines \#1, \#2, and \#3, respectively. But
29
- the names `A`, `f`, `g` and `C` all belong to the same declarative
30
- region — namely, the *namespace-body* of `N`. (`g` is still considered
31
- to belong to this declarative region in spite of its being hidden during
32
- qualified and unqualified name lookup.)
33
-
34
- — *end example*]
35
-
36
- The potential scope of a template parameter name begins at its point of
37
- declaration [[basic.scope.pdecl]] and ends at the end of its declarative
38
- region.
39
-
40
- [*Note 1*:
41
-
42
- This implies that a *template-parameter* can be used in the declaration
43
- of subsequent *template-parameter*s and their default arguments but
44
- cannot be used in preceding *template-parameter*s or their default
45
- arguments. For example,
46
-
47
- ``` cpp
48
- template<class T, T* p, class U = T> class X { ... };
49
- template<class T> void f(T* p = new T);
50
- ```
51
-
52
- This also implies that a *template-parameter* can be used in the
53
- specification of base classes. For example,
54
-
55
- ``` cpp
56
- template<class T> class X : public Array<T> { ... };
57
- template<class T> class Y : public T { ... };
58
- ```
59
-
60
- The use of a template parameter as a base class implies that a class
61
- used as a template argument must be defined and not just declared when
62
- the class template is instantiated.
63
-
64
- — *end note*]
65
-
66
- The declarative region of the name of a template parameter is nested
67
- within the immediately-enclosing declarative region.
68
-
69
- [*Note 2*:
70
-
71
- As a result, a *template-parameter* hides any entity with the same name
72
- in an enclosing scope [[basic.scope.hiding]].
73
-
74
- [*Example 2*:
75
-
76
- ``` cpp
77
- typedef int N;
78
- template<N X, typename N, template<N Y> class T> struct A;
79
- ```
80
-
81
- Here, `X` is a non-type template parameter of type `int` and `Y` is a
82
- non-type template parameter of the same type as the second template
83
- parameter of `A`.
84
-
85
- — *end example*]
86
-
87
- — *end note*]
88
-
89
- [*Note 3*: Because the name of a template parameter cannot be
90
- redeclared within its potential scope [[temp.local]], a template
91
- parameter’s scope is often its potential scope. However, it is still
92
- possible for a template parameter name to be hidden; see 
93
- [[temp.local]]. — *end note*]
94
 
 
1
  ### Template parameter scope <a id="basic.scope.temp">[[basic.scope.temp]]</a>
2
 
3
+ Each template *template-parameter* introduces a
4
+ *template parameter scope* that includes the *template-head* of the
5
+ *template-parameter*.
6
+
7
+ Each *template-declaration* D introduces a template parameter scope that
8
+ extends from the beginning of its *template-parameter-list* to the end
9
+ of the *template-declaration*. Any declaration outside the
10
+ *template-parameter-list* that would inhabit that scope instead inhabits
11
+ the same scope as D. The parent scope of any scope S that is not a
12
+ template parameter scope is the smallest scope that contains S and is
13
+ not a template parameter scope.
14
+
15
+ [*Note 1*: Therefore, only template parameters belong to a template
16
+ parameter scope, and only template parameter scopes have a template
17
+ parameter scope as a parent scope. — *end note*]
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
18