forked from villevoutilainen/papers
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathconstrained-decls.html
742 lines (686 loc) · 30.8 KB
/
constrained-decls.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
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"
"http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<title>Yet another approach for constrained declarations</title>
<style type="text/css">
html {font-family: "DejaVu Serif", serif; size: medium; line-height: 150%; margin: 0; padding: 0;}
code {font-family: "DejaVu Sans Mono", monospace; size: medium; line-height: 135%;}
body {margin: 1em 2em; padding: 0;}
h2 {margin: 1.5em 0 1em 0;}
p, li {text-align:justify}
ol.wide li {margin-top:1em;}
blockquote.note
{
background-color:#E0E0E0;
padding-left: 15px;
padding-right: 15px;
padding-top: 1px;
padding-bottom: 1px;
}
blockquote.std
{
max-width: 55em;
border-left: thick solid #AAA;
padding-left: 1em;
}
ins {color:#00A000}
del {color:#A00000}
p > code, li > code {color: #000080;}
table { border: 1px solid black; border-spacing: 0px;
margin-left: auto; margin-right: auto; }
th { text-align: left; vertical-align: top;
padding-left: 0.8em; border: none; }
td { text-align: left; vertical-align: top;
padding-left: 0.8em; border: none; }
table.table { border-spacing: 2px; border-collapse: separate; }
.table * th, .table * td { border: 1px solid black; }
</style>
</head>
<body>
<address style="text-align:right;">
Document number: D1141R1
<br/>
<br/>
<a href="mailto:[email protected]">Ville Voutilainen</a><br/>
<a href="mailto:[email protected]">Thomas Köppe</a><br/>
<a href="mailto:[email protected]">Andrew Sutton</a><br/>
<a href="mailto:[email protected]">Herb Sutter</a><br/>
<a href="mailto:[email protected]">Gabriel Dos Reis</a><br/>
<a href="mailto:[email protected]">Bjarne Stroustrup</a><br/>
<a href="mailto:[email protected]">Jason Merrill</a><br/>
<a href="mailto:[email protected]">Hubert Tong</a><br/>
<a href="mailto:[email protected]">Eric Niebler</a><br/>
<a href="mailto:[email protected]">Casey Carter</a><br/>
<a href="mailto:[email protected]">Tom Honermann</a><br/>
<a href="mailto:[email protected]">Erich Keane</a><br/>
<a href="mailto:[email protected]">Walter E. Brown</a><br/>
<a href="mailto:[email protected]">Michael Spertus</a><br/>
2018-10-08<br/>
</address>
<hr/>
<h1 style="text-align: center;">Yet another approach for constrained declarations</h1>
<h2>Abstract</h2>
<p>
We propose a short syntax for the constrained declaration
of function parameters, function return types and
variables. The new syntax is a “constrained
<code>auto</code>”, e.g. <code>void sort(Sortable auto& c);</code>.
</p>
<h2>Contents</h2>
<ol>
<li><a href="#revisions">Revision history</a></li>
<li><a href="#summary">Proposal summary</a></li>
<li><a href="#part1">Part 1: “Constrained <code>auto</code>”</a></li>
<li><a href="#part2">Part 2: Relaxed “constrained <code>auto</code>”</a></li>
<li><a href="#part3">Part 3: Meaning of “<code>template <Concept T></code>”</a></li>
<li><a href="#part4">Part 4: Meaning of “<code>template <Concept... T></code>” and its friends</a></li>
<li><a href="#part5">Part 5: Meaning of “<code>-> Concept auto</code>” and its friends</a></li>
</ol>
<h2 id="revisions">Revision history</h2>
<ul>
<li>This document:
<ul>
<li>Added discussion in Part 4 on variadic concepts.</li>
<li>Added discussion in Parts 2 and 5 on <i>return-type-requirement</i>s.</li>
</ul>
</li>
<li>P1141R0: Initial proposal.</li>
</ul>
<h2 id="summary">Proposal summary</h2>
<p>This paper proposes three things:</p>
<ol class="wide">
<li>A syntax for constrained declarations that is practically a
“constrained <code>auto</code>”;
the principle being “wherever <code>auto</code> goes,
a <code>Constraint auto</code> can also (non-recursively) go”.
The semantics are to deduce like <code>auto</code> and additionally check a constraint.
In a nutshell,
<blockquote><pre><code>void f(Sortable auto x);
Sortable auto f(); // #1
Sortable auto x = f(); // #2
template <Sortable auto N> void f();</code></pre></blockquote>
and all combined:
<blockquote><pre><code>template <Sortable auto N> Sortable auto f(Sortable auto x)
{
Sortable auto y = init;
}</code></pre></blockquote>
An unconstrained version of that is:
<blockquote><pre><code>template <auto N> auto f(auto x)
{
auto y = init;
}</code></pre></blockquote>
So, this proposal includes <code>auto</code>-typed parameters for
functions, which we already allow for lambdas.</li>
<li>An additional relaxation where the <code>auto</code> is optional
for the cases #1 and #2 illustrated above:
<blockquote><pre><code>Sortable f();
Sortable x = f();</code></pre></blockquote></li>
<li>Simplifying (and thus restricting) the rules in
<a href="https://wg21.link/temp.param#10">[temp.param]/10</a>,
so that <code>template <Sortable S></code> always
means that <code>S</code> is a type parameter, and
<code>template <Sortable auto S></code> always means
that <code>S</code> is a non-type parameter. Template template-parameters
are no longer supported in this short form. Moreover, <code>Sortable</code>
is restricted to be a concept that takes a type parameter or type parameter pack;
non-type and template concepts are no longer supported in this short form.
</li>
</ol>
<p><code>Sortable</code> is a “type concept” in all the examples of this summary.</p>
<p>
This paper specifically does <em>not</em> propose
</p>
<ul>
<li>any new lead-in syntax for templates, or</li>
<li>a new syntax for introducing names for placeholder types, or</li>
<li>a shortcut syntax for applying multiple constraints
to a placeholder type.</li>
</ul>
<p>
The idea of this approach is to provide a syntax that
</p>
<ul>
<li>
works for constrained function parameters, constrained
return types, constrained variables, and type-constrained
non-type template parameters;
</li>
<li>
avoids inventing many adventurous new things;
</li>
<li>
in particular, avoids inventing new type sigils;
</li>
<li>
does not clash with explicit template instantiations; and
</li>
<li>
is compatible with what we already have in polymorphic
lambdas, and makes functions uniform with them.
</li>
</ul>
<h2 id="part1">Part 1: “Constrained <code>auto</code>”</h2>
<p>
The approach proposed here borrows a subset of
<a href="http://open-std.org/JTC1/SC22/WG21/docs/papers/2017/p0807r0.html">P0807R0 An Adjective Syntax for Concepts</a>. The idea is that
we don’t try to come up with a notation that does everything
that P0807 does; in particular, there is no proposal for a new syntax
to introduce a type name.
</p>
<h3>Function templates</h3>
<p>
The approach is simple: allow <code>auto</code> parameters to produce
function templates (as they produce polymorphic lambdas), and allow the <code>auto</code>
to be preceded by a concept name. In every case, such a parameter
is a deduced parameter, and we can see which parameters are deduced
and which ones are not:
</p>
<blockquote><pre><code>[](auto a, auto& b, const auto& c, auto&& d) {...}; // unconstrained
[](Constraint auto a, Constraint auto& b, const Constraint auto& c, Constraint auto&& d) {...}; // constrained
void f1(auto a, auto& b, const auto& c, auto&& d) {...}; // unconstrained
void f2(Constraint auto a, Constraint auto& b, const Constraint auto& c, Constraint auto&& d) {...}; // constrained
[](Constraint auto&& a, SomethingElse&& b) {...}; // a constrained deduced forwarding reference and a concrete rvalue reference
void f3(Constraint auto&& a, SomethingElse&& b) {...}; // a constrained deduced forwarding reference and a concrete rvalue reference</code></pre></blockquote>
<p>
The appearance of <code>auto</code> (including <code>Constraint auto</code>)
in a parameter list
tells us that we are dealing with a function template. For each parameter,
we know whether it is deduced or not. We can tell apart
concepts from types: concepts precede <code>auto</code>, types do not.
</p>
<h3>Return types and variable declarations</h3>
<p>
Constrained return types work the same way:
</p>
<blockquote><pre><code>auto f4(); // unconstrained, deduced.
Constraint auto f5(); // constrained, deduced.
Whatever f6(); // See part 2. If Whatever is a type, not deduced.
// If Whatever is a concept, constrained and deduced.</code></pre></blockquote>
<p>
Note that <code>f4</code>, <code>f5</code> and <code>f6</code>
are not templates (whereas the previous <code>f1</code>, <code>f2</code>
and <code>f3</code> <em>are</em> templates). Here, there is no
mention of <code>auto</code> in the parameter list. Users have the choice
of adopting a style where it is explicit as to whether the return type is deduced.
</p>
<p>
Constrained types for variables work the same way:
</p>
<blockquote><pre><code>auto x1 = f1(); // unconstrained, deduced.
Constraint auto x2 = f2(); // constrained, deduced.
Whatever x3 = f3(); // See part 2. If Whatever is a type, not deduced.
// If Whatever is a concept, constrained and deduced.</code></pre></blockquote>
<p>
Again, users can make it so that it is easy to see when deduction occurs.
</p>
<p>
Since non-type template parameters can be deduced via <code>auto</code>
(as in <code>template <auto N> void f();</code>),
we also allow a constraint there:
</p>
<blockquote><pre><code>template <Constraint auto N> void f7();</code></pre></blockquote>
<p>
Note, however, that this can only be a type constraint; non-type concepts
(including auto concepts) are not allowed in this form.
</p>
<h3>Other uses of <code>auto</code></h3>
<p>
In concert with the general approach that “<code>Constraint auto</code> goes wherever
<code>auto</code> goes”, new-expressions and conversion operators work:
</p>
<blockquote><pre><code>auto alloc_next() { return new Sortable auto(this->next_val()); }
operator Sortable auto() { }</code></pre></blockquote>
<p>
A “<code>Constraint auto</code>” cannot be used to indicate that a function declarator has a trailing return type:
</p>
<blockquote><pre><code>Constraint auto f() -> auto; // ill-formed; shall be the single <i>type-specifier</i> <code>auto</code></code></pre></blockquote>
<p>
<code>decltype(auto)</code> can also be constrained:
</p>
<blockquote><pre><code>auto f() -> Constraint decltype(auto);
Constraint decltype(auto) x = f();</code></pre></blockquote>
<p>
Structured bindings do deduce <code>auto</code> in some cases; however, the <code>auto</code> is deduced from the whole (and not from the individual components).
It is somewhat doubtful that applying the constraint to the whole, as opposed to (for example) applying separately to each component, is the correct semantic.
Therefore, we propose to defer enabling the application of constraints to structured bindings to separate papers.
</p>
<h3>General rules</h3>
<p>
The constraint applies directly to the deduced type. It does not apply to the possibly cv-qualified
type described by the type specifiers, nor does it apply to the type declared for the variable:
</p>
<blockquote><pre><code>const Assignable<int> auto&& c = *static_cast<int *>(p); // Assignable<int &, int></code></pre></blockquote>
<p>
Naturally, if the deduced type is cv-qualified (or a reference), the constraint applies
to that type.
</p>
<p>
To keep things simple, an <code>auto</code> (or <code>decltype(auto)</code>) being constrained is always immediately preceded by the constraint. So, cv-qualifiers and concept-identifiers
cannot be freely mixed:
</p>
<blockquote><pre><code>const Contraint auto x = foo(); // ok
Constraint const auto x = foo(); // ill-formed
Constraint auto const y = foo(); // ok</code></pre></blockquote>
<p>
We propose only the ability to apply one single constraint for a parameter,
return type, or non-type template parameter. Any proposal to consider multiple
constraints should happen separately after C++20.
</p>
<p>
Partial concept identifiers also work. Given a concept
<code>template <typename T, typename... Args> concept
Constructible = /* ... */;</code>, we can say:
</p>
<blockquote><pre><code>void f(Constructible<int> auto x); // Constructible<decltype(x), int> is satisfied
Constructible<int> auto f();
Constructible<int> auto x = f();
template <Constructible<int> auto N> void f();</code></pre></blockquote>
<h2 id="part2">Part 2: Relaxed “constrained <code>auto</code>”</h2>
<p>
In the return type of a function declaration, we can leave out the <code>auto</code>.
So, in addition to
</p>
<blockquote><pre><code>Constraint auto f1();</code></pre></blockquote>
<p>
we can write
</p>
<blockquote><pre><code>Constraint f2();</code></pre></blockquote>
<p>
Neither <code>f1</code> nor <code>f2</code> are templates.
It seems fairly reasonable to allow omitting the <code>auto</code>,
but that is intended to be a relaxation of the general rule,
not a replacement for <code>Constraint auto</code>.
</p>
<p>
Trailing return types in function declarations behave the same way:
</p>
<blockquote><pre><code>auto f1() -> Constraint; // okay</code></pre></blockquote>
<p>
Trailing return types are also used for <i>return-type-requirement</i>s; however, <code>auto</code> does not (currently) go in such a context, whereas constraints <em>do</em>.
A minimal change we can make as part of this proposal is to take <code>auto</code> as being implicitly modified by a least constrained concept where a constraint is currently allowed in a <i>return-type-requirement</i>.
At the same time, <code>Constraint auto</code> would also be allowed. Thus, a plain <code>Constraint</code> in such a position can be seen as a case of relaxed “constrained <code>auto</code>”.
The interaction with
<a href="http://www.open-std.org/jtc1/sc22/wg21/docs/papers/2018/p1084r0.pdf">P1084R0 Today’s <i>return-type-requirement</i>s Are Insufficient</a>
is discussed later in this paper.
</p>
<p>For example:</p>
<blockquote><pre><code>requires(T t) {
{t} -> const auto*; // t needs to be a pointer to const
}
requires(T t) {
{t} -> Constraint auto; // t needs to be of a type that satisfies Constraint
}</code></pre></blockquote>
<p>
In variable declarations, omitting the <code>auto</code>
also seems reasonable:
</p>
<blockquote><pre><code>Constraint x = f2();</code></pre></blockquote>
<p>
Note, in particular, that we already have a syntax that
does (partial) deduction but doesn’t make that explicit in the syntax:
</p>
<blockquote><pre><code>std::tuple x = foo();</code></pre></blockquote>
<p>
The variable case in particular seems reasonable, considering
the already existing deduction syntaxes that don’t call
attention to deduction. The user always has a choice to use
a more explicit syntax. The return type case might well have
a weaker rationale for being allowed. It should be noted, though,
that this relaxation in general was present in the TS; this
paper is merely not proposing it for parameters.
</p>
<p>
Certain disambiguation details need to be handled:
</p>
<blockquote><pre><code>bool b(Constructible<int> && bar()); // variable definition
void foo() {
Constructible<int> * f2(); // disambiguation/type-name interpretation rule required
Constructible<int> * selector = f2(); // (same?) disambiguation/type-name interpretation rule required
}</code></pre></blockquote>
<p>
Note that the variable definition is unambiguously a variable
definition. This proposal proposes no function declaration
syntax that would clash with it; in particular, <code>Constructible<int></code>
is not considered a <i>type-name</i> that is short for <code>Constructible<int> auto</code>
except in limited contexts. It’s merely something to be aware of, and a demonstration of how
the presence of <code>auto</code> avoids ambiguity. For each remaining case above,
<code>Constructible<int></code> <em>does</em> appear within such a limited context when parsing
the statements as prospective declaration statements; we propose to generalize the rule for disambiguating
in favor of declaration statements to cover this case.
</p>
<h2 id="part3">Part 3: Meaning of “<code>template <Concept T></code>”</h2>
<p>
In <a href="https://wg21.link/temp.param#10">[temp.param]/10</a> we have:
</p>
<blockquote class="std">
<p>
A <i>constrained-parameter</i> declares a template parameter whose kind (type, non-type, template) and type
match that of the prototype parameter (17.6.8) of the concept designated by the <i>qualified-concept-name</i>
in the <i>constrained-parameter</i>. Let <code>X</code> be the prototype parameter of the designated concept.
The declared template parameter is determined by the kind of <code>X</code> (type, non-type, template)
and the optional ellipsis in the <i>constrained-parameter</i> as follows.
</p>
<ul>
<li>If <code>X</code> is a type <i>template-parameter</i>,
the declared parameter is a type <i>template-parameter</i>.</li>
<li>If <code>X</code> is a non-type <i>template-parameter</i>,
the declared parameter is a non-type <i>template-parameter</i>
having the same type as <code>X</code>.</li>
<li>If <code>X</code> is a template <i>template-parameter</i>,
the declared parameter is a template <i>template-parameter</i>
having the same <i>template-parameter-list</i> as <code>X</code>,
excluding default template arguments.</li>
<li>If the <i>qualified-concept-name</i> is followed by an ellipsis,
then the declared parameter is a template parameter pack (17.6.3).</li>
</ul>
<p>
[<i>Example</i>:
</p>
<blockquote><pre><code>template<typename T> concept C1 = true;
template<template<typename> class X> concept C2 = true;
template<int N> concept C3 = true;
template<typename... Ts> concept C4 = true;
template<char... Cs> concept C5 = true;
template<C1 T> void f1(); // OK, T is a type template-parameter
template<C2 X> void f2(); // OK, X is a template with one type-parameter
template<C3 N> void f3(); // OK, N has type int
template<C4... Ts> void f4(); // OK, Ts is a template parameter pack of types
template<C4 T> void f5(); // OK, T is a type template-parameter
template<C5... Cs> void f6(); // OK, Cs is a template parameter pack of chars</code></pre></blockquote>
<p>
—<i>end example</i>]
</p>
</blockquote>
<p>
Does that seem like a mouthful?
</p>
<p>
That’s because it is. In <code>template <Constraint T></code>, the kind of
<code>T</code> depends on the kind of the prototype parameter of <code>Constraint</code>.
</p>
<p>
We instead propose that, for such a constrained-parameter syntax:
</p>
<ul>
<li><code>T</code> should always be a type, and</li>
<li><code>Constraint</code> would always need to be a concept
that has a corresponding type parameter or type parameter pack.</li>
</ul>
<p>
To be clear, we are not proposing that concepts in general should not
have non-type or template template parameters. We are merely proposing for it to be the case
that the constrained parameter shortcut is not provided for concepts with
such prototype parameters; such concepts would need to be used with a <i>requires-clause</i>.
The constrained parameter syntax should mean just one thing.
Note that the same syntax <code>template <A T></code> is still a non-type
parameter when <code>A</code> is a type name rather than a concept. We are willing
to tolerate this small potential for ambiguity.</p>
<p>
The rationale for this part is as follows:
</p>
<ol>
<li>It seems desirable to have the constrained template parameter syntax.</li>
<li>It would be nice if that syntax covered the most common case.</li>
<li>It would further be nice if that syntax covered <em>only</em> the most common case.</li>
<li>The other cases are expected to be so rare that there’s no
need to provide a shortcut for them, and they are certainly rare enough
that they shouldn’t use the same syntax.</li>
</ol>
<p>
So, to clarify:
</p>
<ul>
<li><code>template <MyIntTypeDef N></code> means
a non-type parameter, like it always did.</li>
<li><code>template <ConceptName T></code> means
a type parameter constrained by <code>ConceptName</code>,
and the prototype parameter of <code>ConceptName</code> needs to be
a type parameter or a type parameter pack.</li>
<li><code>template <auto N></code> means a non-type parameter
with a deduced type.</li>
<li><code>template <ConceptName auto N></code> means
a non-type parameter with a deduced type constrained by
<code>ConceptName</code>, and the prototype parameter of <code>ConceptName</code>
needs to be a type parameter or a type parameter pack.</li>
</ul>
<p>
Other use cases can be done with <i>requires-clause</i>s.
</p>
<h2 id="part4">Part 4: Meaning of “<code>template <Concept... T></code>” and its friends</h2>
<p>
In <a href="https://wg21.link/temp.param#11">[temp.param]/11</a> we have:
</p>
<blockquote class="std"><pre><code>template<C2... T> struct s3; // associates C2<T...>
</code></pre></blockquote>
<p>
This seems to be doing an unexpected thing, which is having the constraint
apply to more than one type in a pack at a time. We propose that, regardless of whether the prototype parameter of the named concept is a pack:
</p>
<ul>
<li>For a simple pack of constrained types, the concept
mentioned is applied, as a unary concept, to each type in the pack in turn.</li>
<li>For a pack of constrained types that use <i>partial-concept-id</i>s,
the concept
mentioned is applied, as an n-ary concept whose arity is unaffected by the size of the pack, <i>individually</i> to each type in the pack in turn.</li>
</ul>
<p>
In other words,
</p>
<ul>
<li><code>template <ConceptName... T> void f(T...);</code>
means a variadic function template where each type in the pack
<code>T</code> needs to satisfy <code>ConceptName</code> as a unary concept, applied
as <code>ConceptName<T<sub>n</sub>></code>.</li>
<li>Similarly, <code>void f(ConceptName auto... T);</code>
means exactly the same thing.</li>
<li><code>template <ConceptName<int>... U> void f(U...);</code>
means a variadic function template where each type in the pack
<code>U</code> needs to satisfy <code>ConceptName</code> as a binary concept, applied
as <code>ConceptName<U<sub>n</sub>, int></code>.</li>
<li>Similarly, <code>void f(ConceptName<int> auto... U);</code>
means exactly the same thing.</li>
<li><code>template <ConceptName<0u, void, wchar_t>... U> void f(U...);</code>
means a variadic function template where each type in the pack
<code>U</code> needs to satisfy <code>ConceptName</code> as a n-ary concept, applied
as <code>ConceptName<U<sub>n</sub>, 0u, void, wchar_t></code>.</li>
</ul>
<h2 id="part5">Part 5: Meaning of “<code>-> Concept auto</code>” and its friends</h2>
<p>
<code>Constraint auto</code>, by virtue of being allowed where <code>auto</code> may appear, may now appear (at least syntactically) in a
trailing return type. Following the general rule that we deduce like <code>auto</code> (and additionally check the constraint),
a meaning is given for “<code>-> Concept auto</code>” when it appears as the trailing return type in a function definition.
The meaning being that we get plain return type deduction (as with <code>auto</code>) plus a check of the constraint.
</p>
<p>
In <a href="#part2">Part 2</a>, we note that trailing return types are also used for <i>return-type-requirement</i>s
and we propose for a meaning to be given for use of plain <code>auto</code> in such a context. Further building along that direction, the form of
<i>return-type-requirement</i> involving a concept to be satisfied becomes merely a generalization of
<i>trailing-return-type</i>s with placeholder types. The deduction as described in Part 2 is based on the status quo of the post-Rapperswil working
draft, and it is similar to that of the TS and to the deduction that occurs for return type deduction.
</p>
<p>
P1084R0 explains that the existing deduction rules associated with <i>return-type-requirement</i>s is lacking in terms of expressing certain desired
semantics. As a solution, it proposed making <code>-> Constraint</code> more of a special case in the context of a
<i>return-type-requirement</i>. Expressed in terms of deduction, the semantics proposed by P1084R0 is more akin to deduction for a theoretical
<code>decltype((auto))</code> than to deduction for <code>auto</code>. Which is to say that the semantics for
</p>
<blockquote><pre><code>-> Constraint</code></pre></blockquote>
<p>
as proposed in P1084R0 is incongruous with how we would describe the semantics of
</p>
<blockquote><pre><code>-> Constraint auto</code></pre></blockquote>
<p>
in the context of this paper.
</p>
<p>
This paper raises the possibility of expressing the semantics requested in P1084R0 in a different manner.
<code>{(E)} -> Constraint decltype(auto);</code>
produces the effect that P1084R0 requests for
<code>{E} -> Constraint;</code>
in terms of applying <code>Constraint</code> with <code>decltype((E))</code>
as the argument to its prototype parameter.
There is a further consideration as to whether convertibility, as opposed to type identity, should be enforced; in particular,
P1084R0 leaves the possibility that
<code>{A()} -> std::Same<A></code>
would be satisfied, but
<code>{A()} -> A</code>
would not be.
</p>
<p>
Three different kinds of convertibility requirement have been applied in the various iterations of <i>return-type-requirement</i> thus far.
With
WD signifying <a href="http://www.open-std.org/jtc1/sc22/wg21/docs/papers/2018/n4762.pdf">N4762</a>,
TS signifying <a href="http://www.open-std.org/jtc1/sc22/wg21/docs/papers/2017/n4674.pdf">N4674</a>,
and <code>return</code> representing return type deduction (whether under the TS or under this proposal);
the table below summarizes:
</p>
<table class="table">
<colgroup span="1"></colgroup>
<colgroup span="4"></colgroup>
<colgroup span="4"></colgroup>
<thead>
<tr>
<td></td>
<th colspan="4" scope="colgroup">Concrete type</th>
<th colspan="4" scope="colgroup">Placeholder type</th>
</tr>
</thead>
<tbody>
<tr>
<td></td>
<th scope="col">WD</th>
<th scope="col">TS</th>
<th scope="col"><code>return</code></th>
<th scope="col">P1084</th>
<th scope="col">WD</th>
<th scope="col">TS</th>
<th scope="col"><code>return</code></th>
<th scope="col">P1084</th>
</tr>
<tr>
<th scope="row">Deduction only</th>
<td></td>
<td></td>
<td></td>
<td></td>
<td>X</td>
<td></td>
<td></td>
<td>X</td>
</tr>
<tr>
<th scope="row">Implicit conversion sequence</th>
<td></td>
<td></td>
<td></td>
<td></td>
<td></td>
<td>X</td>
<td></td>
<td></td>
</tr>
<tr>
<th scope="row">Well-formed copy initialization</th>
<td>X</td>
<td>X</td>
<td>X</td>
<td>X</td>
<td></td>
<td></td>
<td>X</td>
<td></td>
</tr>
</tbody>
</table>
<p>
The deduction-only situation with the WD may well be a wording defect, since <code>{0} -> std::Same<int>&</code> would surprisingly not fail.
Similarly, for the TS, the difference between requiring an implicit conversion sequence and requiring a well-formed copy initialization is somewhat subtle.
Nevertheless, the treatment for concrete types differ from that of types involving placeholders for every iteration of <i>return-type-requirement</i> thus far
(given that return type deduction is present for comparison only). This seems undesirable.
</p>
<p>
The WD situation shows that some sort of requirement would be needed since deduction is not sufficient.
A convertibility requirement is an option; however, P1084 does not impose a convertibility requirement for the placeholder case.
Under P1084, the placeholder case would trivially pass a value category-aware type identity check.
Requiring such a check of <code>decltype((E))</code> being the same as the type in the <i>return-type-requirement</i> (after substitution of the deduced placeholders, if any)
is also an option. P1084 proposes a generalization of a same-type constraint, applying a change only to the placeholder case;
this latter option is an application of a generalized same-type constraint on the non-placeholder case (as well as to placeholder cases that P1084 drops).
</p>
<p>
For a parenthesized lvalue of type <code>int</code>, the following table describes the value category-aware type identity check:
</p>
<table class="table">
<thead>
<tr>
<td></td>
<th>Type deduced/passed to prototype parameter</th>
<th>Type to match</th>
<th>Type matches</th>
</tr>
</thead>
<tbody>
<tr>
<th><code>auto</code></th>
<td><code>int</code></td>
<td><code>int</code></td>
<td>no</td>
</tr>
<tr>
<th><code>C</code></th>
<td><code>int</code></td>
<td><code>int</code></td>
<td>no</td>
</tr>
<tr>
<th><code>C&</code></th>
<td><code>int</code></td>
<td><code>int&</code></td>
<td>yes</td>
</tr>
<tr>
<th><code>C&&</code> (forwarding reference)</th>
<td><code>int&</code></td>
<td><code>int&</code></td>
<td>yes</td>
</tr>
<tr>
<th><code>C decltype(auto)</code></th>
<td><code>int&</code></td>
<td><code>int&</code></td>
<td>yes</td>
</tr>
<tr>
<th><code>const C&</code></th>
<td><code>int</code></td>
<th><code>const int&</code></th>
<td>no</td>
</tr>
<tr>
<th><code>int</code></th>
<td>N/A</td>
<th><code>int</code></th>
<td>no</td>
</tr>
<tr>
<th><code>int&</code></th>
<td>N/A</td>
<th><code>int&</code></th>
<td>yes</td>
</tr>
<tr>
<th><code>int&&</code></th>
<td>N/A</td>
<th><code>int&&</code></th>
<td>no</td>
</tr>
</tbody>
</table>
<p>
In brief, <code>auto</code> means “is a prvalue”,
<code>const C&</code> means “is an lvalue of <code>const T</code> requiring <code>C<T></code>”,
<code>int&&</code> means “is an <code>int</code> xvalue”, and
<code>C decltype(auto)</code> has the semantics requested in P1084 for all parenthesized expressions.
</p>
</body>
</html>