开发者

c++ and ublas: creating an array of c_vectors with different sizes

Is there a way to create an array of ublas c_vectors with different sizes?

For example

array[0] would return an ublas::c_vector< double, 3 > (size=3) and array[0](0) would access its first element

array[1] would return an ublas::c_vector< double, 7 > (size=7) and array[1](0) would access its first e开发者_如何学编程lement

etc


I think you can use std::vector<boost::any>, and then push ublas::c_vector of different sizes into it.

std::vector<boost::any> v;
v.push_back(ublas::c_vector<double,3>());
v.push_back(ublas::c_vector<double,7>());
v.push_back(ublas::c_vector<double,9>());
//etc

Elements should be cast back to the appropriate types, using boost::any_cast which is custom keyword cast for extracting a value of a given type from boost::any.

You could try boost::variant as well. Choose whatever suits your need better. Read this before making a decision:

  • Boost.Variant vs. Boost.Any
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