Skip to content

Commit 312c209

Browse files
committed
Merge 2018-03 CWG Motion 7
2 parents 69a067e + 35b73d1 commit 312c209

File tree

4 files changed

+109
-63
lines changed

4 files changed

+109
-63
lines changed

source/basic.tex

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@
3131
structured binding,
3232
function, enumerator, type,
3333
class member, bit-field, template, template specialization, namespace, or
34-
parameter pack.
34+
pack.
3535

3636
\pnum
3737
A \defn{name} is a use of an \grammarterm{identifier}\iref{lex.name},

source/declarators.tex

Lines changed: 10 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1633,14 +1633,14 @@
16331633
\pnum
16341634
A \grammarterm{declarator-id} or \grammarterm{abstract-declarator}
16351635
containing an ellipsis shall only
1636-
be used in a \grammarterm{parameter-declaration}. Such a
1637-
\grammarterm{parameter-declaration} is a parameter
1638-
pack\iref{temp.variadic}. When it is part of a
1639-
\grammarterm{parameter-declaration-clause}, the parameter pack is a
1640-
function parameter pack\iref{temp.variadic}. \begin{note}
1636+
be used in a \grammarterm{parameter-declaration}.
1637+
When it is part of a
1638+
\grammarterm{parameter-declaration-clause},
1639+
the \grammarterm{parameter-declaration} declares a
1640+
function parameter pack\iref{temp.variadic}.
16411641
Otherwise, the \grammarterm{parameter-declaration} is part of a
1642-
\grammarterm{template-parameter-list} and the parameter pack is a
1643-
template parameter pack; see~\ref{temp.param}. \end{note}
1642+
\grammarterm{template-parameter-list} and declares a
1643+
template parameter pack; see~\ref{temp.param}.
16441644
A function parameter pack is a pack expansion\iref{temp.variadic}.
16451645
\begin{example}
16461646

@@ -1713,7 +1713,9 @@
17131713
\grammarterm{template-parameter}\iref{temp.param};
17141714
in the latter case, the \grammarterm{initializer-clause} shall be an
17151715
\grammarterm{assignment-expression}.
1716-
A default argument shall not be specified for a parameter pack.
1716+
A default argument shall not be specified for
1717+
a template parameter pack or
1718+
a function parameter pack.
17171719
If it is specified in a
17181720
\grammarterm{parameter-declaration-clause},
17191721
it shall not occur within a

source/expressions.tex

Lines changed: 25 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -1229,14 +1229,15 @@
12291229

12301230
\begin{bnf}
12311231
\nontermdef{capture-list}\br
1232-
capture \opt{\terminal{...}}\br
1233-
capture-list \terminal{,} capture \opt{\terminal{...}}
1232+
capture\br
1233+
capture-list \terminal{,} capture
12341234
\end{bnf}
12351235

12361236
\begin{bnf}
12371237
\nontermdef{capture}\br
1238-
simple-capture\br
1239-
init-capture
1238+
simple-capture \opt{\terminal{...}}\br
1239+
% FIXME: This is wrong. The ... should go after the &.
1240+
\opt{\terminal{...}} init-capture
12401241
\end{bnf}
12411242

12421243
\begin{bnf}
@@ -1642,14 +1643,22 @@
16421643

