-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathD1814R0.html
317 lines (294 loc) · 14.6 KB
/
D1814R0.html
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
<!DOCTYPE html>
<html><head>
<meta http-equiv="content-type" content="text/html; charset=UTF-8">
<style>
/**
* SyntaxHighlighter
* http://alexgorbatchev.com/SyntaxHighlighter
*
* SyntaxHighlighter is donationware. If you are using it, please donate.
* http://alexgorbatchev.com/SyntaxHighlighter/donate.html
*
* @version
* 3.0.83 (July 02 2010)
*
* @copyright
* Copyright (C) 2004-2010 Alex Gorbatchev.
*
* @license
* Dual licensed under the MIT and GPL licenses.
*/
.syntaxhighlighter {
background-color: white !important;
}
.syntaxhighlighter .line.alt1 {
background-color: white !important;
}
.syntaxhighlighter .line.alt2 {
background-color: white !important;
}
.syntaxhighlighter .line.highlighted.alt1, .syntaxhighlighter .line.highlighted.alt2 {
background-color: #e0e0e0 !important;
}
.syntaxhighlighter .line.highlighted.number {
color: black !important;
}
.syntaxhighlighter table caption {
color: black !important;
}
.syntaxhighlighter .gutter {
color: #afafaf !important;
}
.syntaxhighlighter .gutter .line {
border-right: 3px solid #6ce26c !important;
}
.syntaxhighlighter .gutter .line.highlighted {
background-color: #6ce26c !important;
color: white !important;
}
.syntaxhighlighter.printing .line .content {
border: none !important;
}
.syntaxhighlighter.collapsed {
overflow: visible !important;
}
.syntaxhighlighter.collapsed .toolbar {
color: blue !important;
background: white !important;
border: 1px solid #6ce26c !important;
}
.syntaxhighlighter.collapsed .toolbar a {
color: blue !important;
}
.syntaxhighlighter.collapsed .toolbar a:hover {
color: red !important;
}
.syntaxhighlighter .toolbar {
color: white !important;
background: #6ce26c !important;
border: none !important;
}
.syntaxhighlighter .toolbar a {
color: white !important;
}
.syntaxhighlighter .toolbar a:hover {
color: black !important;
}
.syntaxhighlighter .plain, .syntaxhighlighter .plain a {
color: black !important;
}
.syntaxhighlighter .comments, .syntaxhighlighter .comments a {
color: #008200 !important;
}
.syntaxhighlighter .string, .syntaxhighlighter .string a {
color: blue !important;
}
.syntaxhighlighter .keyword {
color: #006699 !important;
}
.syntaxhighlighter .preprocessor {
color: gray !important;
}
.syntaxhighlighter .variable {
color: #aa7700 !important;
}
.syntaxhighlighter .value {
color: #009900 !important;
}
.syntaxhighlighter .functions {
color: #ff1493 !important;
}
.syntaxhighlighter .constants {
color: #0066cc !important;
}
.syntaxhighlighter .script {
font-weight: bold !important;
color: #006699 !important;
background-color: none !important;
}
.syntaxhighlighter .color1, .syntaxhighlighter .color1 a {
color: gray !important;
}
.syntaxhighlighter .color2, .syntaxhighlighter .color2 a {
color: #ff1493 !important;
}
.syntaxhighlighter .color3, .syntaxhighlighter .color3 a {
color: red !important;
}
.syntaxhighlighter .keyword {
font-weight: bold !important;
}
.syntaxhighlighter div.toolbar span a.toolbar_item{
display: none !important;
}
body .syntaxhighlighter .line {
white-space: pre !important;
}
.pln{color:#000}@media screen{.str{color:#080}.kwd{color:#008}.com{color:#800}.typ{color:#606}.lit{color:#066}.clo,.opn,.pun{color:#660}.tag{color:#008}.atn{color:#606}.atv{color:#080}.dec,.var{color:#606}.fun{color:red}}@media print,projection{.kwd,.tag,.typ{font-weight:700}.str{color:#060}.kwd{color:#006}.com{color:#600;font-style:italic}.typ{color:#404}.lit{color:#044}.clo,.opn,.pun{color:#440}.tag{color:#006}.atn{color:#404}.atv{color:#060}}pre.prettyprint{padding:2px;border:1px solid #888}ol.linenums{margin-top:0;margin-bottom:0}li.L0,li.L1,li.L2,li.L3,li.L5,li.L6,li.L7,li.L8{list-style-type:none}li.L1,li.L3,li.L5,li.L7,li.L9{background:#eee}
</style>
<title>Wording for Class Template Argument Deduction for Alias Templates and Inherited Constructors</title>
</head>
<body>
<p>D1814R0<br>
Mike Spertus, Symantec<br>
Audience: Core Working Group
</p>
<h1>Wording for Class Template Argument Deduction for Alias Templates and Inherited Constructors
</h1>
This paper provides wording for the Alias Template and Inheriting Constructors Class Template Argument Deduction support from
<a href="http://www.open-std.org/jtc1/sc22/wg21/docs/papers/2019/p1021r4.html">D1814R0</a>.
<h2>Document revision history</h2>
<b>R0</b>, 2019-07-15: Split from P1021R4<br>
<h2>Wording</h2>
<p>Modify (dcl.type.simple/2) as follows</p>
<blockquote>
A <em>placeholder-type-specifier</em> is a placeholder for a type to be deduced (9.1.7.5). A <em>type-specifier</em> of the form
<tt>typename</tt><sub><em>opt</em></sub> <em>nested-name-specifier<sub>opt</sub> template-name</em> is a placeholder for a deduced class type (9.1.7.6).
<del>The
template-name
shall name a class template.</del><ins>The <em>nested-name-specifier</em>, if any, shall be non-dependent and the <em>template-name</em> shall name either a class template or an alias template whose <em>defining-type-id</em> is of the form
<tt>typename</tt><sub><em>opt</em></sub><em>nested-name-specifier</em><sub><em>opt</em></sub> <tt>template</tt><sub><em>opt</em></sub> <em>simple-template-id</em>
and the <em>nested-name-specifier</em> (if any) is non-dependent and the
<em>template-name</em> of the <em>simple-template-id</em> names a class template
of an alias template that in turn meets these requirements.</ins>
[Note: An <em>injected-class-name</em> is never interpreted as a <em>template-name</em>
in contexts where class template argument deduction would be performed (13.7.1).
— end note]
</blockquote>
<p>In over.match.class.deduct, modify the beginning of paragraph 1 as follows:</p>
<blockquote>When resolving a placeholder for a deduced class type (9.1.7.6) where the
<em>template-name</em> names a primary class template of C a set of functions and function templates<ins>, called the
<em>guides</em> of <em>C</em>,</ins> is formed comprising:</blockquote>
<p>In over.match.class.deduct, append after paragraph 1 as follows:</p>
<blockquote><ul><ul><li>The return type is the <em>simple-template-id</em> of the
<em>deduction-guide</em>.</li></ul></ul> <p><ins>In addition, if <tt>C</tt> inherits constructors (namespace.udecl 9.8)
from a base
class denoted by a <em>simple-template-id</em> <tt>D</tt>,
and if the name of an alias template whose <em>template-name</em>
is a placeholder for a template parameters are those of <tt>C</tt>
and whose <em>simple-template-id</em> is <tt>D</tt> is
a placeholder for a deduced class type, then the set also
contains the guides of that alias template.</ins></p>
<ins>When resolving a placeholder for a deduced class type (dcl.type.simple 9.1.7.2) where the
<em>template-name</em> names an alias template <tt>A</tt>
whose <em>defining-type-id</em> is a <em>simple-template-id</em>
<tt>B<L></tt>, the guides of A are the
set of function or function templates formed as follows. For each function or function
template <tt>f</tt> in the guides of <tt>B</tt> (as opposed to <tt>A</tt>),
form a function or function template <tt>f'</tt> according to the
following procedure and add it to the set:
<ul><li>Deduce the template arguments of the return type of <tt>f</tt>
from <tt>B<L></tt>
according to the process in (temp.deduct.type) with the exception that deduction does
not fail if not all template arguments are deduced. Let <tt>g</tt>
denote the result of substituting these deductions into <tt>f</tt>.
If the substitution fails, no <tt>f'</tt> is produced.</li>
<li>Form the function or function template <tt>f'</tt> as follows:
<ul><li>The function type of <tt>f'</tt> is the function type of <tt>g</tt>.
<li>If <tt>f</tt> is a function template,
the template parameter list of <tt>f'</tt>
consists of all the template parameters of <tt>A</tt>
(including their default template arguments)
that appear in the above deductions or (recursively) in their
default template arguments, followed by
the template parameters of <tt>f</tt> that were
not deduced (including their default template arguments).</li>
<li>The associated constraints (temp.constr.decl 12.4.2) are the conjunction of the associated constraints of <tt>g</tt> and a constraint that is satisfied if and only if the arguments of <tt>A</tt> are deducible (see below) from the return type.</li></ul>
<li>If <tt>f</tt> is a copy deduction candidate (over.match.class.deduct 11.3.1.8), then <tt>f'</tt>
is considered to be so as well.</li>
<li>
If <tt>f</tt> was generated from a <em>deduction-guide</em> (over.match.class.deduct 11.3.1.8), then <tt>f'</tt>
is considered to be so as well.</li>
<li>The <em>explicit-specifier</em> of <tt>f'</tt> is the <em>explicit-specifier</em> of <tt>g</tt> (if any).</li></ul>
The arguments of a template <tt>A</tt> are said to be deducible from a type <tt>T</tt> if, given a class template
<blockquote><pre>template <typename> class AA;</pre></blockquote>
with a single partial specialization whose template parameter list is that of <tt>A</tt> and whose template argumentIlist is a specialization of <tt>A</tt> with the template argument list of <tt>A</tt> (temp.dep.type), <tt>AA<T></tt> matches the partial specialization.
</ins><p>
<p>Initialization and overload resolution are performed as described in
(dcl.init 9.3) and (over.match.ctor 12.3.1.3),
(over.match.copy 12.3.1.4), or (over.match.list 12.3.1.7) (as
appropriate for the type of initialization performed) for an object of a hypothetical class type, where the <del>selected functions and function templates</del>
<em>guides of the template named by the placeholder</em> are considered to be the
constructors of that class type for the
purpose of forming an overload set, and the initializer is provided by the context in which class template
argument deduction was performed. As an exception, the first phase in 12.3.1.7 (considering initializer-list
constructors) is omitted if the initializer list consists of a single expression of type <em>cv</em> <tt>U</tt>,
where <tt>U</tt> is a specialization of <del><tt>C</tt></del>
<ins>the class template for which the placeholder names a specialization</ins> or a class derived <del>from a specialization of <tt>C</tt></del><ins>therefrom</ins>.
If the function or
function template was generated from a constructor or <em>deduction-guide</em>
that had an <em>explicit-specifier</em>, each such notional constructor is considered to
have that same <em>explicit-specifier</em>. All such notional constructors are considered
to be public members of the hypothetical class type.</p>
</blockquote>
Add the following example to the end of over.match.class.deduct
<blockquote><blockquote><tt>B b{(int*)0, (char*)0};
// OK, deduces B<char*></tt></blockquote>
— <em>end example</em> ]<br><br>
<ins>[<em>Example:</em><pre>
template <class T, class U> struct C {
C(T, U); // #1
};
template<class T, class U>
C(T, U) -> C<T, std::type_identity_t<U>>; // #2
template<class V>
using A = C<V *, V *>;
template<std::Integral W>
using B = A<W>;
int i{};
double d{};
A a1(&i, &i); // Deduces <em>A<int></em>
A a2(i, i); // <em>Error: cannot deduce V * from i</em>
A a3(&i, &d); // <em>Error: #1: Cannot deduce (V*, V*) from (int *, double *) </em>
#2: Cannot deduce C<V> from C<int *, double *>
B b1(&i, &i); // Deduces B<int>
B b2(&d, &d); // Error: cannot deduce B<W> from C<double *, double *>;
</pre>
Possible exposition only implementation of the above procedure:
<pre> //<em>The following concept ensures a specialization of A is deduced</em>
template <class> class AA;
template <class V> class AA<A<V>> { };
template <class T> concept deduces_A = requires { sizeof(AA<T>); };
// <em>f is formed (over.match.class.deduct 11.3.1.8) from the deduction-guide of C</em>
template<class T, class U> auto f(T, U) -> C<T, std::type_identity_t<U>>;
// <em>Deducing arguments for C<T, std::type_identity_t<U>> from C<V *, V*> deduces T as V *</em>
// <em>f' is obtained by transforming f as described by the above procedure</em>
template<class V, class U>
requires deduces_A<C<V *, std::type_identity_t<U>>>
auto f_prime(V *, U) -> C<V *, std::type_identity_t<U>>;
// <em>Likewise, f2 is formed from the C(T, U) constructor of C,</em>
// <em>generating the following function template</em>
template<class V>
requires deduces_A<C<V *, V *>>
auto f2_prime(V *, V*) -> C<V *, V *>;
// <em>The following concept ensures a specialization a B is deduced</em>
template <class> class BB;
template <class V> class BB<B<V>> { };
template <class T> concept deduces_B = requires { sizeof(BB<T>); };
// The function templates for B derived from the above f' and f2' for A is
template<std::Integral W, class U>
requires deduces_A<C<W *, std::type_identity_t<U>>>
&& deduces_B<C<W *, std::type_identity_t<U>>>
auto f_prime_for_B(W *, U) -> C<W *, std::type_identity_t<U>>;
template<std::Integral W>
requires deduces_A<C<W *, W *>>
&& deduces_B<C<W *, W *>>
auto f2_prime_for_B(W *, W *) -> C<W *, W *>;
</pre>
<em>— end example</em>]
</ins></blockquote>
Insert a bullet after over.match.best/2.9 as follows
<blockquote><blockquote><tt>bool b = 1 < S();</tt>
// <em>calls #2</em>
— end example
] or, if not that</blockquote>
<ul><ins><li><tt>F1</tt> is generated from class template argument deduction (over.match.class.deduct 11.3.1.8) for
a class <tt>D</tt>, <tt>F2</tt> is generated from inheriting constructors from
a base class of <tt>D</tt>, and for all arguments the corresponding
parameters of <tt>F1</tt> and <tt>F2</tt> have the same type, or if not that,</li></ins>
<li><tt>F1</tt> is generated from a <em>deduction-guide</em> (12.3.1.8) and <tt>F2</tt> is not, or, if not that</li></ul></blockquote>
<script type="text/javascript">
SyntaxHighlighter.defaults['gutter'] = false;
SyntaxHighlighter.all()
</script>
</body></html>