2

这是昨天的问题,我提供了一些 Visual Studio 2013 无法处理的 C++ 代码,@galop1n 提供了一个解决方法,它非常适合这种情况。但现在我已经走得更远了,Visual Studio 又让我伤心了。

template <typename T>
using ValueType = typename T::value_type;

template<typename... Containers>
void
foo(const Containers &...args) {
    std::tuple<ValueType<Containers>...> x;
}

template<typename... Containers>
struct Foo {
    std::tuple<ValueType<Containers>...> x;
};

每当我尝试实例化函数模板 foo 或类模板 Foo 时,都会收到以下两条消息:

Test.cpp(21): error C3546: '...' : 没有可扩展的参数包

Test.cpp(21): error C3203: 'ValueType' : unspecialized alias template can't be used as a template argument for template parameter '_Types', 应为真实类型

在每种情况下(实例化 foo 或实例化 Foo),两条消息都指向定义“x”的行。

更新:我的Microsoft 错误报告现在(在其附件中)包含此问题的所有基本变体。所以这将是寻找修复的地方。

4

1 回答 1

0

也许以下作品适用于 VS2013(更详细:/):

template<typename... Containers>
void foo(const Containers &...args) {
    std::tuple<typename std::decay<decltype(*args.begin())>::type...> x;
}

template<typename... Containers>
struct Foo {
    std::tuple<typename std::decay<decltype(*std::declval<Containers>().begin())>::type...> x;
};
于 2014-02-07T11:17:34.897 回答