参数包没有用'...'扩展 - gcc的另一个可变参数模板错误? [英] parameter packs not expanded with ‘...' -- another variadic template bug with gcc?

查看:1276
本文介绍了参数包没有用'...'扩展 - gcc的另一个可变参数模板错误?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

众所周知,gcc对variadic模板的处理是不完整的(参见例如 this ),但我不知道以下错误已经知道了(我在bugzilla中找不到它)或者它确实是一个bug。实质上,gcc(4.8.1)无法在lambda表达式中扩展参数包:

  #include< vector> 
#include< algorithm>
#include< type_traits>

模板< typename T,typename F,typename ... X>
void bar(std :: vector< T> const& c,F const& f,X& amp; ... x)
{
std:for_each(c.begin() ,c.end(),[&](const T& t)
{f(t,std :: forward X(x)...);});
}

这会导致(甚至没有任何实例化)

 错误:参数包没有用'...'扩展:
{f(t,std :: forward< X>(x).. ); });
^

任何想法如何避免这种情况? (注意:icpc 14.0.2和clang 3.4可以)或者gcc是正确的,毕竟clang& icpc错误?

edit 请注意,问题在于lambda,因为这也不能编译:

 模板< typename T,typename F,typename ... X> 
void bar(std :: vector< T> const& c,F const& f,X& amp; ... x)
{
auto func = [&](const T& t){f(t,std :: forward X(x)...); };
std:for_each(c.begin(),c.end(),func);
}

与lambda定义中的错误报告。

$考虑到代码与 两个ng版本3.5(中继202594),更重要的是与 gcc编译 版本4.9.0 20140302(实验性)(GCC),都带有 -Wall ,我会说这是早期版本的gcc的问题。 p>

我在 http:// gcc寻找gcc bugreport .gnu.org / bugzilla / 来确认这一点。


gcc's treatment of variadic templates is well known to be patchy (see for example this and this), but I wonder whether the following bug is already known (I cannot find it at bugzilla) or whether it is indeed a bug. Essentially, gcc (4.8.1) fails to expand a parameter pack inside a lambda:

#include <vector>
#include <algorithm>
#include <type_traits>

template<typename T, typename F, typename... X>
void bar(std::vector<T> const&c, F const&f, X&&... x)
{
  std:for_each(c.begin(),c.end(),[&](const T&t)
         { f(t,std::forward<X>(x)...); });
}

this causes (even without any instantiation)

error: parameter packs not expanded with ‘...’:
  { f(t,std::forward<X>(x)...); });
                        ^

any idea how to avoid that? (note: okay with icpc 14.0.2 and clang 3.4) Or is gcc correct after all and clang & icpc wrong?

edit Note that the problem is the lambda, as also this doesn't compile:

template<typename T, typename F, typename... X>
void bar(std::vector<T> const&c, F const&f, X&&... x)
{
auto func = [&](const T&t){ f(t,std::forward<X>(x)...); };
std:for_each(c.begin(),c.end(),func);
}

with the "error" report in the lambda defiition.

解决方案

Given that the code compiles cleanly with both clang version 3.5 (trunk 202594) and more importantly with gcc version 4.9.0 20140302 (experimental) (GCC), both with -Wall, I would say it was an issue with the earlier versions of gcc.

I am looking for a gcc bugreport at http://gcc.gnu.org/bugzilla/ to confirm this.

这篇关于参数包没有用'...'扩展 - gcc的另一个可变参数模板错误?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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