参数包可以在C ++ 11 lambdas中隐式捕获吗? [英] Can a parameter pack be captured implicitly within C++11 lambdas?

查看:85
本文介绍了参数包可以在C ++ 11 lambdas中隐式捕获吗?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

有没有人知道ts的以下隐式捕获是否正确:

Does anyone know if the following implicit capture of 'ts' is well-formed:

template<class ... Ts> void bar(Ts ... ts) { }

template<class ... Ts> int foo(Ts ... ts) {
    auto L = [=] () {
       bar(ts...);
    };
    L();
    return 0;
}
int g = foo(1, 2, 3);

标准是否在任何地方明确说明这不应该形成?

Does the standard clearly state anywhere that this should not be well formed?

推荐答案

14.5.3 / 6:

14.5.3/6:


不是 sizeof ... 表达式的数据包扩展产生列表E1,E2,...,EN,其中
N是包扩展参数。每个Ei通过实例化模式并用其第i个元素替换每个包展开参数来生成。所有的Ei都变成了封闭列表中的元素。

The instantiation of a pack expansion that is not a sizeof... expression produces a list E1, E2, ..., EN , where N is the number of elements in the pack expansion parameters. Each Ei is generated by instantiating the pattern and replacing each pack expansion parameter with its ith element. All of the Ei become elements in the enclosing list.

无论你是否允许明确捕获一个包使用 [ts ...] ),扩展的一般规则将导致列表中每个元素的捕获。

Regardless of whether you're allowed to explicitly capture a pack (you can, using [ts ...]), the general rule of expansion will result in capture of each element of the list.

这篇关于参数包可以在C ++ 11 lambdas中隐式捕获吗?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