jeudi 31 décembre 2015

Eigen and c++11 assignment and rreference

I'm getting very confused with c++11 move semantics and especially with eigen- does it have an assignment operator for rvalue (operator=(Type&&)), or not?

This code crashes over size mismatch:

    Eigen::VectorXd&& func(){
        Eigen::VectorXd&& v=Eigen::VectorXd::Zero(5);
        return std::move(v);
    }

    Eigen::VectorXd v=Eigen::VectorXd::Zero(10);
    v.block(0,0,5,1)=func();

The only way it worked was if func was defined as:

    Eigen::VectorXd func(){
        Eigen::VectorXd v=Eigen::VectorXd::Zero(5);
        return v;
    }

Even the regular single reference (&) didn't work. When can I use these references? What is going on with the memory? Thanks!

Aucun commentaire:

Enregistrer un commentaire