是否可以创建 c_vector<int, 3>
值为 [12 398 -34]
(例如)在一行中?
至于I can see唯一可行的构造函数是:
c_vector(vector_expression<AE> const&)
需要 VectorExpression
,这似乎是所有其他类型的 vector ,如 zero_vector
和 scalar_vector
是动态分配的。
有没有类似 std::initializer_list<T>
的东西我可以使用的构造函数?或者什么VectorExpression
我应该用于这个简单的任务吗?
最佳答案
我在 assignment.hpp
header 中偶然发现了这个:
v <<= 1,2,3;
我想如果你仔细看的话,里面可能会有更多有用的方法。例如
vector<double> a(6, 0);
a <<= 1, 2, move_to(5), 3;
将导致:1 2 0 0 0 3
和
matrix<double> A(3, 3, 0);
A <<= 1, 2, next_row(),
3, 4, begin1(), 1;
将导致:
1 2 1
3 4 0
0 0 0
#include <boost/numeric/ublas/vector.hpp>
#include <boost/numeric/ublas/vector_expression.hpp>
#include <boost/numeric/ublas/traits/c_array.hpp>
#include <boost/numeric/ublas/assignment.hpp>
namespace ublas = boost::numeric::ublas;
int main() {
using V = ublas::c_vector<int, 3>;
V v;
v <<= 1,2,3;
for (auto i : v)
std::cout << i << " ";
}
打印
1 2 3
关于c++ - 创建一个 c_vector,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/30282180/