You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

27 lines
800 B

  1. #include <Eigen/Core>
  2. #include <iostream>
  3. using namespace StormEigen;
  4. using namespace std;
  5. template<typename Derived>
  6. StormEigen::VectorBlock<Derived>
  7. segmentFromRange(MatrixBase<Derived>& v, int start, int end)
  8. {
  9. return StormEigen::VectorBlock<Derived>(v.derived(), start, end-start);
  10. }
  11. template<typename Derived>
  12. const StormEigen::VectorBlock<const Derived>
  13. segmentFromRange(const MatrixBase<Derived>& v, int start, int end)
  14. {
  15. return StormEigen::VectorBlock<const Derived>(v.derived(), start, end-start);
  16. }
  17. int main(int, char**)
  18. {
  19. Matrix<int,1,6> v; v << 1,2,3,4,5,6;
  20. cout << segmentFromRange(2*v, 2, 4) << endl; // calls the const version
  21. segmentFromRange(v, 1, 3) *= 5; // calls the non-const version
  22. cout << "Now the vector v is:" << endl << v << endl;
  23. return 0;
  24. }