Re: [eigen] What's the best way to copy an Eigen::Vector into a std::vector?

[ Thread Index | Date Index | More lists.tuxfamily.org/eigen Archives ]


2009/11/4 Robert Lupton the Good <rhl@xxxxxxxxxxxxxxxxxxx>:
> Dear Mr. Eigen,
>
> What's the best way to copy an Eigen::Vector into a std::vector?
>
> I'd use
>        std::copy(evec.begin(), evec.end(), stdvec.begin());
> if Eigen supported begin and and, but it doesn't seem to.  I don't know what
> Eigen's start() and end() are supposed to do, but the following doesn't
> compile:
>
> #include <algorithm>
> #include <vector>
> #include "Eigen/Core"
>
> int main() {
>    Eigen::VectorXd evec(10);
>    std::vector<double> stdvec(10);
>    std::copy(evec.start(), evec.end(), stdvec.begin());
> }
>
> although the doxygen docs refer to start(void).
>
> I see the headers Eigen/StdVec and Eigen/NewStdVec, but they don't seem to
> do what I want.

These are to allow doing stuff like std::vector<Vector4f,
aligned_allocator> and making sure that the alignment is actually
honored.

In addition to Hauke's method, you can equivalently wrap your
std::vector with Map and assign to that.

Benoit

>
>                                R
>
>
>
>



Mail converted by MHonArc 2.6.19+ http://listengine.tuxfamily.org/