c++eigeneigenvector

Initilialize a typedef eigen vector from std::vector


typedef Eigen::Matrix<double, Eigen::Dynamic, 1> EigenVectorX;
std::vector<double> v;
v.push_back(22);
v.push_back(55);
v.push_back(77);

EigenVectorX ev;

How I can initialize ev with v ?


Solution

  • You can use Eigen::Map for this

    EigenVectorX ev = Eigen::Map<EigenVectorX>(v.data(), v.size());