blob: b643d114851a6b68944eb8eb1bdb2ec1231d7340 [file] [log] [blame]
Benoit Jacob183bf542008-01-13 23:38:48 +00001#include <Eigen/Core>
2USING_PART_OF_NAMESPACE_EIGEN
3using namespace std;
4
Benoit Jacob01572b92008-03-10 17:23:11 +00005template<typename Derived>
Benoit Jacobf12e9c52008-02-29 13:56:40 +00006Eigen::Block<Derived, 2, 2>
Benoit Jacob01572b92008-03-10 17:23:11 +00007topLeft2x2Corner(MatrixBase<Derived>& m)
Benoit Jacob183bf542008-01-13 23:38:48 +00008{
Benoit Jacob861c6f42008-03-04 17:08:23 +00009 return Eigen::Block<Derived, 2, 2>(m.asArg(), 0, 0);
Benoit Jacob183bf542008-01-13 23:38:48 +000010}
11
Benoit Jacob01572b92008-03-10 17:23:11 +000012template<typename Derived>
Benoit Jacobf12e9c52008-02-29 13:56:40 +000013const Eigen::Block<Derived, 2, 2>
Benoit Jacob01572b92008-03-10 17:23:11 +000014topLeft2x2Corner(const MatrixBase<Derived>& m)
Benoit Jacob183bf542008-01-13 23:38:48 +000015{
Benoit Jacob861c6f42008-03-04 17:08:23 +000016 return Eigen::Block<Derived, 2, 2>(m.asArg(), 0, 0);
Benoit Jacob183bf542008-01-13 23:38:48 +000017}
18
19int main(int, char**)
20{
21 Matrix3d m = Matrix3d::identity();
22 cout << topLeft2x2Corner(4*m) << endl; // calls the const version
23 topLeft2x2Corner(m) *= 2; // calls the non-const version
24 cout << "Now the matrix m is:" << endl << m << endl;
25 return 0;
26}