16431644
\pnum
16441645
A \grammarterm{simple-capture} followed by an ellipsis is a pack
1645-
expansion\iref{temp.variadic}. An \grammarterm{init-capture} followed by an
1646-
ellipsis is ill-formed.
1646+
expansion\iref{temp.variadic}.
1647+
\indextext{init-capture pack@\fakegrammarterm{init-capture} pack}%
1648+
An \grammarterm{init-capture} preceded by an ellipsis is a pack
1649+
expansion that introduces an
1650+
\grammarterm{init-capture} pack\iref{temp.variadic}
1651+
whose declarative region is
1652+
the \grammarterm{lambda-expression}'s \grammarterm{compound-statement}.
16471653
\begin{example}
16481654
\begin{codeblock}
16491655
template<class... Args>
16501656
void f(Args... args) {
16511657
auto lm = [&, args...] { return g(args...); };
16521658
lm();
1659+
1660+
auto lm2 = [...xs=std::move(args)] { return g(xs...); };
1661+
lm2();
16531662
}
16541663
\end{codeblock}
16551664
\end{example}%
@@ -1659,7 +1668,7 @@
16591668
\indextext{expression!fold|(}
16601669

16611670
\pnum
1662-
A fold expression performs a fold of a template parameter
1671+
A fold expression performs a fold of a
16631672
pack\iref{temp.variadic} over a binary operator.
16641673

16651674
\begin{bnf}
@@ -1692,7 +1701,7 @@
16921701
are collectively called \defnx{unary folds}{unary fold}.
16931702
In a unary fold,
16941703
the \grammarterm{cast-expression}
1695-
shall contain an unexpanded parameter pack\iref{temp.variadic}.
1704+
shall contain an unexpanded pack\iref{temp.variadic}.
16961705

16971706
\pnum
16981707
\indextext{fold!binary}%
@@ -1704,13 +1713,13 @@
17041713
\placeholder{op1} and \placeholder{op2}
17051714
shall be the same \grammarterm{fold-operator},
17061715
and either \tcode{e1}
1707-
shall contain an unexpanded parameter pack
1716+
shall contain an unexpanded pack
17081717
or \tcode{e2}
1709-
shall contain an unexpanded parameter pack,
1718+
shall contain an unexpanded pack,
17101719
but not both.
1711-
If \tcode{e2} contains an unexpanded parameter pack,
1720+
If \tcode{e2} contains an unexpanded pack,
17121721
the expression is called a \defn{binary left fold}.
1713-
If \tcode{e1} contains an unexpanded parameter pack,
1722+
If \tcode{e1} contains an unexpanded pack,
17141723
the expression is called a \defn{binary right fold}.
17151724
\begin{example}
17161725
\begin{codeblock}
@@ -1721,7 +1730,7 @@
17211730

17221731
template<typename ...Args>
17231732
bool f(Args ...args) {
1724-
return (args + ... + args); // error: both operands contain unexpanded parameter packs
1733+
return (args + ... + args); // error: both operands contain unexpanded packs
17251734
}
17261735
\end{codeblock}
17271736
\end{example}
@@ -3639,9 +3648,9 @@
36393648
is applied.
36403649

36413650
\pnum
3642-
The identifier in a \tcode{sizeof...} expression shall name a parameter
3643-
pack. The \tcode{sizeof...} operator yields the number of arguments
3644-
provided for the parameter pack \grammarterm{identifier}.
3651+
The identifier in a \tcode{sizeof...} expression shall name a
3652+
pack. The \tcode{sizeof...} operator yields the number of elements
3653+
in the pack\iref{temp.variadic}.
36453654
A \tcode{sizeof...} expression is a pack expansion\iref{temp.variadic}.
36463655
\begin{example}
36473656

source/templates.tex

Lines changed: 73 additions & 38 deletions
Original file line numberDiff line numberDiff line change
@@ -735,15 +735,15 @@
735735
If a \grammarterm{template-parameter} is a
736736
\grammarterm{type-parameter} with an ellipsis prior to its
737737
optional \grammarterm{identifier} or is a
738-
\grammarterm{parameter-declaration} that declares a parameter
738+
\grammarterm{parameter-declaration} that declares a
739739
pack\iref{dcl.fct}, then the \grammarterm{template-parameter}
740740
is a template parameter pack\iref{temp.variadic}.
741741
A template parameter pack that is a \grammarterm{parameter-declaration} whose type
742-
contains one or more unexpanded parameter packs is a pack expansion. Similarly,
742+
contains one or more unexpanded packs is a pack expansion. Similarly,
743743
a template parameter pack that is a \grammarterm{type-parameter} with a
744744
\grammarterm{template-parameter-list} containing one or more unexpanded
745-
parameter packs is a pack expansion. A template parameter pack that is a pack
746-
expansion shall not expand a parameter pack declared in the same
745+
packs is a pack expansion. A template parameter pack that is a pack
746+
expansion shall not expand a template parameter pack declared in the same
747747
\grammarterm{template-parameter-list}.
748748
\begin{example}
749749
\begin{codeblock}
@@ -1418,7 +1418,7 @@
14181418
\pnum A \grammarterm{template-argument} matches a template
14191419
\grammarterm{template-parameter} \tcode{P} when
14201420
\tcode{P} is at least as specialized as the \grammarterm{template-argument} \tcode{A}.
1421-
If \tcode{P} contains a parameter pack, then \tcode{A} also matches \tcode{P}
1421+
If \tcode{P} contains a template parameter pack, then \tcode{A} also matches \tcode{P}
14221422
if each of \tcode{A}'s template parameters
14231423
matches the corresponding template parameter in the
14241424
\grammarterm{template-head} of \tcode{P}.
@@ -1514,7 +1514,7 @@
15141514
for each template parameter \tcode{PP}
15151515
in the \grammarterm{template-head} of the function template,
15161516
a corresponding template argument \tcode{AA} is formed.
1517-
If \tcode{PP} declares a parameter pack,
1517+
If \tcode{PP} declares a template parameter pack,
15181518
then \tcode{AA} is the pack expansion \tcode{PP...}\iref{temp.variadic};
15191519
otherwise, \tcode{AA} is the \grammarterm{id-expression} \tcode{PP}.
15201520
\end{itemize}
@@ -2531,15 +2531,40 @@
25312531
\begin{codeblock}
25322532
template<class ... Types> void f(Types ... args);
25332533

2534-
f(); // OK: \tcode{args} contains no arguments
2535-
f(1); // OK: \tcode{args} contains one argument: \tcode{int}
2536-
f(2, 1.0); // OK: \tcode{args} contains two arguments: \tcode{int} and \tcode{double}
2534+
f(); // \tcode{args} contains no arguments
2535+
f(1); // \tcode{args} contains one argument: \tcode{int}
2536+
f(2, 1.0); // \tcode{args} contains two arguments: \tcode{int} and \tcode{double}
25372537
\end{codeblock}
25382538
\end{example}
25392539

25402540
\pnum
2541-
A \defn{parameter pack} is either a template parameter
2542-
pack or a function parameter pack.
2541+
An \defnx{\grammarterm{init-capture} pack}{init-capture pack@\fakegrammarterm{init-capture} pack}
2542+
is a lambda capture that introduces an \grammarterm{init-capture}
2543+
for each of the elements in the pack expansion of its \grammarterm{initializer}.
2544+
\begin{example}
2545+
\begin{codeblock}
2546+
template <typename... Args>
2547+
void foo(Args... args) {
2548+
[...xs=args]{
2549+
bar(xs...); // \tcode{xs} is an \grammarterm{init-capture} pack
2550+
};
2551+
}
2552+
2553+
foo(); // \tcode{xs} contains zero \grammarterm{init-captures}
2554+
foo(1); // \tcode{xs} contains one \grammarterm{init-capture}
2555+
\end{codeblock}
2556+
\end{example}
2557+
2558+
\pnum
2559+
A \defn{pack} is
2560+
a template parameter pack,
2561+
a function parameter pack,
2562+
or an \grammarterm{init-capture} pack.
2563+
The number of elements of a template parameter pack
2564+
or a function parameter pack
2565+
is the number of arguments provided for the parameter pack.
2566+
The number of elements of an \grammarterm{init-capture} pack
2567+
is the number of elements in the pack expansion of its \grammarterm{initializer}.
25432568

25442569
\pnum
25452570
\indextext{pattern|see{pack expansion, pattern}}%
@@ -2595,7 +2620,7 @@
25952620

25962621
\item In a \grammarterm{fold-expression}\iref{expr.prim.fold};
25972622
the pattern is the \grammarterm{cast-expression}
2598-
that contains an unexpanded parameter pack.
2623+
that contains an unexpanded pack.
25992624
\end{itemize}
26002625

26012626
\begin{example}
@@ -2608,20 +2633,20 @@
26082633
\end{example}
26092634

26102635
\pnum
2611-
For the purpose of determining whether a parameter pack satisfies a rule
2612-
regarding entities other than parameter packs, the parameter pack is
2636+
For the purpose of determining whether a pack satisfies a rule
2637+
regarding entities other than packs, the pack is
26132638
considered to be the entity that would result from an instantiation of
26142639
the pattern in which it appears.
26152640

26162641
\pnum
2617-
A parameter pack whose name appears within the pattern of a pack
2642+
A pack whose name appears within the pattern of a pack
26182643
expansion is expanded by that pack expansion. An appearance of the name of
2619-
a parameter pack is only expanded by the innermost enclosing pack expansion.
2620-
The pattern of a pack expansion shall name one or more parameter packs that
2621-
are not expanded by a nested pack expansion; such parameter packs are called
2622-
\defnx{unexpanded parameter packs}{parameter pack!unexpanded} in the pattern. All of the parameter packs expanded
2644+
a pack is only expanded by the innermost enclosing pack expansion.
2645+
The pattern of a pack expansion shall name one or more packs that
2646+
are not expanded by a nested pack expansion; such packs are called
2647+
\defnx{unexpanded packs}{pack!unexpanded} in the pattern. All of the packs expanded
26232648
by a pack expansion shall have the same number of arguments specified. An
2624-
appearance of a name of a parameter pack that is not expanded is
2649+
appearance of a name of a pack that is not expanded is
26252650
ill-formed. \begin{example}
26262651

26272652
\begin{codeblock}
@@ -2642,8 +2667,8 @@
26422667
template<class ... Args>
26432668
void g(Args ... args) { // OK: \tcode{Args} is expanded by the function parameter pack \tcode{args}
26442669
f(const_cast<const Args*>(&args)...); // OK: ``\tcode{Args}'' and ``\tcode{args}'' are expanded
2645-
f(5 ...); // error: pattern does not contain any parameter packs
2646-
f(args); // error: parameter pack ``\tcode{args}'' is not expanded
2670+
f(5 ...); // error: pattern does not contain any packs
2671+
f(args); // error: pack ``\tcode{args}'' is not expanded
26472672
f(h(args ...) + args ...); // OK: first ``\tcode{args}'' expanded within \tcode{h},
26482673
// second ``\tcode{args}'' expanded within \tcode{f}
26492674
}
@@ -2656,30 +2681,40 @@
26562681
that is neither a \tcode{sizeof...} expression
26572682
nor a \grammarterm{fold-expression}
26582683
produces a
2659-
list
2660-
$\mathtt{E}_1, \mathtt{E}_2, \dotsc, \mathtt{E}_N$,
2684+
list of elements
2685+
$\mathtt{E}_1,$ $\mathtt{E}_2,$ $\cdots,$ $\mathtt{E}_N$,
26612686
where
26622687
$N$ is the number of elements in the pack expansion parameters. Each
26632688
$\mathtt{E}_i$ is generated by instantiating the pattern and
2664-
replacing each pack expansion parameter with its $i$th element.
2689+
replacing each pack expansion parameter with its $i^{\textrm{th}}$ element.
26652690
Such an element, in the context of the instantiation, is interpreted as
26662691
follows:
26672692

26682693
\begin{itemize}
26692694
\item
26702695
if the pack is a template parameter pack, the element is a template
26712696
parameter\iref{temp.param} of the corresponding kind (type or
2672-
non-type) designating the type or value from the template
2673-
argument; otherwise,
2697+
non-type) designating the $i^{\textrm{th}}$
2698+
corresponding type or value template argument;
26742699

