0

I want to know how I can assign multiple values to a vector at once:

#include <iostream>
#include <boost/numeric/ublas/vector.hpp>
#include <boost/numeric/ublas/io.hpp>

using namespace boost::numeric::ublas;

int main()
{
    vector<double> v1(3);
    v1(0)=0;
    v1(1)=0.1;
    v1(2)=0.05;
    v1(3)=0.25;

    return 0;
}

I want to assign all the values at once. something like:

v1 << 0,0.1,0.05,0.25;

I tried operator += and there is an error, but I think operator += works for std::vector not boost::....vector

Uyghur Lives Matter
  • 18,820
  • 42
  • 108
  • 144
NKN
  • 6,482
  • 6
  • 36
  • 55

1 Answers1

3

Take a look at documentation examples http://svn.boost.org/svn/boost/trunk/libs/numeric/ublas/doc/samples/assignment_examples.cpp

Basically, you need v1 <<= 0, 1, 2;, see more examples in the docs. Unfortunately this library doesn't support initializer_list's yet: http://boost.2283326.n4.nabble.com/Initializing-from-an-initializer-list-td4647029.html

user3159253
  • 16,836
  • 3
  • 30
  • 56