如何定义variadic模板的参数?
我有一个变异模板,将使用别名声明使用来定义参数。
这是一个示例:
template<class I, class... P>
struct Molecule {
using Index = I;
};
我的问题是,如何定义p ...
的第一个参数?
我已经尝试过,但是它会产生一个错误:
template<class I, class... P>
struct Molecule {
using Index = I;
P array[sizeof...(P)] = { P... };
using Part1 = array[0];
};
请提出任何建议吗?
I have a variadic template and would to define the arguments using using
alias declaration.
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...
?
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?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
如果可以将
分子
重新定义为以下内容,则可以直接获得:否则,制定特征以找到第一种类型:
现在
假设您在variadic
p中至少有一个参数。 ..
。请参阅演示
If the
Molecule
can be redefined to the following, you get it directly:Otherwise, make a trait to find the first type:
Now
assuming that you would have at least one argument in variadic
P...
.See a demo