gpt4 book ai didi

c++ - 具有可变参数模板的更多依赖类型

转载 作者:塔克拉玛干 更新时间:2023-11-03 07:54:44 24 4
gpt4 key购买 nike

接下来是 yesterday's question ,我在其中提供了一些 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: '...' : there are no parameter packs available to expand

Test.cpp(21): error C3203: 'ValueType' : unspecialized alias template can't be used as a template argument for template parameter '_Types', expected a real type

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

更新:我的 Microsoft bug report现在(在其附件中)有这个问题的所有基本变体。因此,这将是关注修复的地方。

最佳答案

也许以下是 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;
};

关于c++ - 具有可变参数模板的更多依赖类型,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/21619760/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com