26752700
\item
26762701
if the pack is a function parameter pack, the element is an
26772702
\grammarterm{id-expression}
2678-
designating the function parameter that resulted from
2679-
the instantiation of the pattern where the pack is declared.
2703+
designating the $i^{\textrm{th}}$ function parameter
2704+
that resulted from instantiation of
2705+
the function parameter pack declaration;
2706+
otherwise
2707+
2708+
\item
2709+
if the pack is an \grammarterm{init-capture} pack,
2710+
the element is an \grammarterm{id-expression}
2711+
designating the variable introduced by
2712+
the $i^{\textrm{th}}$ \grammarterm{init-capture}
2713+
that resulted from instantiation of
2714+
the \grammarterm{init-capture} pack.
26802715
\end{itemize}
26812716

2682-
All of the $\mathtt{E}_i$ become elements in the enclosing list.
2717+
All of the $\mathtt{E}_i$ become items in the enclosing list.
26832718
\begin{note} The variety of list varies with the context:
26842719
\grammarterm{expression-list},
26852720
\grammarterm{base-specifier-list},
@@ -2702,7 +2737,7 @@
27022737

27032738
\pnum
27042739
The instantiation of a \tcode{sizeof...} expression\iref{expr.sizeof} produces
2705-
an integral constant containing the number of elements in the parameter pack
2740+
an integral constant containing the number of elements in the pack
27062741
it expands.
27072742

