[英]How can I define arguments of variadic template?
I have a variadic template and would to define the arguments using using
alias declaration.我有一个可变参数模板,并且会
using
别名声明来定义参数。
Here is an example:这是一个例子:
template<class I, class... P>
struct Molecule {
using Index = I;
};
My question is, how can I define the first argument of P...
?我的问题是,如何定义
P...
的第一个参数?
I have already tried this, but it generates an error:我已经尝试过了,但它会产生一个错误:
template<class I, class... P>
struct Molecule {
using Index = I;
P array[sizeof...(P)] = { P... };
using Part1 = array[0];
};
Any suggestions please?请问有什么建议吗?
how i can define the first argument of P... ?
我如何定义 P... 的第一个参数?
If the Molecule
can be redefined to the following, you get it directly:如果
Molecule
可以重新定义为以下,则直接获取:
template<class I, class First, class... P> {
using Part1 = First;
// .....
}
Otherwise, make a trait to find the first type:否则,创建一个特征来找到第一种类型:
template<typename First, typename... Rest>
struct first { using type = First; };
template<typename... Args> using first_t = typename first<Args...>::type;
Now现在
template<class I, class... P> struct Molecule {
using Part1 = first_t<P...>; // first type
};
assuming that you would have at least one argument in variadic P...
.假设您在可变参数
P...
中至少有一个参数。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.