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