[eigen] Passing result of block() as non-const reference-to-matrix?

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


Today I found, to my surprise, that passing the result of a Matrix::block() method to a function that takes a reference to an Eigen::Matrix doesn't seem to work. The program (which doesn't compile) demonstrates the problem.

I know that it /is/ possible to pass the result of a Matrix::block() const call to a const reference to an Eigen::Matrix. Is it intentional that the non-const version of this does not work?

Any help would be greatly appreciated.

Regards, Sidney

/////////////////////// code fragment starts here

#include <Eigen/Core>

void incrementBottomRight(Eigen::Matrix<double, Eigen::Dynamic, Eigen::Dynamic> & m)
    m(m.rows() - 1, m.cols() - 1) += 1.0;

int main()
    Eigen::Matrix<double, Eigen::Dynamic, Eigen::Dynamic> testMatrix(3, 3);

    // This works fine

    // This gives a compiler error
    incrementBottomRight(testMatrix.block(0, 0, 2, 2));

    std::cout << testMatrix << std::endl;

    return 0;

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