0

我想强制参数包中的所有类型都在其中声明一个嵌套类型别名(T),并将所有T类型的 's 扩展为tuple. 这样的事情可能吗?当我尝试下面的幼稚方式时,它不会被识别Types::T为一种类型。

class A { using T = int; };
class B { using T = double; };


template<class ... Types>
class C {
  using tuple_of_types_t        = std::tuple<Types...>;       // of course this works
  using tuple_of_nested_types_t = std::tuple<((Types::T),...)>;  // how do I achieve this?
};
4

1 回答 1

1

编译器需要被告知Types::T应该被解释为一个类型

using tuple_of_nested_types_t = std::tuple<typename Types::T...>;
//                                         ^^^^^^^^

在 Compiler Explorer 上查看它编译

于 2021-11-02T13:13:49.850 回答