27082743
\pnum
@@ -2745,7 +2780,7 @@
27452780
For a binary fold-expression,
27462781
$\mathtt{E}$ is generated
27472782
by instantiating the \grammarterm{cast-expression}
2748-
that did not contain an unexpanded parameter pack.
2783+
that did not contain an unexpanded pack.
27492784
\begin{example}
27502785
\begin{codeblock}
27512786
template<typename ...Args>
@@ -2766,7 +2801,7 @@
27662801
\begin{floattable}{Value of folding empty sequences}{tab:fold.empty}
27672802
{ll}
27682803
\topline
2769-
\lhdr{Operator} & \rhdr{Value when parameter pack is empty} \\
2804+
\lhdr{Operator} & \rhdr{Value when pack is empty} \\
27702805
\capsep
27712806
\tcode{\&\&} & \tcode{true} \\
27722807
\tcode{||} & \tcode{false} \\
@@ -3152,7 +3187,7 @@
31523187
The template parameter list of a specialization shall not contain default
31533188
template argument values.\footnote{There is no way in which they could be used.}
31543189
\item
3155-
An argument shall not contain an unexpanded parameter pack. If
3190+
An argument shall not contain an unexpanded pack. If
31563191
an argument is a pack expansion\iref{temp.variadic}, it shall be
31573192
the last argument in the template argument list.
31583193
\end{itemize}
@@ -4739,9 +4774,9 @@
47394774
the partial specialization enclosed in
47404775
\tcode{<>} (or an equivalent template alias specialization).
47414776
If the \textit{n}th template parameter is
4742-
a parameter pack, the \textit{n}th template argument is a pack
4777+
a template parameter pack, the \textit{n}th template argument is a pack
47434778
expansion\iref{temp.variadic} whose pattern is the name of
4744-
the parameter pack.
4779+
the template parameter pack.
47454780
\end{itemize}
47464781

47474782
\pnum
@@ -7209,7 +7244,7 @@
72097244
\begin{note}
72107245
Type deduction may fail for the following reasons:
72117246
\begin{itemize}
7212-
\item Attempting to instantiate a pack expansion containing multiple parameter packs of differing lengths.
7247+
\item Attempting to instantiate a pack expansion containing multiple packs of differing lengths.
72137248
\item
72147249
Attempting to create an array with an element type that is \tcode{void}, a
72157250
function type, a reference type, or an abstract class type, or attempting
@@ -7391,7 +7426,7 @@
73917426
Each deduction deduces template arguments for subsequent positions in
73927427
the template parameter packs expanded by the function parameter pack.
73937428
When a function parameter pack appears in a non-deduced
7394-
context\iref{temp.deduct.type}, the type of that parameter pack is
7429+
context\iref{temp.deduct.type}, the type of that pack is
73957430
never deduced.
73967431
\begin{example}
73977432
\begin{codeblock}

0 commit comments

Comments
 (0)