[英]Storing a list of Eigen arrays
I would like to store a collection of Eigen arrays in an std::list
or std::vector
. 我想将本征数组的集合存储在std::list
或std::vector
。
My arrays have different types, some Array<Scalar, 1, Dynamic>
, some Array<Scalar, Dynamic, Dynamic>
, so I'm not sure what template argument to give std::list
. 我的数组有不同的类型,有些是Array<Scalar, 1, Dynamic>
,有些是Array<Scalar, Dynamic, Dynamic>
,所以我不确定要给std::list
什么模板参数。
Ideas: 想法:
Dynamic
and store as std::list<Array<Scalar, Dynamic, Dynamic>>
, but this feels like needless copying 将所有内容强制转换为Dynamic
并存储为std::list<Array<Scalar, Dynamic, Dynamic>>
,但这感觉像是不必要的复制 boost::variant
? boost::variant
吗? For those less familiar with Eigen, Dynamic
means -1
. 对于不熟悉Eigen的人, Dynamic
表示-1
。
For more context, see here: What's the right type for a join_rows() function? 有关更多上下文,请参见此处: join_rows()函数的正确类型是什么?
ArrayXf
, ArrayXXd
, Array3i
, etc. are all different types. ArrayXf
, ArrayXXd
, Array3i
等都是不同的类型。 Therefore, your question boils down to: Is there a STL container that allows heterogeneous types? 因此,您的问题可以归结为:是否有一个允许异构类型的STL容器? The short answer to that is: No. The long answer to that is: No, but... 简短的答案是:否。长长的答案是:不,但是...
There are alternatives. 还有其他选择。 As you pointed out, you could use a list
/ vector
of boost::variant
(explicitly list all types) or boost::any
(effectively allow any type). 如您所指出的,您可以使用boost::variant
的list
/ vector
(明确列出所有类型)或boost::any
(有效地允许任何类型)。 You could also use a list
/ vector<void*>
and static_cast
at every usage (personally, not my preferred option). 您还可以在每次使用时使用list
/ vector<void*>
和static_cast
(个人使用,不是我的首选)。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.