<!DOCTYPE HTML PUBLIC "-//IETF//DTD HTML//EN">
<html>
<style>
.ins {background-color:#A0FFA0;font-weight: bold}
.del {background-color:#FFA0A0;text-decoration:line-through}
</style>
<title>Variadic Templates: Wording for Core Issues 778, 1182, and 1183.</title>
<body>

Document number: N3270=11-0040<br>
Author: Doug Gregor<br>
Date: 2011-03-22<br>
Reply-To: doug.gregor@gmail.com

<h1>Variadic Templates: Wording for Core Issues 778, 1182, and 1183.</h1>

<p>This paper addresses the following three issues with variadic templates:
<ul>
  <li>778. Template parameter packs in non-type template parameters.</li>
  <li>1182. Incorrect description of pack expansion syntax.</li>
  <li>1183. Expansion of parameter packs in declarators.</li>
</ul>

<p><b>Proposed resolution</b>: </p>

<OL><LI><P>Change 5.3.3 [expr.sizeof] paragraph 5 as follows:</P></LI>

<BLOCKQUOTE>

The identifier in a <TT>sizeof...</TT> expression shall name a
parameter pack. The <TT>sizeof...</TT> operator yields the number of
arguments provided for the parameter pack <I>identifier</I>. <span class="del">The
parameter pack is expanded (14.5.3 [temp.variadic]) by the
<TT>sizeof...</TT> operator</span> <span class="ins">A <TT>sizeof...</TT> expression
is a pack expansion (14.5.3 [temp.variadic])</span>. [<I>Example:</I>...

</BLOCKQUOTE>

<LI><P>Change 8.3.5 [dcl.fct] paragraph 13 as follows:</P></LI>

<BLOCKQUOTE>

A <I>declarator-id</I> or <I>abstract-declarator</I> containing an
ellipsis shall only be used in a <I>parameter-declaration</I>.  Such a
<I>parameter-declaration</I> is a parameter pack (14.5.3 [temp.variadic]). When it is part of a
<I>parameter-declaration-clause</I>, the parameter pack is a function
parameter pack (14.5.3 [temp.variadic]).  [<I>Note:</I>
Otherwise, the <I>parameter-declaration</I> is part of a
<I>template-parameter-list</I> and the parameter pack is a template
parameter pack; see 14.1 [temp.param].  &#8212;<I>end
note</I>] <span class="del">The type <TT>T</TT> of the <I>declarator-id</I> of the
function parameter pack shall contain a template parameter pack; each
template parameter pack in <TT>T</TT> is expanded by the function
parameter pack</span> <span class="ins">A function parameter pack is a pack
expansion (14.5.3 [temp.variadic])</span>. [<I>Example:</I>...

</BLOCKQUOTE>

<LI><P>Change 14.1 [temp.param] paragraph 15 as follows:</P></LI>

<BLOCKQUOTE>

<P>If a <I>template-parameter</I> is a <I>type-parameter</I> with an
ellipsis prior to its optional <I>identifier</I> or is a
<I>parameter-declaration</I> that declares a parameter pack
(8.3.5 [dcl.fct]), then the <I>template-parameter</I> is a
template parameter pack (14.5.3 [temp.variadic]). <span class="ins">A template
parameter pack that is a <I>parameter-declaration</I> whose type
contains one or more unexpanded parameter packs is a pack
expansion. Similarly, a template parameter pack that is a
<I>type-parameter</I> with a <I>template-parameter-list</I> containing
one or more unexpanded parameter packs is a pack expansion. A template parameter pack that is a pack expansion shall not expand a parameter pack declared in the same <i>template-parameter-list</i>.</span>
[<I>Example:</I></P>

<PRE>
  template &lt;class ...Types&gt; class Tuple; <i>// <tt>Types</tt> is a template type parameter pack <span class="ins">but not a pack expansion</span></i>
  template &lt;class T, int ...Dims&gt; struct multi_array; // <i><tt>Dims</tt> is a non-type template parameter pack <span class="ins">but not a pack expansion</span></i>
<span class="ins">  template&lt;class ...T&gt; struct value_holder {</span>
<span class="ins">    template&lt;T ...Values&gt; apply { }; <i>// <tt>Values</tt> is a non-type template parameter pack and a pack expansion</i></span>
<span class="ins">  };</span>
<span class="ins">  template &lt;class ...T, T ...Values&gt; struct static_array; <i>// Error: <tt>Values</tt> expands template type parameter pack <tt>T</tt> within the same template parameter list</span></i>
</PRE>

</BLOCKQUOTE>

<LI><P>Change 14.5.3 [temp.variadic] paragraphs 4-6 and add a new
paragraph 7 as follows:</P></LI>

<BLOCKQUOTE>

<P>A <I>pack expansion</I> <span class="del">is a sequence of tokens that names one
or more parameter packs, followed by an ellipsis.  The sequence of
tokens is called the <I>pattern of the expansion</I>; its syntax</span>
<span class="ins">consists of a <I>pattern</I> and an ellipsis, the instantiation
of which produces zero or more instantiations of the pattern in a list
(described below).  The form of the pattern</span> depends on the
context in which the expansion occurs. Pack expansions can occur in
the following contexts:</P>

<UL><LI><P><span class="ins">In a function parameter pack (8.3.5 [dcl.fct]);
the pattern is the <I>parameter-declaration</I> without the
ellipsis.</span></P></LI>

<LI><P><span class="ins">In a template parameter pack that is a pack expansion
(14.1 [temp.param]):</span></P>

<UL><LI><P><span class="ins">if the template parameter pack is a
<I>parameter-declaration</I>; the pattern is the
<I>parameter-declaration</I> without the ellipsis,</span></P></LI>

<LI><P><span class="ins">if the template parameter pack is a <I>type-parameter</I>
with a <I>template-parameter-list</I>; the pattern is the corresponding
<I>type-parameter</I> without the ellipsis.</span></P></LI>

</UL>

</LI>

<LI><P>...</P></LI>

<LI><P><span class="ins">In a <TT>sizeof...</TT> expression (5.3.3 [expr.sizeof]),
the pattern is an <I>identifier</I>.</span></P></LI>

</UL>

<P>[<I>Example:...</I></P>

<P>A parameter pack whose name appears within the pattern of a pack
expansion is expanded by that pack expansion.  An appearance of the
name of a parameter pack is only expanded by the innermost enclosing
pack expansion.  The pattern of a pack expansion shall name one or
more parameter packs that are not expanded by a nested pack
expansion<span class="ins">; such parameter packs are called
<I>unexpanded</I> parameter packs in the pattern</span>. All of the
parameter packs expanded...</P>

<PRE>
  ...
  void g(Args ... args) {  <span class="ins">//<i> OK: Args is expanded by the function parameter pack args</i></span>
  ...
</PRE>

<P>The instantiation of <span class="del">an</span> <span class="ins">a pack</span> expansion
<span class="ins">that is not a <TT>sizeof...</TT> expression</span> produces a
list...</P>

<P><span class="ins">The instantiation of a <TT>sizeof...</TT> expression
(5.3.3 [expr.sizeof]) produces an integral constant containing
the number of elements in the parameter pack it expands.</span></P>

</BLOCKQUOTE>

</OL>

</body>
</html>
 