You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

27 lines
737 B

  1. #include <Eigen/Core>
  2. #include <iostream>
  3. using namespace Eigen;
  4. using namespace std;
  5. template<typename Derived>
  6. Eigen::Block<Derived>
  7. topLeftCorner(MatrixBase<Derived>& m, int rows, int cols)
  8. {
  9. return Eigen::Block<Derived>(m.derived(), 0, 0, rows, cols);
  10. }
  11. template<typename Derived>
  12. const Eigen::Block<const Derived>
  13. topLeftCorner(const MatrixBase<Derived>& m, int rows, int cols)
  14. {
  15. return Eigen::Block<const Derived>(m.derived(), 0, 0, rows, cols);
  16. }
  17. int main(int, char**)
  18. {
  19. Matrix4d m = Matrix4d::Identity();
  20. cout << topLeftCorner(4*m, 2, 3) << endl; // calls the const version
  21. topLeftCorner(m, 2, 3) *= 5; // calls the non-const version
  22. cout << "Now the matrix m is:" << endl << m << endl;
  23. return 0;
  24. }