forked from HowardHinnant/papers
-
Notifications
You must be signed in to change notification settings - Fork 5
/
constrained-decls.html
1147 lines (1001 loc) · 50 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
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN" "http://www.w3.org/TR/html4/strict.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, h3, h4 {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;
}
blockquote.stdins
{
max-width: 55em;
border-left: thick solid #00A000;
padding-left: 1em;
}
blockquote.stddel
{
max-width: 55em;
border-left: thick solid #A00000;
padding-left: 1em;
}
blockquote.stdins * { color: #00A000; text-decoration: underline; }
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; }
/* ul[del] is a list with deleted bullets */
ul.del li {
list-style-type: none;
list-style-position: outside;
text-indent: -1ex;
}
ul.del li:before {
display: inline-block;
content: "\2022";
color: #A00000;
text-decoration: line-through;
width: 1ex;
}
</style>
</head>
<body>
<address style="text-align:right;">
Document number: P1141R2
<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/>
<a href="mailto:[email protected]">Richard Smith</a><br/>
2018-11-09<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="#proposal">Proposal details</a>
<ul>
<li><a href="#part1">Part 1: “Constrained <code>auto</code>”</a></li>
<li><a href="#part2">Part 2: Relaxed “constrained <code>auto</code>”</a> [not proposed]</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> [not proposed]</li>
</ul>
</li>
<li><a href="#wording">Proposed wording for Parts 1, 3, and 4</a>
<ul>
<li><a href="#wordingexpr">Changes in [expr]</a></li>
<li><a href="#wordingdcl">Changes in [dcl]</a></li>
<li><a href="#wordingtemp">Changes in [temp]</a></li>
</ul>
</li>
</ol>
<h2 id="revisions">Revision history</h2>
<ul>
<li>P1141R2 (this document):
Added formal wording for parts 1, 3, and 4. Parts 2 and 5 are not being proposed.</li>
<li><a href="http://www.open-std.org/jtc1/sc22/wg21/docs/papers/2018/p1141r1.html">P1141R1</a>:
Added discussion in Parts 2 and 5 on <i>return-type-requirement</i>s and in Part 4 on variadic concepts.
</li>
<li><a href="http://www.open-std.org/jtc1/sc22/wg21/docs/papers/2018/p1141r0.html">P1141R0</a>:
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>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>
<li>Changing the meaning of parameter packs, so that <code>template <Sortable ...T></code>
means <code>requires Sortable<T> && ... && true</code>, and not
<code>requires Sortable<T...></code>.</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>
<p>The previous revision of this paper
(<a href="http://www.open-std.org/jtc1/sc22/wg21/docs/papers/2018/p1141r1.html">P1141R1</a>)
also proposed (in Part 2) an optional relaxation where the <code>auto</code>
would be optional for the cases #1 and #2 illustrated above, and (in Part 5) a
change of the meaning of <code>-> Concept auto</code>. However, EWG decided
to propose only parts 1, 3, and 4.</p>
<h2 id="proposal">Proposal details</h2>
<h3 id="part1">Part 1: “Constrained <code>auto</code>”</h3>
<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>
<h4>Function templates</h4>
<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>
<h4>Return types and variable declarations</h4>
<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>
<h4>Other uses of <code>auto</code></h4>
<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>
<h4>General rules</h4>
<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>
<h3 id="part2" style="color: #666"><span style="text-decoration: line-through">Part 2: Relaxed “constrained <code>auto</code>”</span> [not proposed]</h3>
<h3 id="part3">Part 3: Meaning of “<code>template <Concept T></code>”</h3>
<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>type-constraint</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>type-constraint</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>
<h3 id="part4">Part 4: Meaning of “<code>template <Concept... T></code>” and its friends</h3>
<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>
<h3 id="part5" style="color: #666"><span style="text-decoration: line-through">Part 5: Meaning
of “<code>-> Concept auto</code>” and its friends</span> [not proposed]</h3>
<h2 id="wording">Proposed wording for Parts 1, 3, and 4</h2>
<h3 id="wordingexpr">Changes in [expr]</h3>
<p>
Update [expr.prim.lambda, 7.5.5], paragraph 5, to allow
placeholder type specifiers as lambda parameters.
</p>
<blockquote class="std">
<p>A lambda is a generic lambda if
<del>the <code>auto</code> <i>type-specifier</i> appears as one of the
<i>decl-specifier</i>s</del><ins>there is a <i>decl-specifier</i> that is a <i>placeholder-type-specifier</i></ins>
in the <i>decl-specifier-seq</i>
of a <i>parameter-declaration</i> of the <i>lambda-expression</i>,
or if the lambda has a <i>template-parameter-list</i>.
[<i>Example:</i> […] —<i>end example</i>]</p>
</blockquote>
<p>
In [expr.prim.lambda.closure, 7.5.5.1], modify paragraph 3.
</p>
<blockquote class="std">
<p>The closure type for a <del>non-generic</del> <i>lambda-expression</i> has a public inline
function call operator <ins>(for a non-generic lambda) or function call operator template (for a generic lambda)</ins> (11.5.4)
whose parameters and return type are described
by the <i>lambda-expression</i>’s <i>parameter-declaration-clause</i>
and <i>trailing-return-type</i> respectively<del>. For a generic lambda,
the closure type has a public inline function call
operator member template (12.6.2) </del><ins>, and</ins> whose <i>template-parameter-list</i>
consists of the specified <i>template-parameter-list</i>, if any<del>, to which is
appended one invented type <i>template-parameter</i> for each occurrence of
<code>auto</code> in the lambda’s <i>parameter-declaration-clause</i>, in
order of appearance.
The invented type <i>template-parameter</i> is a template parameter pack if
the corresponding parameter-declaration declares a function parameter pack (9.2.3.5).
The return type and function parameters of the function call operator template
are derived from the <i>lambda-expression</i>’s <i>trailing-return-type</i>
and <i>parameter-declaration-clause</i> by replacing each occurrence of
<code>auto</code> in the <i>decl-specifier</i>s of the
<i>parameter-declaration-clause</i> with the name of the corresponding
<i>invented template-parameter</i></del>. The <i>requires-clause</i> of the function
call operator template is the <i>requires-clause</i> immediately following
<code><</code> <i>template-parameter-list</i> <code>></code>, if any. The trailing
<i>requires-clause</i> of the function call operator or operator template is
the <i>requires-clause</i> following the <i>lambda-declarator</i>, if any.
<ins>[<i>Note</i>: The function call operator for a generic lambda might
be an abbreviated function template (9.2.3.5). —<i>end note</i>]</ins>
[<i>Example:</i> […] —<i>end example</i>]</p>
</blockquote>
<p>Modify paragraph 6 as follows.</p>
<blockquote class="std">
<p><ins>[<i>Note</i>:</ins> The function call operator or operator template may be constrained (12.4.2)
by a <del><i>constrained-parameter</i></del><ins><i>type-constraint</i></ins>
(12.1), a <i>requires-clause</i> (Clause 12), or a
trailing <i>requires-clause</i> (9.2)<ins></ins>. [<i>Example</i>:</p>
<blockquote><pre><code>template <typename T> concept C1 = /* ... */;
template <std::size_t N> concept C2 = /* ... */;
template <typename A, typename B> concept C3 = /* ... */;
auto f = []<typename T1, C1 T2> requires C2<sizeof(T1) + sizeof(T2)>
(T1 a1, T1 b1, T2 a2, auto a3, auto a4) requires C3<decltype(a4), T2> {
// T2 is <del>a constrained parameter</del><ins>constrained by a <i>type-constraint</i></ins>,
// T1 and T2 are constrained by a <i>requires-clause</i>, and
// T2 and the type of a4 are constrained by a trailing <i>requires-clause</i>.
};</code></pre></blockquote>
<p>—<i>end example</i>] <ins>—<i>end note</i>]</ins></p>
</blockquote>
<h3 id="wordingdcl">Changes in [dcl]</h3>
<p>Change [dcl.type.simple, 9.1.7.2] paragraph 1 to add <i>placeholder-type-specifier</i>s.</p>
<blockquote class="std">
<blockquote><pre><code><i>simple-type-specifier</i>:
<i>nested-name-specifier<sub>opt</sub> type-name</i>
<i>nested-name-specifier</i> template <i>simple-template-id</i>
<i>nested-name-specifier<sub>opt</sub> template-name</i>
char
char16_t
char32_t
wchar_t
bool
short
int
long
signed
unsigned
float
double
void
<del>auto</del>
<i>decltype-specifier</i>
<ins><i>placeholder-type-specifier</i></ins>
<i>type-name</i>:
class-name
enum-name
typedef-name
simple-template-id
<i>decltype-specifier</i>:
decltype ( expression )
<del>decltype ( auto )</del>
<ins><i>placeholder-type-specifier</i>:</ins>
<ins><i>type-constraint</i><sub>opt</sub> auto</ins>
<ins><i>type-constraint</i><sub>opt</sub> decltype ( auto )</ins>
</code></pre></blockquote>
</blockquote>
<p>Modify paragraph 2 as follows.</p>
<blockquote class="std">
<p><del>The <i>simple-type-specifier</i> <code>auto</code></del><ins>A
<i>placeholder-type-specifier</i></ins> is a placeholder for a type to
be deduced (9.1.7.4).</p>
</blockquote>
<p>Add <i>placeholder-type-specifier</i>s to the table of
<i>simple-type-specifier</i>s and their meaning.</p>
<blockquote class="std">
<table>
<tr><td>Specifier(s)</td><td>Type</td></tr>
<tr><td><i>type-name</i></td><td>the type named</td></tr>
<tr><td><i>simple-template-id</i><td>the as defined in 12.2</td></tr>
<tr><td>...</td><td>...</td></tr>
<tr><td><code>void</code></td><td>“<code>void</code>”</td></tr>
<tr><td><del><code>auto</code></del><td><del>placeholder for a type to be deduced</del></td></tr>
<tr><td><del><code>decltype(auto)</code></del><td><del>placeholder for a type to be deduced</del></td></tr>
<tr><td><code>decltype(<i>expression</i>)</code><td>the type as described below</td></tr>
<tr><td><ins><i>placeholder-type-specifier</i></ins><td><ins>placeholder for a type to be deduced</ins></td></tr>
</table>
</blockquote>
<p>In [dcl.spec.auto, 9.1.7.4], modify and split paragraph 1 as follows.</p>
<blockquote class="std">
<p><del>The <code>auto</code> and <code>decltype(auto)</code>
<i>type-specifier</i>s are used to</del><ins>A <i>placeholder-type-specifier</i></ins>
designate<ins>s</ins> a placeholder type that will be replaced later by deduction
from an initializer.</p>
<p> <ins>A <i>placeholder-type-specifier</i> of the form <i>type-constraint</i><sub>opt</sub> <code>auto</code> can be used in the <i>decl-specifier-seq</i>
of a <i>parameter-declaration</i> of a function declaration or <i>lambda-expression</i> and signifies that the function is an
abbreviated function template (9.2.3.5) or the</ins><del>The <code>auto</code>
<i>type-specifier</i> is also used to introduce a function type having a
<i>trailing-return-type</i> or to signify that a</del> lambda is a generic
lambda (7.5.5).<del> The <code>auto</code> <i>type-specifier</i> is also used to introduce a
structured binding declaration (9.5).</del></p>
</blockquote>
<p>Modify (old) paragraph 3 as follows.</p>
<blockquote class="std">
<p>The type of a variable declared using <del><code>auto</code> or
<code>decltype(auto)</code></del><ins>a placeholder type</ins> is deduced
from its initializer. This use is allowed in an initializing declaration (9.3)
of a variable. <del><code>auto</code> or <code>decltype(auto)</code></del><ins>The
placeholder type</ins> shall appear as one of the
<i>decl-specifier</i>s in the <i>decl-specifier-seq</i> and the
<i>decl-specifier-seq</i> shall be followed by one or more declarators, each
of which shall be followed by a non-empty initializer. […]—<i>end example</i>]
<ins>The <code>auto</code> <i>type-specifier</i> can also be used to introduce a
structured binding declaration (9.5).</ins></p>
</blockquote>
<p>Modify (old) paragraph 5 as follows.</p>
<blockquote class="std">
<p>A program that uses <del><code>auto</code> or <code>decltype(auto)</code></del><ins>a
placeholder type</ins> in a context not explicitly allowed in this
subclause is ill-formed.</p>
</blockquote>
<p>In [dcl.type.auto.deduct, 9.1.7.4.1], modify the last sentence of paragraph 2 as follows.</p>
<blockquote class="std">
<p>[…] In the case of a return statement with no operand or with an operand of type
<code>void</code>, <code>T</code> shall be either
<ins><i>type-constraint</i><sub>opt</sub> </ins><code>decltype(auto)</code>or
<i>cv</i> <ins><i>type-constraint</i><sub>opt</sub> </ins><code>auto</code>.</p>
</blockquote>
<p>Modify paragraph 4 as follows.</p>
<blockquote class="std">
<p>If the <del>placeholder is the <code>auto</code>
<i>type-specifier</i></del><ins><i>placeholder-type-specifier</i> is of the form
<i>type-constraint</i><sub>opt</sub> <code>auto</code></ins>, the deduced type
<code>T′</code> replacing <code>T</code> is determined using the rules for
template argument deduction. Obtain <code>P</code> from <code>T</code> by
replacing the occurrences of <ins><i>type-constraint</i><sub>opt</sub> </ins><code>auto</code>
with either a new invented
type template parameter <code>U</code> or, if the initialization is copy-list-initialization,
with <code>std::initiali­zer_list<U></code>. […]
</p>
</blockquote>
<p>Modify paragraph 5 as follows.</p>
<blockquote class="std">
<p>If the <del>placeholder is the <code>decltype(auto)</code>
<i>type-specifier</i></del><ins><i>placeholder-type-specifier</i> is of the form
<i>type-constraint</i><sub>opt</sub> <code>decltype(auto)</code></ins>,
<code>T</code> shall be the placeholder alone. The type deduced
for <code>T</code> is deter­mined […]
</p>
</blockquote>
<p>Append a new paragraph as follows.</p>
<blockquote class="stdins">
<p>?. For a <i>placeholder-type-specifier</i> with a <i>type-constraint</i>,
if the type deduced for the placeholder does not satisfy its immediately-declared constraint ([temp, 12]),
the program is ill-formed.</p>
</blockquote>
<p>Add the following paragraphs to [dcl.fct, 9.2.3.5], after paragraph 16.</p>
<blockquote class="stdins">
<p>
?. An <i>abbreviated function template</i> is a function declaration whose
parameter-type-list includes one or more placeholders (9.1.7.4). An
abbreviated function template is equivalent to a function template (17.6.5)
whose <i>template-parameter-list</i> includes one invented type
<i>template-parameter</i> for each occurrence of a placeholder type in the
<i>decl-specifier-seq</i> of a <i>parameter-declaration</i> in the
function’s parameter-type-list, in order of
appearance.
For a <i>placeholder-type-specifier</i> of the form <code>auto</code>, the
invented parameter is an unconstrained <i>type-parameter</i>.
For a <i>placeholder-type-specifier</i> of the form <i>type-constraint</i> <code>auto</code>,
the invented parameter is a <i>type-parameter</i> with that <i>type-constraint</i>.
The invented type <i>template-parameter</i> is a template parameter pack if
the corresponding parameter-declaration declares a function parameter pack (9.2.3.5).
If the placeholder contains <code>decltype(auto)</code>, the program is ill-formed.
The adjusted function parameters of an abbreviated function template are
derived from the <i>parameter-declaration-clause</i> by replacing each
occurrence of a placeholder with the name of the corresponding invented
<i>template-parameter</i>.</p>
<p>[<i>Example</i>:</p>
<blockquote><pre><code>template<typename T> concept C1 = /* ... */;
template<typename T> concept C2 = /* ... */;
template<typename... Ts> concept C4 = /* ... */;
void g1(const C1 auto*, C2 auto&);
void g3(C1 auto&...);
void g5(C4 auto...);
void g7(C4 auto);
</code></pre></blockquote>
<p>These declarations are functionally equivalent (but not equivalent) to the following declarations.</p>
<blockquote><pre><code>template<C1 T, C2 U> void g1(const T*, U&);
template<C1... Ts> void g3(Ts&...);
template<C4... Ts> void g5(Ts...);
template<C4 T> void g7(T);
</code></pre></blockquote>
<p>Abbreviated function templates can be specialized like all function templates.</p>
<blockquote><pre><code>template<> void g1<int>(const int*, const double&); // OK, specialization of g1<int, const double>
</code></pre></blockquote>
<p>—<i>end example</i>]</p>
<p>
?. An abbreviated function template can have a <i>template-head</i>.
The invented <i>template-parameter</i>s are appended to the
<i>template-parameter-list</i> after the explicitly declared
<i>template-parameter</i>s.
<p>[<i>Example</i>:</p>
<blockquote><pre><code>template<typename> concept C = /* ... */;
template <typename T, C U>
void g(T x, U y, C auto z);</code></pre></blockquote>
<p>This is functionally equivalent to each of the following two declarations.</p>
<blockquote><pre><code>template<typename T, C U, C W>
void g(T x, U y, W z);
template<typename T, typename U, typename W>
requires C<U> && C<W>
void g(T x, U y, W z);</code></pre></blockquote>
<p>—<i>end example</i>]</p>
<p>
?. A function declaration at block scope shall not declare
an abbreviated function template.
</p>
</blockquote>
<h3 id="wordingtemp">Changes in [temp]</h3>
<p>Add to the grammar in [temp, 12] the following.</p>
<blockquote class="std">
<blockquote><pre><code><i>concept-name</i>:
<i>identifier</i>
<ins><i>type-constraint</i>:</ins>
<ins><i>nested-name-specifier<sub>opt</sub> concept-name</i></ins>
<ins><i>nested-name-specifier<sub>opt</sub> concept-name</i> < <i>template-argument-list<sub>opt</sub></i> ></ins>
</code></pre></blockquote>
</blockquote>
<p>Append a new paragraph as follows.</p>
<blockquote class="stdins">
<p>?. A <i>type-constraint</i>
<code>Q</code> that designates a concept <code>C</code> can be used to constrain a contextually-determined type or template type parameter pack <code>T</code> with a <i>constraint-expression</i> <code>E</code> defined as follows.
If <code>Q</code> is of the form <code>C<A1, ..., An></code>,
then let <code>E′</code> be <code>C<T, A1, ..., An></code>. Otherwise, let <code>E′</code> be <code>C<T></code>.
If <code>T</code> is not a pack, then <code>E</code> is <code>E′</code>, otherwise
<code>E</code> is <code>(E′ && ...)</code>.
This is called the <em>immediately-declared constraint</em> of <code>T</code>.
The concept designated by a <i>type-constraint</i> shall be
a type concept (12.6.8).</p>
</blockquote>
<p>
Change [temp.param, 12.1] paragraph 1 to remove the grammar for
<i>constrained-parameter</i> and to enhance the grammar of
<i>type-parameter</i>.
</p>
<p><em>Editorial note:</em> No further appearances of “<i>qualified-concept-name</i>”
should remain in the working draft after application of P1084R2 and P1141R2 (this paper).</p>
<blockquote class="std">
<blockquote><pre><code><i>template-parameter</i>:
<i>type-parameter</i>
<i>parameter-declaration</i>
<del><i>constrained-parameter</i></del>
<i>type-parameter</i>:
<i>type-parameter-key</i> ...<sub>opt</sub> <i>identifier</i><sub>opt</sub>
<i>type-parameter-key identifier</i><sub>opt</sub> = <i>type-id</i>
<ins><i>type-constraint</i> ...<sub>opt</sub> <i>identifier</i><sub>opt</sub></ins>
<ins><i>type-constraint identifier</i><sub>opt</sub> = <i>type-id</i></ins>
<i>template-head type-parameter-key</i> ...<sub>opt</sub> <i>identifier</i><sub>opt</sub>
<i>template-head type-parameter-key identifier</i><sub>opt</sub> = <i>id-expression</i>
<i>type-parameter-key</i>:
class
typename
<del><i>constrained-parameter</i>:</del>
<del><i>qualified-concept-name</i> ... <i>identifier<sub>opt</sub></i></del>
<del><i>qualified-concept-name identifier<sub>opt</sub> default-template-argument<sub>opt</sub></i></del>
<del><i>qualified-concept-name</i>:</del>
<del><i>nested-name-specifier<sub>opt</sub> concept-name nested-name-specifier<sub>opt</sub>partial-concept-id</i></del>
<del><i>partial-concept-id</i>:</del>
<del><i>concept-name</i> < <i>template-argument-list<sub>opt</sub></i> ></del></code></pre>
</blockquote>
</blockquote>
<p>Change [12.1, temp.param] paragraph 9 as follows.</p>
<blockquote class="std">
<p>
<del>A <i>partial-concept-id</i> is a <i>concept-name</i>
followed by a sequence of <i>template-arguments</i>.
These template arguments are used to form a <i>constraint-expression</i>
as described below.</del><ins>A <i>type-parameter</i> that starts with a
<i>type-constraint</i> introduces the immediately-declared constraint
of the parameter.</ins>
</p>
</blockquote>
<p>Delete [12.1, temp.param] paragraph 10.</p>
<blockquote class="stddel">
<p>
<del>A <i>constrained-parameter</i> declares a template parameter whose
kind (type, non-type, template) and type
match that of the prototype parameter (12.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.</del>
</p>
<ul class="del">
<li><del>If <code>X</code> is a type <i>template-parameter</i>,
the declared parameter is a type <i>template-parameter</i>.</del></li>
<li><del>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>.</del></li>
<li><del>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.</del></li>
<li><del>If the <i>qualified-concept-name</i> is followed by an ellipsis,
then the declared parameter is a template parameter pack (temp.variadic, 12.6.3).</del></li>
</ul>
<p><del>[<i>Example</i>:</del></p>
<blockquote><pre><code><del>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</del>
</code>
</pre>
</blockquote>
<p><del>—<i>end example</i>]</del></p>
</blockquote>
<p>In [12.1, temp.param], delete the normative wording of (old)
paragraph 11 and merge the (modified) example into paragraph 9 as follows.</p>
<p><em>Editorial note:</em> This change effects the design change of Part 4 (changing
the meaning of <code>...</code>). The new pack expansion behaviour is subsumed by
the “immediately-declared constraint” facility.</p>
<blockquote class="std">
<p>
<del>A <i>constrained-parameter</i> <i>constraint-expression</i>.
The expression is derived from
the <i>qualified-concept-name</i> <code>Q</code>
in the <i>constrained-parameter</i>, its designated concept <code>C</code>,
and the declared template parameter <code>P</code>.</del>
</p>
<ul>
<li><del>First, a template argument
<code>A</code> is invented from <code>P</code>.
If <code>P</code> declares a template parameter pack ([temp.variadic])
and <code>C</code> is a variadic concept ([temp.concept]), then <code>A</code>
is the pack expansion <code>P...</code>. Otherwise, <code>A</code> is
the <i>id-expression</i> <code>P</code>.</del></li>
<li><del>Then, an <i>id-expression</i> <code>E</code>
is formed as follows.
If <code>Q</code> is a <i>concept-name</i>, then
<code>E</code> is <code>C<A></code>.
Otherwise, <code>Q</code> is a <i>partial-concept-id</i> of the
form <code>C<A1, A2, ..., An></code>,
and <code>E</code> is <code>C<A, A1, A2, ..., An></code>.
</del></li>
<li><del>Finally, if <code>P</code> declares a template parameter pack and <code>C</code>
is not a variadic concept, <code>E</code> is adjusted to be the
<i>fold-expression</i> <code>(E && ...)</code> (7.5.6).</del></li>
</ul>
<p><del><code>E</code> is the introduced <i>constraint-expression</i>.</del></p>
<p>[<i>Example</i>:</p>
<blockquote><pre><code>template<typename T> concept C1 = true;
template<typename... Ts> concept C2 = true;
template<typename T, typename U> concept C3 = true;
template<C1 T> struct s1; // associates C1<T>
template<C1... T> struct s2; // associates (C1<T> && ...)
template<C2... T> struct s3; // associates <del>C2<T...></del><ins>(C2<T> && ...)</ins>
template<C3<int> T> struct s4; // associates C3<T, int>
<ins>template<C3<int>... T> struct s5; // associates (C3<T, int> && ...)</ins></code></pre></blockquote>
<p>—<i>end example</i>]</p>
</blockquote>
<p>Insert a new paragraph after (old) paragraph 11.</p>
<blockquote class="stdins">
<p>?. A non-type template parameter declared with a type that contains
a placeholder type with a <i>type-constraint</i> introduces the
immediately-declared constraint of the invented type corresponding
to the placeholder.</p>
</blockquote>
<p>Delete (old) paragraph 13.</p>
<blockquote class="stddel">
<p><del>The default <i>template-argument</i> of a <i>constrained-parameter</i>
shall match the kind (type, non-type, template) of the declared template parameter.
[<i>Example</i>: […] —<i>end example</i>]</del></p></blockquote>