Title
Capturing function parameter packs
Status
c++14
Section
7.5.5 [expr.prim.lambda]
Submitter
Michael Wong

Created on 2013-04-15.00:00:00 last changed 81 months ago

Messages

Date: 2014-02-15.00:00:00

[Moved to DR at the February, 2014 meeting.]

Date: 2013-09-15.00:00:00

Proposed resolution (September, 2013):

  1. Change 7.5.5 [expr.prim.lambda] paragraph 10 as follows:

  2. The identifier in a simple-capture is looked up using the usual rules for unqualified name lookup (6.5.3 [basic.lookup.unqual]); each such lookup shall find an entity. An entity that is designated by a simple-capture is said to be explicitly captured, and shall be this or a variable with automatic storage duration declared in the reaching scope of the local lambda expression. An entity (i.e. a variable or this) is said to be explicitly captured if it is found by this process.
  3. Change 13.7.4 [temp.variadic] paragraph 4 as follows:

  4. ...Pack expansions can occur in the following contexts:

    • ...

    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.

    [Example:

    ...
  5. Change 13.7.4 [temp.variadic] paragraph 6 as follows:

  6. ...Each Ei is generated by instantiating the pattern and replacing each pack expansion parameter with its ith element. Such an element, in the context of the instantiation, is interpreted as follows:

    • if the pack is a template parameter pack, the element is a template parameter (13.2 [temp.param]) of the corresponding kind (type or non-type) designating the type or value from the template argument; otherwise,

    • if the pack is a function parameter pack, the element is an id-expression designating the function parameter that resulted from the instantiation of the pattern where the pack is declared.

    All of the Ei become elements in the enclosing list. [Note:...

Date: 2013-10-14.00:00:00
N3690 comment CA 20

The example in 7.5.5 [expr.prim.lambda] paragraph 24 reads,

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

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

The identifier in a simple-capture is looked up using the usual rules for unqualified name lookup (6.5.3 [basic.lookup.unqual]); each such lookup shall find a variable with automatic storage duration declared in the reaching scope of the local lambda expression.

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?

History
Date User Action Args
2014-11-24 00:00:00adminsetstatus: dr -> c++14
2014-03-03 00:00:00adminsetmessages: + msg4939
2014-03-03 00:00:00adminsetstatus: ready -> dr
2013-10-14 00:00:00adminsetmessages: + msg4575
2013-10-14 00:00:00adminsetstatus: open -> ready
2013-04-15 00:00:00admincreate