2009-07-05 17:33:55 +08:00
|
|
|
#include <Eigen/Core>
|
2010-03-09 03:34:24 +08:00
|
|
|
#include <iostream>
|
2010-04-23 06:27:13 +08:00
|
|
|
using namespace Eigen;
|
2009-07-05 17:33:55 +08:00
|
|
|
using namespace std;
|
|
|
|
|
|
|
|
template<typename Derived>
|
|
|
|
Eigen::VectorBlock<Derived, 2>
|
|
|
|
firstTwo(MatrixBase<Derived>& v)
|
|
|
|
{
|
|
|
|
return Eigen::VectorBlock<Derived, 2>(v.derived(), 0);
|
|
|
|
}
|
|
|
|
|
|
|
|
template<typename Derived>
|
2010-12-30 17:52:20 +08:00
|
|
|
const Eigen::VectorBlock<const Derived, 2>
|
2009-07-05 17:33:55 +08:00
|
|
|
firstTwo(const MatrixBase<Derived>& v)
|
|
|
|
{
|
2010-12-30 17:52:20 +08:00
|
|
|
return Eigen::VectorBlock<const Derived, 2>(v.derived(), 0);
|
2009-07-05 17:33:55 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
int main(int, char**)
|
|
|
|
{
|
|
|
|
Matrix<int,1,6> v; v << 1,2,3,4,5,6;
|
|
|
|
cout << firstTwo(4*v) << endl; // calls the const version
|
|
|
|
firstTwo(v) *= 2; // calls the non-const version
|
|
|
|
cout << "Now the vector v is:" << endl << v << endl;
|
|
|
|
return 0;
|
|
|
|
}
|