多个参数包-如何? [英] Multiple parameter packs -- how?
本文介绍了多个参数包-如何?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我有以下问题:
#include <vector>
#include <tuple>
using namespace std;
template< size_t... N_i, typename Ts... >
class A
{
// ...
private:
std::vector<size_t> _v = { N_i... };
std::tuple<Ts...> _t;
};
int main()
{
A<1> a;
}
正如您在上面看到的,我尝试将多个参数包定义为类 A
的模板参数.
不幸的是,该代码无法编译:
As you can see above, I try to define multiple parameter packs as template arguments of the class A
.
Unfortunately, the code does not compile:
错误:"Ts"之前的预期嵌套名称说明符
error: expected nested-name-specifier before 'Ts'
如何为该示例定义多个参数包?
How can I define multiple parameter packs for this example?
推荐答案
实现最终目标的一种方法是使用嵌套模板:
One way to achieve the end goal is by a using a nested template:
template< size_t... N_i> class initial_values {
public:
template <typename Ts...>
class A
{
// ...
private:
std::vector<size_t> _v = { N_i... };
std::tuple<Ts...> _t;
};
};
然后可以引用该模板,例如:
Then the template can be referenced as, for example:
initial_values<1,2,3>::A<int, char> a;
这篇关于多个参数包-如何?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文