#include #include using namespace Eigen; using namespace std; template Eigen::VectorBlock segmentFromRange(MatrixBase& v, int start, int end) { return Eigen::VectorBlock(v.derived(), start, end - start); } template const Eigen::VectorBlock segmentFromRange( const MatrixBase& v, int start, int end) { return Eigen::VectorBlock(v.derived(), start, end - start); } int main(int, char**) { Matrix v; v << 1, 2, 3, 4, 5, 6; cout << segmentFromRange(2 * v, 2, 4) << endl; // calls the const version segmentFromRange(v, 1, 3) *= 5; // calls the non-const version cout << "Now the vector v is:" << endl << v << endl; return 0; }