blob: 26f9666cbaf432f4f5a990b3ed0dc111ce259c9a [file] [log] [blame]
Benoit Jacob86220782007-12-28 16:20:00 +00001#include <Eigen/Core>
Benoit Jacob3cd2a122007-12-24 11:14:25 +00002USING_PART_OF_NAMESPACE_EIGEN
3using namespace std;
4
5template<typename Scalar, typename Derived>
Benoit Jacob183bf542008-01-13 23:38:48 +00006Eigen::Block<Derived>
7topLeftCorner(MatrixBase<Scalar, Derived>& m, int rows, int cols)
Benoit Jacob3cd2a122007-12-24 11:14:25 +00008{
Benoit Jacob861c6f42008-03-04 17:08:23 +00009 return Eigen::Block<Derived>(m.asArg(), 0, 0, rows, cols);
Benoit Jacob6b9370e2007-12-26 09:25:00 +000010}
11
12template<typename Scalar, typename Derived>
Benoit Jacob183bf542008-01-13 23:38:48 +000013const Eigen::Block<Derived>
14topLeftCorner(const MatrixBase<Scalar, Derived>& m, int rows, int cols)
Benoit Jacob6b9370e2007-12-26 09:25:00 +000015{
Benoit Jacob861c6f42008-03-04 17:08:23 +000016 return Eigen::Block<Derived>(m.asArg(), 0, 0, rows, cols);
Benoit Jacob3cd2a122007-12-24 11:14:25 +000017}
18
19int main(int, char**)
20{
Benoit Jacob183bf542008-01-13 23:38:48 +000021 Matrix4d m = Matrix4d::identity();
22 cout << topLeftCorner(4*m, 2, 3) << endl; // calls the const version
23 topLeftCorner(m, 2, 3) *= 5; // calls the non-const version
Benoit Jacob3cd2a122007-12-24 11:14:25 +000024 cout << "Now the matrix m is:" << endl << m << endl;
25 return 0;
26}