是否允许元组的元组? [英] Are tuples of tuples allowed?
问题描述
我目前正在使用具有许多模板的类,并且能够构建元组的元组将使其变得更加简单
I'm currently working on a class with a lot of templates and being able to build tuples of tuples would make it a lot easier
但是我在MSVC ++ 2010中尝试了以下简单代码:
But I tried this simple code in MSVC++ 2010:
#include <tuple>
void main() {
auto x = std::make_tuple(std::make_tuple(5, true));
}
我得到一个编译错误.如果我不使用std::make_tuple
而是直接使用std::tuple
的构造函数,则会发生相同的问题.
And I get a compilation error. The same problem happens if I don't use std::make_tuple
but directly std::tuple
's constructor.
是MSVC的错误还是标准不允许的元组?
Is it a bug of MSVC or are tuples of tuples not allowed by the standard?
推荐答案
更多数据点:
-
如果我们使用
std::tr1::tuple
并明确声明类型而不是使用auto
,则Visual C ++ 2008会编译代码而不会出现错误.尝试使用Visual C ++ 2010编译相同的代码会导致您看到错误.
If we use
std::tr1::tuple
and explicitly state the type instead of usingauto
, then Visual C++ 2008 compiles the code without error. Trying to compile that same code with Visual C++ 2010 results in the error you are seeing.
如果我们使用boost::tuple
显式声明类型而不是使用auto
,则Visual C ++ 2008和Visual C ++ 2010都可以正确地编译代码.
If we use boost::tuple
an explicitly state the type instead of using auto
, then Visual C++ 2008 and Visual C++ 2010 both compile the code without error.
它看起来可能是实现错误.
It looks like it is probably an implementation bug.
这篇关于是否允许元组的元组?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!