use*_*020 2 c++ templates variadic-templates c++11
例如
struct A { typedef int Type; }
struct B { typedef float Type; }
template<class... Ts>
struct C
{
typedef tuple<Ts::Type...> TupleType; // comilation error: parameter pack
// expects a type template argument
};
Run Code Online (Sandbox Code Playgroud)
如何解压缩类型定义的类型?
你需要typename.
typedef tuple<typename Ts::Type...> TupleType;
Run Code Online (Sandbox Code Playgroud)
请注意,这与您处理参数包的事实无关.你需要typename和往常一样.事实上,如果你有
template<class T>
struct D {
typedef vector<typename T::type> VectorType;
};
Run Code Online (Sandbox Code Playgroud)
在typename有必要在这里了.