【问题标题】:VS2013 C++ C1001 error with std::tuple_catVS2013 C++ C1001 错误与 std::tuple_cat
【发布时间】:2015-06-11 00:05:19
【问题描述】:

我最近将 C++ 代码从 VS2012 迁移到 VS2013。代码在 VS2012 下编译,但是 VS2013 抛出 C1001 内部编译器错误。

具体来说,错误指向std库中的tuple.h文件:

template<class... _Types1,
    class _Kx_arg,
    size_t... _Ix,
    size_t _Ix_next,
    class... _Types2,
    class... _Rest>
    struct _Tuple_cat2<tuple<_Types1...>, _Kx_arg, _Arg_idx<_Ix...>, _Ix_next,
        tuple<_Types2...>, _Rest...>
        : _Tuple_cat2<
            tuple<_Types1..., _Types2...>,
            typename _Cat_arg_idx<_Kx_arg,
                typename _Make_arg_idx<_Types2...>::type>::type,
            _Arg_idx<_Ix..., _Repeat_for<_Ix_next, _Types2>::value...>,
            _Ix_next + 1,
            _Rest...>
    {   // determine tuple_cat's return type and _Kx/_Ix indices
    };

我的代码调用 std::tuple_cat 方法来检索连接元组的类型(注意 void 类型的部分特化):

template <typename TupleA, typename TupleB>
    struct tuple_concatenator//yields the type of two concatenated tuples.
    {
        typedef decltype(std::tuple_cat(std::declval<TupleA>(),
                                        std::declval<TupleB>())) type;
    };
    template <typename TupleA>
    struct tuple_concatenator<TupleA, void>//yields the type of TupleA.
    {
        typedef TupleA type;
    };
    template <typename TupleB>
    struct tuple_concatenator<void, TupleB>//yields the type of TupleB.
    {
        typedef TupleB type;
    };
    template <>
    struct tuple_concatenator<void, void>
    {
        typedef void type;
    };

你将如何配置VS2013或重写上述代码以避免C1001错误?

提前感谢您的帮助。

【问题讨论】:

    标签: c++ visual-studio-2012 visual-studio-2013 stdtuple


    【解决方案1】:

    ICE 始终是编译器错误。向 Microsoft 提交错误(另外,尝试看看是否可以在运行 VS2015 RC 的 http://webcompiler.cloudapp.net/ 上重现它)。

    std::tuple_cat 实现起来很棘手,因为它需要能够有效地连接任意数量的元组——包括类型和值。但是如果你只需要连接两个std::tuple&lt;...&gt; 类型,你就不需要复杂的tuple_cat 机制;很简单:

    template <typename TupleA, typename TupleB>
    struct tuple_concatenator;
    
    template <class... Ts, class... Us>
    struct tuple_concatenator<std::tuple<Ts...>, std::tuple<Us...>>
    {
        typedef std::tuple<Ts..., Us...> type;
    };
    

    这应该适用于您现有的 void 的部分和完整专业化。

    【讨论】:

    • 谢谢 T.C.为您快速而清晰的回复。您的解决方案确实适用于 VS2013。
    猜你喜欢
    • 2020-09-16
    • 2023-03-06
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2011-08-26
    • 1970-01-01
    • 1970-01-01
    • 2021-04-06
    相关资源
    最近更新 更多