从所有包元素的特定成员中推导出参数包
Deduce a parameter pack from specific member of all pack elements
我猜这很简单,只是不知道该怎么做 - 假设作为参数传入的每个类型都有一个名为 't' 的成员 typedef,我该如何制作元组会员的?
#include <tuple>
template <typename T>
struct A{
typedef T t;
};
template <typename ...Ts>
struct B{
std::tuple<Ts::t...> ts; // I want a tuple of Ts::t type...
};
int main()
{
B<A<int>,A<float>> b;
return 0;
}
class模板的参数std::tuple
是类型。
Ts::t
是 dependent name
.
要声明依赖名称是类型,您必须在它之前使用 typename
关键字。
现在你知道为什么 typename Ts::t...
有效而 Ts::t...
无效了。
我猜这很简单,只是不知道该怎么做 - 假设作为参数传入的每个类型都有一个名为 't' 的成员 typedef,我该如何制作元组会员的?
#include <tuple>
template <typename T>
struct A{
typedef T t;
};
template <typename ...Ts>
struct B{
std::tuple<Ts::t...> ts; // I want a tuple of Ts::t type...
};
int main()
{
B<A<int>,A<float>> b;
return 0;
}
class模板的参数std::tuple
是类型。
Ts::t
是 dependent name
.
要声明依赖名称是类型,您必须在它之前使用 typename
关键字。
现在你知道为什么 typename Ts::t...
有效而 Ts::t...
无效了。