Boost.Tuple 与 C++0x 可变参数模板兼容吗?
我正在使用可变参数模板(gcc 4.5)并遇到这个问题:
template <typename... Args>
boost::tuple<Args...>
my_make_tuple(Args... args)
{
return boost::tuple<Args...>(args...);
}
int main (void)
{
boost::tuple<int, char> t = my_make_tuple(8, 'c');
}
GCC错误消息:
sorry, unimplemented: cannot expand 'Arg ...' into a fixed-length argument list
In function 'int my_make_tuple(Arg ...)'
如果我用std::tuple
替换每次出现的boost::tuple
,它编译得很好。
boost tuple实现有问题吗?或者这是一个 gcc 错误?
我现在必须坚持使用 Boost.Tuple。你知道有什么解决方法吗?
谢谢。
I was playing around with variadic templates (gcc 4.5) and hit this problem :
template <typename... Args>
boost::tuple<Args...>
my_make_tuple(Args... args)
{
return boost::tuple<Args...>(args...);
}
int main (void)
{
boost::tuple<int, char> t = my_make_tuple(8, 'c');
}
GCC error message :
sorry, unimplemented: cannot expand 'Arg ...' into a fixed-length argument list
In function 'int my_make_tuple(Arg ...)'
If I replace every occurrence of boost::tuple
by std::tuple
, it compiles fine.
Is there a problem in boost tuple implementation? Or is this a gcc bug ?
I must stick with Boost.Tuple for now. Do you know any workaround ?
Thanks.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
它似乎不像 Boost 那样将
Args...
扩展到T1, T2, T3, ..., T9
。作为解决方法,请使用不需要此扩展的构造:
另一种选择可能是手动进行扩展,因为
boost::tuple
支持最多 10 个参数。It doesn't seem to like expanding
Args...
toT1, T2, T3, ..., T9
as Boost has it.As a workaround, use constructs that don't require this expansion:
Another option might be to do the expanding manually, seeing that
boost::tuple
supports up to 10 arguments.