#include #include using namespace Eigen; using namespace std; template Eigen::VectorBlock firstTwo(MatrixBase& v) { return Eigen::VectorBlock(v.derived(), 0); } template const Eigen::VectorBlock firstTwo( const MatrixBase& v) { return Eigen::VectorBlock(v.derived(), 0); } int main(int, char**) { Matrix 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; }