From Jason Turner

[temp.spec.partial.general]

Diff to HTML by rtfpessoa

Files changed (1) hide show
  1. tmp/tmp8xkdqiio/{from.md → to.md} +144 -0
tmp/tmp8xkdqiio/{from.md → to.md} RENAMED
@@ -0,0 +1,144 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ #### General <a id="temp.spec.partial.general">[[temp.spec.partial.general]]</a>
2
+
3
+ A partial specialization of a template provides an alternative
4
+ definition of the template that is used instead of the primary
5
+ definition when the arguments in a specialization match those given in
6
+ the partial specialization [[temp.spec.partial.match]]. A declaration of
7
+ the primary template shall precede any partial specialization of that
8
+ template. A partial specialization shall be reachable from any use of a
9
+ template specialization that would make use of the partial
10
+ specialization as the result of an implicit or explicit instantiation;
11
+ no diagnostic is required.
12
+
13
+ Two partial specialization declarations declare the same entity if they
14
+ are partial specializations of the same template and have equivalent
15
+ *template-head*s and template argument lists [[temp.over.link]]. Each
16
+ partial specialization is a distinct template.
17
+
18
+ [*Example 1*:
19
+
20
+ ``` cpp
21
+ template<class T1, class T2, int I> class A { };
22
+ template<class T, int I> class A<T, T*, I> { };
23
+ template<class T1, class T2, int I> class A<T1*, T2, I> { };
24
+ template<class T> class A<int, T*, 5> { };
25
+ template<class T1, class T2, int I> class A<T1, T2*, I> { };
26
+ ```
27
+
28
+ The first declaration declares the primary (unspecialized) class
29
+ template. The second and subsequent declarations declare partial
30
+ specializations of the primary template.
31
+
32
+ — *end example*]
33
+
34
+ A partial specialization may be constrained [[temp.constr]].
35
+
36
+ [*Example 2*:
37
+
38
+ ``` cpp
39
+ template<typename T> concept C = true;
40
+
41
+ template<typename T> struct X { };
42
+ template<typename T> struct X<T*> { }; // #1
43
+ template<C T> struct X<T> { }; // #2
44
+ ```
45
+
46
+ Both partial specializations are more specialized than the primary
47
+ template. \#1 is more specialized because the deduction of its template
48
+ arguments from the template argument list of the class template
49
+ specialization succeeds, while the reverse does not. \#2 is more
50
+ specialized because the template arguments are equivalent, but the
51
+ partial specialization is more constrained [[temp.constr.order]].
52
+
53
+ — *end example*]
54
+
55
+ The template argument list of a partial specialization is the
56
+ *template-argument-list* following the name of the template.
57
+
58
+ A partial specialization may be declared in any scope in which the
59
+ corresponding primary template may be defined
60
+ [[dcl.meaning]], [[class.mem]], [[temp.mem]].
61
+
62
+ [*Example 3*:
63
+
64
+ ``` cpp
65
+ template<class T> struct A {
66
+ struct C {
67
+ template<class T2> struct B { };
68
+ template<class T2> struct B<T2**> { }; // partial specialization #1
69
+ };
70
+ };
71
+
72
+ // partial specialization of A<T>::C::B<T2>
73
+ template<class T> template<class T2>
74
+ struct A<T>::C::B<T2*> { }; // #2
75
+
76
+ A<short>::C::B<int*> absip; // uses partial specialization #2
77
+ ```
78
+
79
+ — *end example*]
80
+
81
+ Partial specialization declarations do not introduce a name. Instead,
82
+ when the primary template name is used, any reachable partial
83
+ specializations of the primary template are also considered.
84
+
85
+ [*Note 1*: One consequence is that a *using-declaration* which refers
86
+ to a class template does not restrict the set of partial specializations
87
+ that are found through the *using-declaration*. — *end note*]
88
+
89
+ [*Example 4*:
90
+
91
+ ``` cpp
92
+ namespace N {
93
+ template<class T1, class T2> class A { }; // primary template
94
+ }
95
+
96
+ using N::A; // refers to the primary template
97
+
98
+ namespace N {
99
+ template<class T> class A<T, T*> { }; // partial specialization
100
+ }
101
+
102
+ A<int,int*> a; // uses the partial specialization, which is found through the using-declaration
103
+ // which refers to the primary template
104
+ ```
105
+
106
+ — *end example*]
107
+
108
+ A non-type argument is non-specialized if it is the name of a non-type
109
+ parameter. All other non-type arguments are specialized.
110
+
111
+ Within the argument list of a partial specialization, the following
112
+ restrictions apply:
113
+
114
+ - The type of a template parameter corresponding to a specialized
115
+ non-type argument shall not be dependent on a parameter of the partial
116
+ specialization.
117
+ \[*Example 5*:
118
+ ``` cpp
119
+ template <class T, T t> struct C {};
120
+ template <class T> struct C<T, 1>; // error
121
+
122
+ template< int X, int (*array_ptr)[X] > class A {};
123
+ int array[5];
124
+ template< int X > class A<X,&array> { }; // error
125
+ ```
126
+
127
+ — *end example*]
128
+ - The partial specialization shall be more specialized than the primary
129
+ template [[temp.spec.partial.order]].
130
+ - The template parameter list of a partial specialization shall not
131
+ contain default template argument values.[^8]
132
+ - An argument shall not contain an unexpanded pack. If an argument is a
133
+ pack expansion [[temp.variadic]], it shall be the last argument in the
134
+ template argument list.
135
+
136
+ The usual access checking rules do not apply to non-dependent names used
137
+ to specify template arguments of the *simple-template-id* of the partial
138
+ specialization.
139
+
140
+ [*Note 2*: The template arguments can be private types or objects that
141
+ would normally not be accessible. Dependent names cannot be checked when
142
+ declaring the partial specialization, but will be checked when
143
+ substituting into the partial specialization. — *end note*]
144
+