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
697 B

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