我在元组上使用 std::get。当给定 5 个整数的元组时,它运行良好:
typedef std::tuple<int, int, int, int, int> int5Tuple;
std::get<1>(int5Tuple(1, 2, 3, 4, 5));
但是在 6 个整数的元组上它失败了:
typedef std::tuple<int, int, int, int, int, int> int6Tuple;
std::get<1>(int6Tuple(1, 2, 3, 4, 5, 6));
出现此错误:错误 C2243:“类型转换”:从“std::tuple<,_V0_t,_V1_t,_V2_t,_V3_t,_V4_t> *”转换为“std::tuple<,_V0_t,_V1_t,_V2_t, _V3_t> &&' 存在,但不可访问。
在寻找解决方案时,似乎暗示它与访问保护有关,但我认为这不会成为解决方案的途径。
我得到的智能感知错误是没有 std::get 的实例与参数列表匹配。
最佳答案
Visual Studio 直到 VS 2013 才真正支持可变参数模板,这意味着它们改为使用宏生成的“重载”来支持通常使用此语言功能实现的 C++11 STL 功能。默认情况下,这些重载最多支持五个(模板)参数。但是,以更高的编译时间为代价,这可以使用 _VARIADIC_MAX
定义进行配置。
You can define
_VARIADIC_MAX
project-wide between 5 and 10 inclusive (it defaults to 5).
请参阅 C++11 Features in Visual C++ 11 中的“人造变量”部分VCBlog 条目以获取更多详细信息。
关于c++ - std::get 在给定 6 个整数的元组时失败,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/18934113/