我想有一个类,它有一个构造函数,它接受可变数量的争论,并通过以某种方式解包到数组支持的逗号初始值设定项列表来填充数组,这里是示例:
class A{
public:
template<typename ...T>
A(T ... values): arr(sizeof...(T)) {
//convert the values somehow that the parameter pack is expanded in the comma initialized list as the following:
//arr << values1, values2, values3,... , valuesN
}
ArrayType arr;
}
这种逗号初始化方法尤其适用于 ArrayType 与 Eigen::Matrix 类 ( arr << 1,2,3;
) 之间的关系。我想知道以下是否可行,如果有其他优雅的方式来填充数组,我们可以使用索引运算符 (i) 到第 i 个元素:-)
非常感谢 :)