Benoit Jacob | 3cd2a12 | 2007-12-24 11:14:25 +0000 | [diff] [blame] | 1 | #include <Eigen/Core.h> |
| 2 | USING_PART_OF_NAMESPACE_EIGEN |
| 3 | using namespace std; |
| 4 | |
| 5 | template<typename Scalar, typename Derived> |
| 6 | Eigen::Row<Derived> |
| 7 | firstRow(MatrixBase<Scalar, Derived>& m) |
| 8 | { |
Benoit Jacob | 6b9370e | 2007-12-26 09:25:00 +0000 | [diff] [blame^] | 9 | return Eigen::Row<Derived>(m.ref(), 0); |
| 10 | } |
| 11 | |
| 12 | template<typename Scalar, typename Derived> |
| 13 | const Eigen::Row<Derived> |
| 14 | firstRow(const MatrixBase<Scalar, Derived>& m) |
| 15 | { |
| 16 | return Eigen::Row<Derived>(m.ref(), 0); |
Benoit Jacob | 3cd2a12 | 2007-12-24 11:14:25 +0000 | [diff] [blame] | 17 | } |
| 18 | |
| 19 | int main(int, char**) |
| 20 | { |
| 21 | Matrix4d m = Matrix4d::identity(); |
Benoit Jacob | 6b9370e | 2007-12-26 09:25:00 +0000 | [diff] [blame^] | 22 | cout << firstRow(2*m) << endl; // calls the const version |
| 23 | firstRow(m) *= 5; // calls the non-const version |
Benoit Jacob | 3cd2a12 | 2007-12-24 11:14:25 +0000 | [diff] [blame] | 24 | cout << "Now the matrix m is:" << endl << m << endl; |
| 25 | return 0; |
| 26 | } |