首页 > 解决方案 > 如何为依赖类型扩展参数包?

问题描述

扩展参数包的语法是什么,我想要的类型直接依赖于包中的类型?

例如:

template <typename T>
struct foo
{
   typedef T value_type;
};

template <typename ... T>
struct aggregate_of_foo
{
   typedef std::tuple<foo<T>::value_type...> tuple; // MSVC compiler error here
};

标签: c++c++11templatesvariadic-templatesclass-template

解决方案


如果您的意思是foo而不是barin your typedef,那么您只是缺少typename之前的关键字:

template <typename ... T>
struct aggregate_of_foo
{
   using tuple_foo =  std::tuple<typename foo<T>::value_type...>;
                      //         ^^^^^^^^
};

另请注意,我将其命名为tuple_foo因为这比拥有更有意义tuple


推荐阅读