From c6f610093bff10c5a6e4fac94bfed422ba54b39a Mon Sep 17 00:00:00 2001 From: Gael Guennebaud Date: Sun, 5 Jul 2009 11:33:55 +0200 Subject: add a VectorBlock expr as a specialization of Block --- doc/examples/class_FixedVectorBlock.cpp | 26 ++++++++++++++++++++++++++ 1 file changed, 26 insertions(+) create mode 100644 doc/examples/class_FixedVectorBlock.cpp (limited to 'doc/examples/class_FixedVectorBlock.cpp') diff --git a/doc/examples/class_FixedVectorBlock.cpp b/doc/examples/class_FixedVectorBlock.cpp new file mode 100644 index 000000000..c176be495 --- /dev/null +++ b/doc/examples/class_FixedVectorBlock.cpp @@ -0,0 +1,26 @@ +#include +USING_PART_OF_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; +} -- cgit v1.2.3