blob: 5138b2e7cb82f6b9853b93dd9a7f1a5cac11b16a (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
|
#include <Eigen/Core>
USING_PART_OF_NAMESPACE_EIGEN
using namespace std;
template<typename Derived>
Eigen::Block<Derived,1,Derived::ColsAtCompileTime>
firstRow(MatrixBase<Derived>& m)
{
return Eigen::Block<Derived,1,Derived::ColsAtCompileTime>(m.asArg(), 0);
}
template<typename Derived>
const Eigen::Block<Derived,1,Derived::ColsAtCompileTime>
firstRow(const MatrixBase<Derived>& m)
{
return Eigen::Block<Derived,1,Derived::ColsAtCompileTime>(m.asArg(), 0);
}
int main(int, char**)
{
Matrix4d m = Matrix4d::identity();
cout << firstRow(2*m) << endl; // calls the const version
firstRow(m) *= 5; // calls the non-const version
cout << "Now the matrix m is:" << endl << m << endl;
return 0;
}
|