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
703 B

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