eigen/doc/examples/class_Column.cpp
Benoit Jacob 01572b9f54 big change: MatrixBase only takes one template parameter "Derived", the
template parameter "Scalar" is removed. This is achieved by introducting a
template <typename Derived> struct Scalar to achieve a forward-declaration of
the Scalar typedefs.
2008-03-10 17:23:11 +00:00

27 lines
622 B
C++

#include <Eigen/Core>
USING_PART_OF_NAMESPACE_EIGEN
using namespace std;
template<typename Derived>
Eigen::Column<Derived>
firstColumn(MatrixBase<Derived>& m)
{
return Eigen::Column<Derived>(m.asArg(), 0);
}
template<typename Derived>
const Eigen::Column<Derived>
firstColumn(const MatrixBase<Derived>& m)
{
return Eigen::Column<Derived>(m.asArg(), 0);
}
int main(int, char**)
{
Matrix4d m = Matrix4d::identity();
cout << firstColumn(2*m) << endl; // calls the const version
firstColumn(m) *= 5; // calls the non-const version
cout << "Now the matrix m is:" << endl << m << endl;
return 0;
}