assignment.hpp
我在标题中偶然发现了这一点:
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
Live On Coliru
#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