From Jason Turner

[basic.scope.temp]

Diff to HTML by rtfpessoa

Files changed (1) hide show
  1. tmp/tmppduwyn1z/{from.md → to.md} +35 -15
tmp/tmppduwyn1z/{from.md → to.md} RENAMED
@@ -10,10 +10,12 @@ 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
  ``` cpp
16
  namespace N {
17
  template<class T> struct A { }; // #1
18
  template<class U> void f(U) { } // #2
19
  struct B {
@@ -21,54 +23,72 @@ namespace N {
21
  };
22
  }
23
  ```
24
 
25
  The declarative regions of `T`, `U` and `V` are the
26
- *template-declaration*s on lines `#1`, `#2` and `#3`, respectively. But
27
  the names `A`, `f`, `g` and `C` all belong to the same declarative
28
  region — namely, the *namespace-body* of `N`. (`g` is still considered
29
  to belong to this declarative region in spite of its being hidden during
30
  qualified and unqualified name lookup.)
31
 
 
 
32
  The potential scope of a template parameter name begins at its point of
33
  declaration ([[basic.scope.pdecl]]) and ends at the end of its
34
- declarative region. This implies that a *template-parameter* can be used
35
- in the declaration of subsequent *template-parameter*s and their default
36
- arguments but cannot be used in preceding *template-parameter*s or their
37
- default arguments. For example,
 
 
 
 
38
 
39
  ``` cpp
40
- template<class T, T* p, class U = T> class X { /* ... */ };
41
  template<class T> void f(T* p = new T);
42
  ```
43
 
44
  This also implies that a *template-parameter* can be used in the
45
  specification of base classes. For example,
46
 
47
  ``` cpp
48
- template<class T> class X : public Array<T> { /* ... */ };
49
- template<class T> class Y : public T { /* ... */ };
50
  ```
51
 
52
  The use of a template parameter as a base class implies that a class
53
  used as a template argument must be defined and not just declared when
54
  the class template is instantiated.
55
 
 
 
56
  The declarative region of the name of a template parameter is nested
57
- within the immediately-enclosing declarative region. As a result, a
58
- *template-parameter* hides any entity with the same name in an enclosing
59
- scope ([[basic.scope.hiding]]).
 
 
 
 
 
60
 
61
  ``` cpp
62
  typedef int N;
63
  template<N X, typename N, template<N Y> class T> struct A;
64
  ```
65
 
66
  Here, `X` is a non-type template parameter of type `int` and `Y` is a
67
  non-type template parameter of the same type as the second template
68
  parameter of `A`.
69
 
70
- Because the name of a template parameter cannot be redeclared within its
71
- potential scope ([[temp.local]]), a template parameter’s scope is often
72
- its potential scope. However, it is still possible for a template
73
- parameter name to be hidden; see  [[temp.local]].
 
 
 
 
 
74
 
 
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 {
 
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
38
+ declarative 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