加入收藏 | 设为首页 | 会员中心 | 我要投稿 李大同 (https://www.lidatong.com.cn/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 百科 > 正文

c – lambda表达式的变体模板

发布时间:2020-12-16 05:51:13 所属栏目:百科 来源:网络整理
导读:用g做什么正确的方法? template typename F void g (F f);template typename ... A void h (A ... a);template typename ... A void f (A ... a) { g ([a] () { h (a...); }); // g++-4.6: error: parameter packs not expanded with ?...?} 解决方法 我想
用g做什么正确的方法?
template < typename F >
void g (F f);

template < typename ... A >
void h (A ... a);

template < typename ... A >
void f (A ... a) {
  g ([&a] () { h (a...); }); // g++-4.6: error: parameter packs not expanded with ?...?
}

解决方法

我想你也需要在捕获列表中扩展包,如下所示:
template < typename ... A >
void f (A ... a) {
  g ([&,a...] () { h (a...); }); 
}

以下是C 0x最终委员会草案的相关文本,第5.1.2.23节:

A capture followed by an ellipsis is a
pack expansion (14.5.3). [ Example:

06001

— end example ]

(编辑:李大同)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

    推荐文章
      热点阅读