<HTML>
<HEAD>
<meta http-equiv="Content-Type" content="text/html; charset=us-ascii">
<TITLE>
    CWG Issue 1662</TITLE>
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<STYLE TYPE="text/css">
  INS { text-decoration:none; font-weight:bold; background-color:#A0FFA0 }
  .INS { text-decoration:none; background-color:#D0FFD0 }
  DEL { text-decoration:line-through; background-color:#FFA0A0 }
  .DEL { text-decoration:line-through; background-color: #FFD0D0 }
  @media (prefers-color-scheme: dark) {
    HTML { background-color:#202020; color:#f0f0f0; }
    A { color:#5bc0ff; }
    A:visited { color:#c6a8ff; }
    A:hover, a:focus { color:#afd7ff; }
    INS { background-color:#033a16; color:#aff5b4; }
    .INS { background-color: #033a16; }
    DEL { background-color:#67060c; color:#ffdcd7; }
    .DEL { background-color:#67060c; }
  }
  SPAN.cmnt { font-family:Times; font-style:italic }
</STYLE>
</HEAD>
<BODY>
<P><EM>This is an unofficial snapshot of the ISO/IEC JTC1 SC22 WG21
  Core Issues List revision 118b.
  See http://www.open-std.org/jtc1/sc22/wg21/ for the official
  list.</EM></P>
<P>2025-09-28</P>
<HR>
<A NAME="1662"></A><H4>1662.
  
Capturing function parameter packs
</H4>
<B>Section: </B>7.5.6.3&#160; [<A href="https://wg21.link/expr.prim.lambda.capture">expr.prim.lambda.capture</A>]
 &#160;&#160;&#160;

 <B>Status: </B>C++14
 &#160;&#160;&#160;

 <B>Submitter: </B>Michael Wong
 &#160;&#160;&#160;

 <B>Date: </B>2013-04-15<BR><BR>


<A href="http://www.open-std.org/jtc1/sc22/wg21/docs/papers/2014/n3903.html#CA20">N3690 comment
  CA&#160;20<BR></A>

<P>[Moved to DR at the February, 2014 meeting.]</P>



<P>The example in 7.5.6 [<A href="https://wg21.link/expr.prim.lambda#24">expr.prim.lambda</A>] paragraph 24 reads,</P>

<PRE>
  template&lt;class... Args&gt;
  void f(Args... args) {
    auto lm = [&amp;, args...] { return g(args...); };
    lm();
  }
</PRE>

<P>However, it's not clear how this example squares with the
requirements in paragraph 10,</P>

<BLOCKQUOTE>

The identifier in a <I>simple-capture</I> is looked up using the usual
rules for unqualified name lookup (6.5.3 [<A href="https://wg21.link/basic.lookup.unqual">basic.lookup.unqual</A>]); each such
lookup shall find a variable with automatic storage duration declared in
the reaching scope of the local lambda expression.

</BLOCKQUOTE>

<P>since a function parameter pack is not a variable.  Although the
requirement might be met in a given specialization of the function
template, is there a rule that relaxes it in the context of the function
template definition?</P>

<P><B>Proposed resolution (September, 2013):</B></P>

<OL>
<LI><P>Change 7.5.6 [<A href="https://wg21.link/expr.prim.lambda#10">expr.prim.lambda</A>] paragraph 10 as follows:</P></LI>

<BLOCKQUOTE>

The <I>identifier</I> in a <I>simple-capture</I> is looked up using the
usual rules for unqualified name lookup (6.5.3 [<A href="https://wg21.link/basic.lookup.unqual">basic.lookup.unqual</A>]); each
such lookup shall find <INS>an entity.  An entity that is designated by a
<I>simple-capture</I> is said to be <I>explicitly captured</I>, and shall
be <TT>this</TT> or</INS> a variable with automatic storage duration
declared in the reaching scope of the local lambda expression. <DEL>An
entity (i.e. a variable or <TT>this</TT>) is said to be <I>explicitly
captured</I> if it is found by this process.</DEL>

</BLOCKQUOTE>

<LI><P>Change 13.7.4 [<A href="https://wg21.link/temp.variadic#4">temp.variadic</A>] paragraph 4 as follows:</P></LI>

<BLOCKQUOTE>

<P>...Pack expansions can occur in the following contexts:</P>

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

<P><INS>For the purpose of determining whether a parameter pack satisfies a
rule regarding entities other than parameter packs, the parameter pack is
considered to be the entity that would result from an instantiation of the
pattern in which it appears.</INS></P>

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

</BLOCKQUOTE>

<LI><P>Change 13.7.4 [<A href="https://wg21.link/temp.variadic#6">temp.variadic</A>] paragraph 6 as follows:</P></LI>

<BLOCKQUOTE>

<P>...Each <TT>E</TT><SUB><I>i</I></SUB> is generated by instantiating the
pattern and replacing each pack expansion parameter with its <I>i</I>th
element. <INS>Such an element, in the context of the instantiation, is
interpreted as follows:</INS>
</P>

<UL>
<LI><P><INS>if the pack is a template parameter pack, the element is a
template parameter (13.2 [<A href="https://wg21.link/temp.param">temp.param</A>]) of the corresponding kind
(type or non-type) designating the type or value from the template
argument; otherwise,</INS></P></LI>

<LI><P><INS>if the pack is a function parameter pack, the element is
an <I>id-expression</I> designating the function parameter that resulted
from the instantiation of the pattern where the pack is
declared.</INS></P></LI>

</UL>

<P>All of the <TT>E</TT><SUB><I>i</I></SUB> become elements in the
enclosing list. [<I>Note:</I>...</P>

</BLOCKQUOTE>

</OL>

<BR><BR>
</BODY>
</HTML>
